签出调整
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
@echo off
|
||||
chcp 65001 >nul
|
||||
echo ========================================
|
||||
echo 清理并重新打包`r
|
||||
echo 清理并重新打包
|
||||
echo ========================================
|
||||
echo.
|
||||
|
||||
echo [1/5] 结束所有相关进<EFBFBD>?..
|
||||
echo [1/5] 结束所有相关进程...
|
||||
echo 正在停止 NPQS9100...
|
||||
taskkill /F /IM NPQS9100.exe 2>nul
|
||||
|
||||
echo 正在停止 Java...
|
||||
taskkill /F /IM java.exe 2>nul
|
||||
taskkill /F /IM javaw.exe 2>nul
|
||||
echo <EFBFBD>?所有进程已结束
|
||||
echo ✓ 所有进程已结束
|
||||
timeout /t 2 /nobreak >nul
|
||||
echo.
|
||||
|
||||
@@ -21,48 +21,48 @@ cd /d "%~dp0.."
|
||||
if exist out (
|
||||
rmdir /s /q out 2>nul
|
||||
if exist out (
|
||||
echo <EFBFBD>?删除失败,请手动删除 out 目录
|
||||
echo ✗ 删除失败,请手动删除 out 目录
|
||||
pause
|
||||
exit /b 1
|
||||
) else (
|
||||
echo <EFBFBD>?out 目录已删除`r
|
||||
echo ✓ out 目录已删除
|
||||
)
|
||||
) else (
|
||||
echo <EFBFBD>?out 目录不存在`r
|
||||
echo ✓ out 目录不存在
|
||||
)
|
||||
echo.
|
||||
|
||||
echo [3/5] 构建前端代码...
|
||||
call npm run build-frontend
|
||||
if %errorlevel% neq 0 (
|
||||
echo <EFBFBD>?前端构建失败
|
||||
echo ✗ 前端构建失败
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
echo <EFBFBD>?前端代码构建完成
|
||||
echo ✓ 前端代码构建完成
|
||||
echo.
|
||||
|
||||
echo [4/5] 构建 electron 代码...
|
||||
call npm run build-electron
|
||||
if %errorlevel% neq 0 (
|
||||
echo <EFBFBD>?electron 构建失败
|
||||
echo ✗ electron 构建失败
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
echo <EFBFBD>?electron 代码构建完成
|
||||
echo ✓ electron 代码构建完成
|
||||
echo.
|
||||
|
||||
echo [5/5] 打包 Windows 版本(包含代码加密)...
|
||||
call npm run build-w
|
||||
if %errorlevel% neq 0 (
|
||||
echo <EFBFBD>?打包失败
|
||||
echo ✗ 打包失败
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
echo.
|
||||
|
||||
echo ========================================
|
||||
echo <EFBFBD>?打包完成!`r
|
||||
echo ✓ 打包完成!
|
||||
echo 输出目录: out\win-unpacked\
|
||||
echo ========================================
|
||||
echo.
|
||||
|
||||
@@ -79,6 +79,9 @@
|
||||
],
|
||||
"win": {
|
||||
"icon": "public/images/icon.png",
|
||||
"requestedExecutionLevel": "requireAdministrator",
|
||||
"signAndEditExecutable": false,
|
||||
"verifyUpdateCodeSignature": false,
|
||||
"artifactName": "${productName}-${os}-${version}-${arch}.${ext}",
|
||||
"target": [
|
||||
{
|
||||
|
||||
@@ -565,11 +565,86 @@ class Lifecycle {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否有管理员权限(仅 Windows)
|
||||
*/
|
||||
checkAdminPrivileges() {
|
||||
if (process.platform !== 'win32') {
|
||||
return true; // 非 Windows 系统不需要检查
|
||||
}
|
||||
|
||||
try {
|
||||
const { execSync } = require('child_process');
|
||||
// 尝试执行需要管理员权限的命令
|
||||
execSync('net session', { stdio: 'ignore' });
|
||||
return true;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* electron app ready
|
||||
*/
|
||||
async electronAppReady() {
|
||||
logger.info('[lifecycle] electron-app-ready');
|
||||
|
||||
// 检查管理员权限
|
||||
const hasAdminPrivileges = this.checkAdminPrivileges();
|
||||
logger.info('[lifecycle] Has admin privileges:', hasAdminPrivileges);
|
||||
|
||||
if (!hasAdminPrivileges) {
|
||||
logger.warn('[lifecycle] No admin privileges, will request elevation when needed');
|
||||
|
||||
// 立即请求管理员权限
|
||||
const { dialog, app } = require('electron');
|
||||
const { spawn } = require('child_process');
|
||||
|
||||
setTimeout(async () => {
|
||||
const { response } = await dialog.showMessageBox({
|
||||
type: 'warning',
|
||||
title: '需要管理员权限',
|
||||
message: 'NPQS9100 需要管理员权限来管理 MySQL 服务',
|
||||
detail: '应用将以管理员身份重新启动。\n\n如果您拒绝,应用可能无法正常工作。',
|
||||
buttons: ['退出应用', '以管理员身份启动'],
|
||||
defaultId: 1,
|
||||
cancelId: 0
|
||||
});
|
||||
|
||||
if (response === 0) {
|
||||
logger.info('[lifecycle] User declined admin elevation, quitting');
|
||||
app.quit();
|
||||
return;
|
||||
}
|
||||
|
||||
// 以管理员身份重启
|
||||
try {
|
||||
const exePath = app.getPath('exe');
|
||||
logger.info('[lifecycle] Restarting with admin privileges:', exePath);
|
||||
|
||||
const psCommand = `Start-Process -FilePath "${exePath}" -Verb RunAs`;
|
||||
const child = spawn('powershell.exe', ['-Command', psCommand], {
|
||||
detached: true,
|
||||
stdio: 'ignore',
|
||||
windowsHide: true
|
||||
});
|
||||
|
||||
child.unref();
|
||||
|
||||
// 设置标记,跳过清理
|
||||
this.isRestartingForAdmin = true;
|
||||
|
||||
// 退出当前实例
|
||||
setTimeout(() => {
|
||||
app.quit();
|
||||
}, 500);
|
||||
} catch (error) {
|
||||
logger.error('[lifecycle] Failed to restart as admin:', error);
|
||||
dialog.showErrorBox('启动失败', '无法以管理员身份启动应用,请手动右键选择"以管理员身份运行"');
|
||||
app.quit();
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user