fix portable

This commit is contained in:
pompurin404 2024-08-29 10:40:48 +08:00
parent 6d3066c522
commit 54306ee64b
No known key found for this signature in database
2 changed files with 7 additions and 7 deletions

View File

@ -15,7 +15,7 @@ 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 { exeDir } from './utils/dirs'
import path from 'path'
export let mainWindow: BrowserWindow | null = null
@ -25,9 +25,9 @@ if (process.platform === 'win32' && !is.dev) {
} catch (e) {
try {
if (process.argv.slice(1).length > 0) {
writeFileSync(path.join(dataDir(), 'param.txt'), process.argv.slice(1).join(' '))
writeFileSync(path.join(exeDir(), 'param.txt'), process.argv.slice(1).join(' '))
} else {
writeFileSync(path.join(dataDir(), 'param.txt'), 'empty')
writeFileSync(path.join(exeDir(), 'param.txt'), 'empty')
}
execSync('schtasks /run /tn mihomo-party-run')
} catch (e) {

View File

@ -3,7 +3,7 @@ import { dialog, nativeTheme } from 'electron'
import { readFile } from 'fs/promises'
import path from 'path'
import { promisify } from 'util'
import { dataDir, exePath, mihomoCorePath, resourcesDir } from '../utils/dirs'
import { exeDir, exePath, mihomoCorePath, resourcesDir } from '../utils/dirs'
import { writeFileSync } from 'fs'
export function getFilePath(ext: string[]): string[] | undefined {
@ -82,7 +82,7 @@ const elevateTaskXml = `<?xml version="1.0" encoding="UTF-16"?>
<Actions Context="Author">
<Exec>
<Command>wscript.exe</Command>
<Arguments>"${path.join(dataDir(), `mihomo-party-run.vbs`)}"</Arguments>
<Arguments>"${path.join(exeDir(), `mihomo-party-run.vbs`)}"</Arguments>
</Exec>
</Actions>
</Task>
@ -100,8 +100,8 @@ shell.Run commandLine, 0, false
`
export function createElevateTask(): void {
const taskFilePath = path.join(dataDir(), `mihomo-party-run.xml`)
writeFileSync(path.join(dataDir(), `mihomo-party-run.vbs`), startScript)
const taskFilePath = path.join(exeDir(), `mihomo-party-run.xml`)
writeFileSync(path.join(exeDir(), `mihomo-party-run.vbs`), startScript)
writeFileSync(taskFilePath, Buffer.from(`\ufeff${elevateTaskXml}`, 'utf-16le'))
execSync(`schtasks /create /tn "mihomo-party-run" /xml "${taskFilePath}" /f`)
}