mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2026-02-11 04:00:32 +08:00
fix url scheme for windows
This commit is contained in:
parent
91ff99b72d
commit
ed69c1261d
@ -14,14 +14,21 @@ import { initShortcut } from './resolve/shortcut'
|
|||||||
import { execSync } from 'child_process'
|
import { execSync } from 'child_process'
|
||||||
import { createElevateTask } from './sys/misc'
|
import { createElevateTask } from './sys/misc'
|
||||||
import { initProfileUpdater } from './core/profileUpdater'
|
import { initProfileUpdater } from './core/profileUpdater'
|
||||||
|
import { writeFileSync } from 'fs'
|
||||||
|
import { dataDir } from './utils/dirs'
|
||||||
|
import path from 'path'
|
||||||
|
|
||||||
export let mainWindow: BrowserWindow | null = null
|
export let mainWindow: BrowserWindow | null = null
|
||||||
|
|
||||||
if (process.platform === 'win32' && !is.dev) {
|
if (process.platform === 'win32' && !is.dev) {
|
||||||
try {
|
try {
|
||||||
createElevateTask()
|
createElevateTask()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
try {
|
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')
|
execSync('schtasks /run /tn mihomo-party-run')
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
dialog.showErrorBox('首次启动请以管理员权限运行', '首次启动请以管理员权限运行')
|
dialog.showErrorBox('首次启动请以管理员权限运行', '首次启动请以管理员权限运行')
|
||||||
|
|||||||
@ -2,9 +2,8 @@ import { exec, execFile, execSync } from 'child_process'
|
|||||||
import { dialog, nativeTheme } from 'electron'
|
import { dialog, nativeTheme } from 'electron'
|
||||||
import { readFile } from 'fs/promises'
|
import { readFile } from 'fs/promises'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import os from 'os'
|
|
||||||
import { promisify } from 'util'
|
import { promisify } from 'util'
|
||||||
import { exePath, mihomoCorePath, resourcesDir } from '../utils/dirs'
|
import { dataDir, exePath, mihomoCorePath, resourcesDir } from '../utils/dirs'
|
||||||
import { writeFileSync } from 'fs'
|
import { writeFileSync } from 'fs'
|
||||||
|
|
||||||
export function getFilePath(ext: string[]): string[] | undefined {
|
export function getFilePath(ext: string[]): string[] | undefined {
|
||||||
@ -82,14 +81,25 @@ const elevateTaskXml = `<?xml version="1.0" encoding="UTF-16"?>
|
|||||||
</Settings>
|
</Settings>
|
||||||
<Actions Context="Author">
|
<Actions Context="Author">
|
||||||
<Exec>
|
<Exec>
|
||||||
<Command>${exePath()}</Command>
|
<Command>powershell</Command>
|
||||||
|
<Arguments>-WindowStyle Hidden -File "${path.join(dataDir(), `mihomo-party-run.ps1`)}"</Arguments>
|
||||||
</Exec>
|
</Exec>
|
||||||
</Actions>
|
</Actions>
|
||||||
</Task>
|
</Task>
|
||||||
`
|
`
|
||||||
|
|
||||||
|
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 {
|
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'))
|
writeFileSync(taskFilePath, Buffer.from(`\ufeff${elevateTaskXml}`, 'utf-16le'))
|
||||||
execSync(`schtasks /create /tn "mihomo-party-run" /xml "${taskFilePath}" /f`)
|
execSync(`schtasks /create /tn "mihomo-party-run" /xml "${taskFilePath}" /f`)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user