如何修改基于electron-forge的electron-wix-msi安装程序?
解决方案
1. 添加桌面图标可选复选框
默认情况下electron-wix-msi会自动创建桌面快捷方式,要改成用户可选,需在maker配置里自定义桌面快捷方式组件,并在安装UI中添加对应的复选框:
在你的Electron Forge配置文件(如forge.config.js)中,修改@electron-forge/maker-wix的配置:
module.exports = { makers: [ { name: '@electron-forge/maker-wix', config: { // 保留原有配置(如appName、version等) components: [ { id: 'DesktopShortcutComponent', guid: '{生成一个唯一GUID}', // 可用uuidgen命令或在线工具生成唯一值 conditions: ['NOT Installed'], features: [ { id: 'DesktopShortcutFeature', title: '创建桌面快捷方式', description: '在桌面添加应用快捷方式', level: 1, display: 'expand', allowAdvertise: false, typicalDefault: 'install', custom: { UIRef: 'DesktopShortcutCheckbox' } } ], shortcuts: [ { name: '你的应用名称', description: '应用描述', target: '[INSTALLDIR]你的主程序.exe', // 替换为你的主程序文件名 workingDirectory: '[INSTALLDIR]', icon: '[INSTALLDIR]你的主程序.exe', iconIndex: 0, showCommand: 'normal', wixShortcutId: 'DesktopShortcut', extension: 'exe' } ] } ], ui: { chooseDirectory: true, elements: [ { name: 'DesktopShortcutCheckbox', type: 'Checkbox', x: 20, y: 200, width: 300, height: 17, text: '创建桌面快捷方式', checkboxValue: '1', defaultValue: '1', // 可设为'0'默认不勾选 property: 'DESKTOP_SHORTCUT' } ] } } } ] };
2. 设置autoUpdate默认勾选或隐藏选项
针对autoUpdate的配置直接在maker参数中修改即可:
方法1:默认勾选autoUpdate
在@electron-forge/maker-wix的config中添加autoUpdate字段,设置默认值为true:
module.exports = { makers: [ { name: '@electron-forge/maker-wix', config: { // 其他原有配置 autoUpdate: { default: true // 设置默认勾选 } } } ] };
方法2:隐藏autoUpdate选项并自动启用
如果想完全隐藏该选项,同时后台自动开启更新功能:
module.exports = { makers: [ { name: '@electron-forge/maker-wix', config: { // 其他原有配置 autoUpdate: { default: true, visible: false // 隐藏UI选项,后台自动启用更新 } } } ] };
内容的提问来源于stack exchange,提问作者Mindfuc
相关产品推荐
相关产品推荐

