Skip to content

Commit

Permalink
support reset application
Browse files Browse the repository at this point in the history
  • Loading branch information
pompurin404 committed Nov 23, 2024
1 parent ec3efe8 commit 22c35b6
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 115 deletions.
12 changes: 6 additions & 6 deletions src/main/config/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ export async function createProfile(item: Partial<IProfileItem>): Promise<IProfi
res = await axios.get(item.url, {
proxy: newItem.useProxy
? {
protocol: 'http',
host: '127.0.0.1',
port: mixedPort
}
protocol: 'http',
host: '127.0.0.1',
port: mixedPort
}
: false,
headers: {
'User-Agent': userAgent || 'clash.meta'
Expand Down Expand Up @@ -222,7 +222,7 @@ function parseSubinfo(str: string): ISubscriptionUserInfo {
}

function isAbsolutePath(path: string): boolean {
return path.startsWith('/') || /^[a-zA-Z]:\\/.test(path);
return path.startsWith('/') || /^[a-zA-Z]:\\/.test(path)
}

export async function getFileStr(path: string): Promise<string> {
Expand All @@ -239,4 +239,4 @@ export async function setFileStr(path: string, content: string): Promise<void> {
} else {
await writeFile(mihomoProfileWorkDir(path), content, 'utf-8')
}
}
}
35 changes: 33 additions & 2 deletions src/main/sys/misc.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { exec, execFile, execSync } from 'child_process'
import { dialog, nativeTheme, shell } from 'electron'
import { exec, execFile, execSync, spawn } from 'child_process'
import { app, dialog, nativeTheme, shell } from 'electron'
import { readFile } from 'fs/promises'
import path from 'path'
import { promisify } from 'util'
import {
dataDir,
exePath,
mihomoCorePath,
overridePath,
Expand Down Expand Up @@ -112,3 +113,33 @@ export function createElevateTask(): void {
`%SystemRoot%\\System32\\schtasks.exe /create /tn "mihomo-party-run" /xml "${taskFilePath}" /f`
)
}

export function resetAppConfig(): void {
if (process.platform === 'win32') {
spawn(
'cmd',
[
'/C',
`"timeout /t 2 /nobreak >nul && rmdir /s /q "${dataDir()}" && start "" "${exePath()}""`
],
{
shell: true,
detached: true
}
).unref()
} else {
const script = `while kill -0 ${process.pid} 2>/dev/null; do
sleep 0.1
done
rm -rf '${dataDir()}'
${process.argv.join(' ')} & disown
exit
`
spawn('sh', ['-c', `"${script}"`], {
shell: true,
detached: true,
stdio: 'ignore'
})
}
app.quit()
}
2 changes: 2 additions & 0 deletions src/main/utils/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import {
openFile,
openUWPTool,
readTextFile,
resetAppConfig,
setNativeTheme,
setupFirewall
} from '../sys/misc'
Expand Down Expand Up @@ -246,6 +247,7 @@ export function registerIpcMainHandlers(): void {
ipcMain.handle('alert', (_e, msg) => {
dialog.showErrorBox('Mihomo Party', msg)
})
ipcMain.handle('resetAppConfig', resetAppConfig)
ipcMain.handle('relaunchApp', () => {
app.relaunch()
app.quit()
Expand Down
Loading

0 comments on commit 22c35b6

Please sign in to comment.