diff --git a/src/main/config/override.ts b/src/main/config/override.ts index 41fec4e..b3df855 100644 --- a/src/main/config/override.ts +++ b/src/main/config/override.ts @@ -56,10 +56,6 @@ export async function createOverride(item: Partial): Promise): Promise): Promise): Promise): Promise { if (trafficRetry) { trafficRetry-- mihomoTraffic() - } else { - dialog.showErrorBox('External controller traffic error', 'Retry limit reached') } } @@ -234,8 +231,6 @@ const mihomoMemory = (): void => { if (memoryRetry) { memoryRetry-- mihomoMemory() - } else { - dialog.showErrorBox('External controller memory error', 'Retry limit reached') } } @@ -281,8 +276,6 @@ const mihomoLogs = (): void => { if (logsRetry) { logsRetry-- mihomoLogs() - } else { - dialog.showErrorBox('External controller logs error', 'Retry limit reached') } } @@ -328,8 +321,6 @@ const mihomoConnections = (): void => { if (connectionsRetry) { connectionsRetry-- mihomoConnections() - } else { - dialog.showErrorBox('External controller connections error', 'Retry limit reached') } } diff --git a/src/main/core/profileUpdater.ts b/src/main/core/profileUpdater.ts index 58c6052..6490166 100644 --- a/src/main/core/profileUpdater.ts +++ b/src/main/core/profileUpdater.ts @@ -1,34 +1,42 @@ -import { addProfileItem, getProfileConfig, getProfileItem } from '../config' +import { addProfileItem, getCurrentProfileItem, getProfileConfig, getProfileItem } from '../config' const intervalPool: Record = {} -export function initProfileUpdater(): void { - const { items } = getProfileConfig() - - for (const item of items) { +export async function initProfileUpdater(): Promise { + const { items, current } = getProfileConfig() + const currentItem = getCurrentProfileItem() + for (const item of items.filter((i) => i.id !== current)) { if (item.type === 'remote' && item.interval) { - addProfileItem(getProfileItem(item.id)) + await addProfileItem(item) intervalPool[item.id] = setInterval( - () => { - addProfileItem(getProfileItem(item.id)) + async () => { + await addProfileItem(item) }, item.interval * 60 * 1000 ) } } + if (currentItem.type === 'remote' && currentItem.interval) { + await addProfileItem(currentItem) + intervalPool[currentItem.id] = setInterval( + async () => { + await addProfileItem(currentItem) + }, + currentItem.interval * 60 * 1000 + 10000 // +10s + ) + } } export function addProfileUpdater(id: string): void { - const { items } = getProfileConfig() - const item = items.find((i) => i.id === id) + const item = getProfileItem(id) - if (item?.type === 'remote' && item.interval) { + if (item.type === 'remote' && item.interval) { if (intervalPool[id]) { clearInterval(intervalPool[id]) } intervalPool[id] = setInterval( - () => { - addProfileItem(getProfileItem(id)) + async () => { + await addProfileItem(item) }, item.interval * 60 * 1000 ) diff --git a/src/main/core/tray.ts b/src/main/core/tray.ts index a96f4df..82fa102 100644 --- a/src/main/core/tray.ts +++ b/src/main/core/tray.ts @@ -74,7 +74,6 @@ const buildContextMenu = (): Menu => { window?.webContents.send('appConfigUpdated') } catch (e) { setAppConfig({ sysProxy: { enable: !enable } }) - console.error(e) } finally { updateTrayMenu() } diff --git a/src/main/index.ts b/src/main/index.ts index 7a8a6b4..f6e324e 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -59,9 +59,9 @@ if (!gotTheLock) { // Set app user model id for windows electronApp.setAppUserModelId('party.mihomo.app') startCore().then(() => { - setTimeout(() => { - initProfileUpdater() - }, 30000) + setTimeout(async () => { + await initProfileUpdater() + }, 60000) }) // Default open or close DevTools by F12 in development // and ignore CommandOrControl + R in production. diff --git a/src/main/utils/ipc.ts b/src/main/utils/ipc.ts index 817f4c7..33f513b 100644 --- a/src/main/utils/ipc.ts +++ b/src/main/utils/ipc.ts @@ -116,7 +116,7 @@ export function registerIpcMainHandlers(): void { function getFilePath(ext: string[]): string[] | undefined { return dialog.showOpenDialogSync({ title: '选择订阅文件', - filters: [{ name: 'Yaml Files', extensions: ext }], + filters: [{ name: `${ext} file`, extensions: ext }], properties: ['openFile'] }) } diff --git a/src/renderer/src/components/sider/sysproxy-switcher.tsx b/src/renderer/src/components/sider/sysproxy-switcher.tsx index 7dd2fe5..e0e5719 100644 --- a/src/renderer/src/components/sider/sysproxy-switcher.tsx +++ b/src/renderer/src/components/sider/sysproxy-switcher.tsx @@ -19,12 +19,8 @@ const SysproxySwitcher: React.FC = () => { id: 'sysproxy' }) const onChange = async (enable: boolean): Promise => { - try { - await triggerSysProxy(enable) - await patchAppConfig({ sysProxy: { enable } }) - } catch (e) { - console.error(e) - } + await triggerSysProxy(enable) + await patchAppConfig({ sysProxy: { enable } }) } return ( diff --git a/src/renderer/src/pages/syspeoxy.tsx b/src/renderer/src/pages/syspeoxy.tsx index 385f6ca..85f2885 100644 --- a/src/renderer/src/pages/syspeoxy.tsx +++ b/src/renderer/src/pages/syspeoxy.tsx @@ -90,9 +90,8 @@ const Sysproxy: React.FC = () => { try { await triggerSysProxy(true) await patchAppConfig({ sysProxy: { enable: true } }) - } catch (e) { + } catch { await patchAppConfig({ sysProxy: { enable: false } }) - console.error(e) } }