From 911d72975eaca52e77a4dbfea39be605bec1c69e Mon Sep 17 00:00:00 2001 From: pompurin404 Date: Mon, 21 Oct 2024 12:03:22 +0800 Subject: [PATCH] readable error output --- package.json | 1 + pnpm-lock.yaml | 3 +++ src/main/index.ts | 13 +++++++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 073a54c..519d0f3 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "chokidar": "^4.0.1", "dayjs": "^1.11.13", "express": "^5.0.1", + "iconv-lite": "^0.6.3", "webdav": "^5.7.1", "ws": "^8.18.0", "yaml": "^2.6.0" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4a47b41..edce098 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -32,6 +32,9 @@ importers: express: specifier: ^5.0.1 version: 5.0.1 + iconv-lite: + specifier: ^0.6.3 + version: 0.6.3 webdav: specifier: ^5.7.1 version: 5.7.1 diff --git a/src/main/index.ts b/src/main/index.ts index f3e6950..815ee39 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -18,11 +18,12 @@ import { exePath, taskDir } from './utils/dirs' import path from 'path' import { startMonitor } from './resolve/trafficMonitor' import { showFloatingWindow } from './resolve/floatingWindow' +import iconv from 'iconv-lite' let quitTimeout: NodeJS.Timeout | null = null export let mainWindow: BrowserWindow | null = null -if (process.platform === 'win32' && !is.dev && !process.argv.includes('noadmin')) { +if (process.platform === 'win32' && !process.argv.includes('noadmin')) { try { createElevateTask() } catch (createError) { @@ -38,9 +39,17 @@ if (process.platform === 'win32' && !is.dev && !process.argv.includes('noadmin') execSync('C:\\\\Windows\\System32\\schtasks.exe /run /tn mihomo-party-run') } } catch (e) { + let createErrorStr = `${createError}` + let eStr = `${e}` + try { + createErrorStr = iconv.decode((createError as { stderr: Buffer }).stderr, 'gbk') + eStr = iconv.decode((e as { stderr: Buffer }).stderr, 'gbk') + } catch { + // ignore + } dialog.showErrorBox( '首次启动请以管理员权限运行', - `首次启动请以管理员权限运行\n${createError}\n${e}` + `首次启动请以管理员权限运行\n${createErrorStr}\n${eStr}` ) } finally { app.exit()