From ed69c1261d79ee9bf99d31c71a18c3615d7cfad9 Mon Sep 17 00:00:00 2001 From: pompurin404 Date: Tue, 27 Aug 2024 22:46:38 +0800 Subject: [PATCH] fix url scheme for windows --- src/main/index.ts | 9 ++++++++- src/main/sys/misc.ts | 18 ++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index 4ead4b4..3b3fd4f 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -14,14 +14,21 @@ import { initShortcut } from './resolve/shortcut' import { execSync } from 'child_process' import { createElevateTask } from './sys/misc' import { initProfileUpdater } from './core/profileUpdater' +import { writeFileSync } from 'fs' +import { dataDir } from './utils/dirs' +import path from 'path' export let mainWindow: BrowserWindow | null = null - if (process.platform === 'win32' && !is.dev) { try { createElevateTask() } catch (e) { try { + if (process.argv.slice(1).length > 0) { + writeFileSync(path.join(dataDir(), 'param.txt'), process.argv.slice(1).join(' ')) + } else { + writeFileSync(path.join(dataDir(), 'param.txt'), '') + } execSync('schtasks /run /tn mihomo-party-run') } catch (e) { dialog.showErrorBox('首次启动请以管理员权限运行', '首次启动请以管理员权限运行') diff --git a/src/main/sys/misc.ts b/src/main/sys/misc.ts index b511f40..b73a03a 100644 --- a/src/main/sys/misc.ts +++ b/src/main/sys/misc.ts @@ -2,9 +2,8 @@ import { exec, execFile, execSync } from 'child_process' import { dialog, nativeTheme } from 'electron' import { readFile } from 'fs/promises' import path from 'path' -import os from 'os' import { promisify } from 'util' -import { exePath, mihomoCorePath, resourcesDir } from '../utils/dirs' +import { dataDir, exePath, mihomoCorePath, resourcesDir } from '../utils/dirs' import { writeFileSync } from 'fs' export function getFilePath(ext: string[]): string[] | undefined { @@ -82,14 +81,25 @@ const elevateTaskXml = ` - ${exePath()} + powershell + -WindowStyle Hidden -File "${path.join(dataDir(), `mihomo-party-run.ps1`)}" ` +const startScript = `$paramFilePath = Join-Path -Path $PSScriptRoot -ChildPath "param.txt" +if (Test-Path -Path $paramFilePath) { + $paramContent = Get-Content -Path $paramFilePath + & "${exePath()}" $paramContent +} else { + & "${exePath()}" +} +` + export function createElevateTask(): void { - const taskFilePath = path.join(os.tmpdir(), `mihomo-party-run.xml`) + const taskFilePath = path.join(dataDir(), `mihomo-party-run.xml`) + writeFileSync(path.join(dataDir(), `mihomo-party-run.ps1`), startScript) writeFileSync(taskFilePath, Buffer.from(`\ufeff${elevateTaskXml}`, 'utf-16le')) execSync(`schtasks /create /tn "mihomo-party-run" /xml "${taskFilePath}" /f`) }