diff --git a/src/main/resolve/server.ts b/src/main/resolve/server.ts index ca49e2c..d91e384 100644 --- a/src/main/resolve/server.ts +++ b/src/main/resolve/server.ts @@ -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 { const { useSubStore = true, useCustomSubStore = false, + useProxyInSubStore = false, subStoreHost = '127.0.0.1', subStoreBackendSyncCron = '', subStoreBackendDownloadCron = '', @@ -101,6 +103,8 @@ export async function startSubStoreBackendServer(): Promise { 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 { 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) } } diff --git a/src/main/utils/dirs.ts b/src/main/utils/dirs.ts index 87df764..0ea3566 100644 --- a/src/main/utils/dirs.ts +++ b/src/main/utils/dirs.ts @@ -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`) +} diff --git a/src/renderer/src/components/settings/substore-config.tsx b/src/renderer/src/components/settings/substore-config.tsx index dec3922..7a04d55 100644 --- a/src/renderer/src/components/settings/substore-config.tsx +++ b/src/renderer/src/components/settings/substore-config.tsx @@ -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 = () => { ) : ( <> + + { + try { + await patchAppConfig({ useProxyInSubStore: v }) + await startSubStoreBackendServer() + } catch (e) { + alert(e) + } + }} + /> +
{subStoreBackendSyncCronValue !== subStoreBackendSyncCron && ( diff --git a/src/shared/types.d.ts b/src/shared/types.d.ts index 060d95e..7eff56e 100644 --- a/src/shared/types.d.ts +++ b/src/shared/types.d.ts @@ -239,6 +239,7 @@ interface IAppConfig { autoQuitWithoutCore?: boolean autoQuitWithoutCoreDelay?: number useCustomSubStore?: boolean + useProxyInSubStore?: boolean customSubStoreUrl?: string diffWorkDir?: boolean autoSetDNS?: boolean