Skip to content

Commit

Permalink
deprecated vbs
Browse files Browse the repository at this point in the history
  • Loading branch information
pompurin404 committed Aug 29, 2024
1 parent 1c924bc commit d250b8b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
12 changes: 11 additions & 1 deletion scripts/prepare.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -312,6 +316,12 @@ const tasks = [
func: resolveSysproxy,
retry: 5,
winOnly: true
},
{
name: 'runner',
func: resolveRunner,
retry: 5,
winOnly: true
}
]

Expand Down
24 changes: 8 additions & 16 deletions src/main/sys/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -81,27 +81,19 @@ const elevateTaskXml = `<?xml version="1.0" encoding="UTF-16"?>
</Settings>
<Actions Context="Author">
<Exec>
<Command>wscript.exe</Command>
<Arguments>"${path.join(taskDir(), `mihomo-party-run.vbs`)}"</Arguments>
<Command>"${path.join(taskDir(), `mihomo-party-run.exe`)}"</Command>
<Arguments>"${exePath()}"</Arguments>
</Exec>
</Actions>
</Task>
`

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')
)
}
7 changes: 4 additions & 3 deletions src/main/utils/dirs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d250b8b

Please sign in to comment.