From daf5152dd3300df5530d4eaa3437f0d219ba5691 Mon Sep 17 00:00:00 2001 From: pompurin404 Date: Fri, 16 Aug 2024 15:33:14 +0800 Subject: [PATCH] fix windows auto start --- src/main/index.ts | 3 +- src/main/sys/autoRun.ts | 86 ++++++++++++++++++++--------------------- 2 files changed, 45 insertions(+), 44 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index e46cc83..4da3b40 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -2,7 +2,7 @@ import { electronApp, optimizer, is } from '@electron-toolkit/utils' import { registerIpcMainHandlers } from './utils/ipc' import windowStateKeeper from 'electron-window-state' import { app, shell, BrowserWindow, Menu, dialog, Notification } from 'electron' -import { startMihomoMemory, stopMihomoMemory } from './core/mihomoApi' +import { pauseWebsockets, startMihomoMemory, stopMihomoMemory } from './core/mihomoApi' import { addProfileItem, getAppConfig } from './config' import { stopCore } from './core/manager' import { triggerSysProxy } from './sys/sysproxy' @@ -43,6 +43,7 @@ app.on('window-all-closed', (e) => { }) app.on('before-quit', () => { + pauseWebsockets() stopCore() triggerSysProxy(false) app.exit() diff --git a/src/main/sys/autoRun.ts b/src/main/sys/autoRun.ts index 922b36a..8c10da3 100644 --- a/src/main/sys/autoRun.ts +++ b/src/main/sys/autoRun.ts @@ -8,48 +8,48 @@ import path from 'path' const appName = 'mihomo-party' -const taskXml = ` - - - ${new Date().toISOString()} - ${process.env.USERNAME} - - - - true - - - - - InteractiveToken - HighestAvailable - - - - IgnoreNew - false - false - false - true - true - - false - false - - true - true - false - false - false - PT0S - 7 - - - - ${exePath()} - - - +const taskXml = ` + + + ${new Date().toISOString()} + ${process.env.USERNAME} + + + + true + + + + + InteractiveToken + HighestAvailable + + + + IgnoreNew + false + false + false + true + true + + false + false + + true + true + false + false + false + PT0S + 7 + + + + ${exePath()} + + + ` export async function checkAutoRun(): Promise { @@ -77,7 +77,7 @@ export async function enableAutoRun(): Promise { if (process.platform === 'win32') { const execPromise = promisify(exec) const taskFilePath = path.join(dataDir(), `${appName}.xml`) - await writeFile(taskFilePath, taskXml) + await writeFile(taskFilePath, Buffer.from(`\ufeff${taskXml}`, 'utf-16le')) await execPromise(`schtasks /create /tn "${appName}" /xml "${taskFilePath}" /f`) } if (process.platform === 'darwin') {