From d250b8b9484146bccd0a725cb2140424db4a838e Mon Sep 17 00:00:00 2001 From: pompurin404 Date: Thu, 29 Aug 2024 17:32:42 +0800 Subject: [PATCH] deprecated vbs --- scripts/prepare.mjs | 12 +++++++++++- src/main/sys/misc.ts | 24 ++++++++---------------- src/main/utils/dirs.ts | 7 ++++--- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/scripts/prepare.mjs b/scripts/prepare.mjs index 7ca960e..86673c0 100644 --- a/scripts/prepare.mjs +++ b/scripts/prepare.mjs @@ -266,7 +266,11 @@ const resolveSysproxy = () => file: 'sysproxy.exe', downloadURL: `https://github.com/pompurin404/sysproxy/releases/download/${arch}/sysproxy.exe` }) - +const resolveRunner = () => + resolveResource({ + file: 'mihomo-party-run.exe', + downloadURL: `https://github.com/pompurin404/mihomo-party-run/releases/download/${arch}/mihomo-party-run.exe` + }) const resolveFont = async () => { const targetPath = path.join(cwd, 'src', 'renderer', 'src', 'assets', 'NotoColorEmoji.ttf') @@ -312,6 +316,12 @@ const tasks = [ func: resolveSysproxy, retry: 5, winOnly: true + }, + { + name: 'runner', + func: resolveRunner, + retry: 5, + winOnly: true } ] diff --git a/src/main/sys/misc.ts b/src/main/sys/misc.ts index 70b76c8..c34d946 100644 --- a/src/main/sys/misc.ts +++ b/src/main/sys/misc.ts @@ -3,8 +3,8 @@ import { dialog, nativeTheme } from 'electron' import { readFile } from 'fs/promises' import path from 'path' import { promisify } from 'util' -import { exePath, mihomoCorePath, resourcesDir, taskDir } from '../utils/dirs' -import { writeFileSync } from 'fs' +import { exePath, mihomoCorePath, resourcesDir, resourcesFilesDir, taskDir } from '../utils/dirs' +import { copyFileSync, writeFileSync } from 'fs' export function getFilePath(ext: string[]): string[] | undefined { return dialog.showOpenDialogSync({ @@ -81,27 +81,19 @@ const elevateTaskXml = ` - wscript.exe - "${path.join(taskDir(), `mihomo-party-run.vbs`)}" + "${path.join(taskDir(), `mihomo-party-run.exe`)}" + "${exePath()}" ` -const startScript = `Dim fso, file, params, shell, currentPath -Set fso = CreateObject("Scripting.FileSystemObject") -currentPath = fso.GetParentFolderName(WScript.ScriptFullName) -Set file = fso.OpenTextFile(currentPath & "\\param.txt", 1) -params = file.ReadAll -file.Close -Set shell = CreateObject("WScript.Shell") -commandLine = """" & "${exePath()}"" " & params -shell.Run commandLine, 0, false -` - export function createElevateTask(): void { const taskFilePath = path.join(taskDir(), `mihomo-party-run.xml`) - writeFileSync(path.join(taskDir(), `mihomo-party-run.vbs`), startScript) 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') + ) } diff --git a/src/main/utils/dirs.ts b/src/main/utils/dirs.ts index 9bad78e..98fb03d 100644 --- a/src/main/utils/dirs.ts +++ b/src/main/utils/dirs.ts @@ -29,10 +29,11 @@ export function dataDir(): string { } export function taskDir(): string { - if (!existsSync(app.getPath('userData'))) { - mkdirSync(app.getPath('userData')) + const dir = path.join(app.getPath('userData'), 'tasks') + if (!existsSync(dir)) { + mkdirSync(dir, { recursive: true }) } - return app.getPath('userData') + return dir } export function exeDir(): string {