You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改基于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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 13:52:20