mirror of
https://github.com/pompurin404/mihomo-party.git
synced 2024-11-16 11:42:19 +08:00
control the sub-store proxy and catch logs
This commit is contained in:
parent
955b3fe666
commit
f85e1ecd55
|
@ -1,7 +1,8 @@
|
|||
import { getAppConfig, getControledMihomoConfig } from '../config'
|
||||
import { Worker } from 'worker_threads'
|
||||
import { mihomoWorkDir, resourcesFilesDir, subStoreDir } from '../utils/dirs'
|
||||
import { mihomoWorkDir, resourcesFilesDir, subStoreDir, substoreLogPath } from '../utils/dirs'
|
||||
import subStoreIcon from '../../../resources/subStoreIcon.png?asset'
|
||||
import { createWriteStream } from 'fs'
|
||||
import http from 'http'
|
||||
import net from 'net'
|
||||
import path from 'path'
|
||||
|
@ -89,6 +90,7 @@ export async function startSubStoreBackendServer(): Promise<void> {
|
|||
const {
|
||||
useSubStore = true,
|
||||
useCustomSubStore = false,
|
||||
useProxyInSubStore = false,
|
||||
subStoreHost = '127.0.0.1',
|
||||
subStoreBackendSyncCron = '',
|
||||
subStoreBackendDownloadCron = '',
|
||||
|
@ -101,6 +103,8 @@ export async function startSubStoreBackendServer(): Promise<void> {
|
|||
subStorePort = await findAvailablePort(38324)
|
||||
const icon = nativeImage.createFromPath(subStoreIcon)
|
||||
icon.toDataURL()
|
||||
const stdout = createWriteStream(substoreLogPath(), { flags: 'a' })
|
||||
const stderr = createWriteStream(substoreLogPath(), { flags: 'a' })
|
||||
subStoreBackendWorker = new Worker(path.join(resourcesFilesDir(), 'sub-store.bundle.js'), {
|
||||
env: {
|
||||
SUB_STORE_BACKEND_API_PORT: subStorePort.toString(),
|
||||
|
@ -113,11 +117,13 @@ export async function startSubStoreBackendServer(): Promise<void> {
|
|||
SUB_STORE_BACKEND_UPLOAD_CRON: subStoreBackendUploadCron,
|
||||
SUB_STORE_MMDB_COUNTRY_PATH: path.join(mihomoWorkDir(), 'country.mmdb'),
|
||||
SUB_STORE_MMDB_ASN_PATH: path.join(mihomoWorkDir(), 'ASN.mmdb'),
|
||||
HTTP_PROXY: `http://127.0.0.1:${port}`,
|
||||
HTTPS_PROXY: `http://127.0.0.1:${port}`,
|
||||
ALL_PROXY: `http://127.0.0.1:${port}`
|
||||
HTTP_PROXY: useProxyInSubStore ? `http://127.0.0.1:${port}` : undefined,
|
||||
HTTPS_PROXY: useProxyInSubStore ? `http://127.0.0.1:${port}` : undefined,
|
||||
ALL_PROXY: useProxyInSubStore ? `http://127.0.0.1:${port}` : undefined
|
||||
}
|
||||
})
|
||||
subStoreBackendWorker.stdout.pipe(stdout)
|
||||
subStoreBackendWorker.stderr.pipe(stderr)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -127,3 +127,9 @@ export function logPath(): string {
|
|||
const name = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`
|
||||
return path.join(logDir(), `${name}.log`)
|
||||
}
|
||||
|
||||
export function substoreLogPath(): string {
|
||||
const date = new Date()
|
||||
const name = `sub-store-${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`
|
||||
return path.join(logDir(), `${name}.log`)
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ const SubStoreConfig: React.FC = () => {
|
|||
const {
|
||||
useSubStore = true,
|
||||
useCustomSubStore = false,
|
||||
useProxyInSubStore = false,
|
||||
subStoreHost = '127.0.0.1',
|
||||
customSubStoreUrl,
|
||||
subStoreBackendSyncCron,
|
||||
|
@ -111,6 +112,20 @@ const SubStoreConfig: React.FC = () => {
|
|||
</SettingItem>
|
||||
) : (
|
||||
<>
|
||||
<SettingItem title="为 Sub-Store 内所有请求启用代理" divider>
|
||||
<Switch
|
||||
size="sm"
|
||||
isSelected={useProxyInSubStore}
|
||||
onValueChange={async (v) => {
|
||||
try {
|
||||
await patchAppConfig({ useProxyInSubStore: v })
|
||||
await startSubStoreBackendServer()
|
||||
} catch (e) {
|
||||
alert(e)
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</SettingItem>
|
||||
<SettingItem title="定时同步订阅/文件" divider>
|
||||
<div className="flex w-[60%] gap-2">
|
||||
{subStoreBackendSyncCronValue !== subStoreBackendSyncCron && (
|
||||
|
|
1
src/shared/types.d.ts
vendored
1
src/shared/types.d.ts
vendored
|
@ -239,6 +239,7 @@ interface IAppConfig {
|
|||
autoQuitWithoutCore?: boolean
|
||||
autoQuitWithoutCoreDelay?: number
|
||||
useCustomSubStore?: boolean
|
||||
useProxyInSubStore?: boolean
|
||||
customSubStoreUrl?: string
|
||||
diffWorkDir?: boolean
|
||||
autoSetDNS?: boolean
|
||||
|
|
Loading…
Reference in New Issue
Block a user