mirror of
https://github.com/pompurin404/mihomo-party.git
synced 2024-11-16 11:42:19 +08:00
fix schtasks
This commit is contained in:
parent
ccc03c8ae0
commit
72c1acdfd2
|
@ -1,8 +1,4 @@
|
|||
### New Features
|
||||
|
||||
- 支持通过代理拉取内置 SubStore 订阅(仅对通过订阅页面Sub-Store图标新导入的订阅有效)
|
||||
- 支持根据网速快慢旋转悬浮窗图标
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- 修复某些 Windows 设备反复提示管理员权限启动的问题
|
||||
- 修复 macOS 自动更新失败的问题
|
||||
- 修复某些 Windows 管理员权限依然无法启动的问题
|
||||
|
|
|
@ -25,7 +25,7 @@ export let mainWindow: BrowserWindow | null = null
|
|||
if (process.platform === 'win32' && !is.dev && !process.argv.includes('noadmin')) {
|
||||
try {
|
||||
createElevateTask()
|
||||
} catch (e) {
|
||||
} catch (createError) {
|
||||
try {
|
||||
if (process.argv.slice(1).length > 0) {
|
||||
writeFileSync(path.join(taskDir(), 'param.txt'), process.argv.slice(1).join(' '))
|
||||
|
@ -35,10 +35,13 @@ if (process.platform === 'win32' && !is.dev && !process.argv.includes('noadmin')
|
|||
if (!existsSync(path.join(taskDir(), 'mihomo-party-run.exe'))) {
|
||||
throw new Error('mihomo-party-run.exe not found')
|
||||
} else {
|
||||
execSync('schtasks /run /tn mihomo-party-run')
|
||||
execSync('C:\\\\Windows\\System32\\schtasks.exe /run /tn mihomo-party-run')
|
||||
}
|
||||
} catch (e) {
|
||||
dialog.showErrorBox('首次启动请以管理员权限运行', '首次启动请以管理员权限运行')
|
||||
dialog.showErrorBox(
|
||||
'首次启动请以管理员权限运行',
|
||||
`首次启动请以管理员权限运行\n${createError}\n${e}`
|
||||
)
|
||||
} finally {
|
||||
app.exit()
|
||||
}
|
||||
|
|
|
@ -56,7 +56,9 @@ export async function checkAutoRun(): Promise<boolean> {
|
|||
if (process.platform === 'win32') {
|
||||
const execPromise = promisify(exec)
|
||||
try {
|
||||
const { stdout } = await execPromise(`chcp 437 && schtasks /query /tn "${appName}"`)
|
||||
const { stdout } = await execPromise(
|
||||
`chcp 437 && C:\\\\Windows\\System32\\schtasks.exe /query /tn "${appName}"`
|
||||
)
|
||||
return stdout.includes(appName)
|
||||
} catch (e) {
|
||||
return false
|
||||
|
@ -82,7 +84,9 @@ export async function enableAutoRun(): Promise<void> {
|
|||
const execPromise = promisify(exec)
|
||||
const taskFilePath = path.join(taskDir(), `${appName}.xml`)
|
||||
await writeFile(taskFilePath, Buffer.from(`\ufeff${taskXml}`, 'utf-16le'))
|
||||
await execPromise(`schtasks /create /tn "${appName}" /xml "${taskFilePath}" /f`)
|
||||
await execPromise(
|
||||
`C:\\\\Windows\\System32\\schtasks.exe /create /tn "${appName}" /xml "${taskFilePath}" /f`
|
||||
)
|
||||
}
|
||||
if (process.platform === 'darwin') {
|
||||
const execPromise = promisify(exec)
|
||||
|
@ -118,7 +122,7 @@ Categories=Utility;
|
|||
export async function disableAutoRun(): Promise<void> {
|
||||
if (process.platform === 'win32') {
|
||||
const execPromise = promisify(exec)
|
||||
await execPromise(`schtasks /delete /tn "${appName}" /f`)
|
||||
await execPromise(`C:\\\\Windows\\System32\\schtasks.exe /delete /tn "${appName}" /f`)
|
||||
}
|
||||
if (process.platform === 'darwin') {
|
||||
const execPromise = promisify(exec)
|
||||
|
|
|
@ -108,9 +108,11 @@ const elevateTaskXml = `<?xml version="1.0" encoding="UTF-16"?>
|
|||
export function createElevateTask(): void {
|
||||
const taskFilePath = path.join(taskDir(), `mihomo-party-run.xml`)
|
||||
writeFileSync(taskFilePath, Buffer.from(`\ufeff${elevateTaskXml}`, 'utf-16le'))
|
||||
execSync(`schtasks /create /tn "mihomo-party-run" /xml "${taskFilePath}" /f`)
|
||||
copyFileSync(
|
||||
path.join(resourcesFilesDir(), 'mihomo-party-run.exe'),
|
||||
path.join(taskDir(), 'mihomo-party-run.exe')
|
||||
)
|
||||
execSync(
|
||||
`C:\\\\Windows\\System32\\schtasks.exe /create /tn "mihomo-party-run" /xml "${taskFilePath}" /f`
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user