Update package.json and afterPack.js to set application name and version info, enhancing build process and user experience. Enable executable signing in package.json and improve logging in afterPack.js for better clarity during icon and version setting.

This commit is contained in:
ethanfly 2026-01-04 03:02:48 +08:00
parent 11ad2cf722
commit 982a51ef52
3 changed files with 29 additions and 7 deletions

View File

@ -7,10 +7,11 @@ exports.default = async function(context) {
return; return;
} }
console.log('Running afterPack hook to set icon...'); console.log('Running afterPack hook to set icon and version info...');
const appOutDir = context.appOutDir; const appOutDir = context.appOutDir;
const productName = context.packager.appInfo.productName; const productName = context.packager.appInfo.productName;
const version = context.packager.appInfo.version;
const exePath = path.join(appOutDir, `${productName}.exe`); const exePath = path.join(appOutDir, `${productName}.exe`);
const iconPath = path.join(__dirname, 'icon.ico'); const iconPath = path.join(__dirname, 'icon.ico');
@ -25,18 +26,29 @@ exports.default = async function(context) {
} }
try { try {
// 使用 npm 安装的 rcedit 模块 // rcedit 是默认导出
const { rcedit } = require('rcedit'); const rcedit = require('rcedit');
console.log(`Setting icon for: ${exePath}`); console.log(`Setting icon and version info for: ${exePath}`);
console.log(`Using icon: ${iconPath}`); console.log(`Using icon: ${iconPath}`);
await rcedit(exePath, { await rcedit(exePath, {
icon: iconPath icon: iconPath,
'version-string': {
'ProductName': productName,
'FileDescription': productName,
'CompanyName': 'PHPer',
'LegalCopyright': 'Copyright © 2024 PHPer',
'OriginalFilename': `${productName}.exe`,
'InternalName': productName
},
'file-version': version,
'product-version': version
}); });
console.log('Icon set successfully!'); console.log('Icon and version info set successfully!');
} catch (error) { } catch (error) {
console.error('Failed to set icon:', error.message); console.error('Failed to set icon:', error.message);
// 不阻止打包继续
} }
}; };

View File

@ -241,6 +241,15 @@ function createTray() {
}); });
} }
// 设置应用名称和 Windows AppUserModelId用于任务栏图标分组和进程名称显示
const APP_NAME = "PHPer开发环境管理器";
const APP_ID = "com.phper.devmanager";
app.setName(APP_NAME);
if (process.platform === "win32") {
app.setAppUserModelId(APP_ID);
}
// 单实例锁定 // 单实例锁定
const gotTheLock = app.requestSingleInstanceLock(); const gotTheLock = app.requestSingleInstanceLock();

View File

@ -75,8 +75,9 @@
} }
], ],
"icon": "build/icon.ico", "icon": "build/icon.ico",
"executableName": "PHPer开发环境管理器",
"requestedExecutionLevel": "requireAdministrator", "requestedExecutionLevel": "requireAdministrator",
"signAndEditExecutable": false "signAndEditExecutable": true
}, },
"nsis": { "nsis": {
"oneClick": false, "oneClick": false,