electron 自动更新静默安装到一半就失败

第一种情况:

原因是我设置了阻止关闭事件

let canQuit = false;
 
mainWindow.on('close', (event) => {
    if (!canQuit) {
        mainWindow.hide();
        mainWindow.setSkipTaskbar(true);
        event.preventDefault();
    }
});
所以在执行 autoUpdater.quitAndInstall(); 方法之前要加上 canQuit = true;

if (process.platform !== 'darwin') {
    canQuit = true;
    autoUpdater.quitAndInstall();
}
问题解决~

 

 

把exe应用默认安装到了用户上,然后更新的时候就闪退,或者安装第二次的时候就闪退!

"electron-builder": "^22.8.1",

特别强调nsis配置:

"nsis": {
      "oneClick": false,
      "perMachine": true, // 配置为true,不认默认就是安装到了隐藏文件的用户上。
      "allowElevation": true,
      "allowToChangeInstallationDirectory": true,
      "installerIcon": "build/icons/icon.ico",
      "uninstallerIcon": "build/icons/icon.ico",
      "installerHeaderIcon": "build/icons/icon.ico",
      "createDesktopShortcut": true,
      "createStartMenuShortcut": true,
      "deleteAppDataOnUninstall": true,
      "menuCategory": true,
      "artifactName": "${productName}.${ext}", // 这是是坑千万别这样写,为了打出来的包名好看,这样写会导致你的应用第二次安装失败 中途闪退
"artifactName": "${productName}${version}.${ext}", // 你得这样写,得加上版本号! 默认为artifactName字符串-工件文件名模板默认为${productName} Setup ${version}.${ext}
"shortcutName": "商盟订货"
},

 

 

3. package.json的build配置顺序很重要

"build": {
    "extraFiles": [],
    "publish": [
      {
        "provider": "generic",
        "url": "https://sm2.35dinghuo.com/download/"
      }
    ],
    "productName": "shangmengdinghuo",
    "appId": "com.35dinghuo.www",
    "directories": {
      "output": "build"
    },
    "nsis": {
      "oneClick": false,
      "perMachine": true,
      "allowElevation": true,
      "allowToChangeInstallationDirectory": true,
      "installerIcon": "build/icons/icon.ico",
      "uninstallerIcon": "build/icons/icon.ico",
      "installerHeaderIcon": "build/icons/icon.ico",
      "createDesktopShortcut": true,
      "createStartMenuShortcut": true,
      "deleteAppDataOnUninstall": true,
      "artifactName": "${productName}${version}.${ext}",
      "shortcutName": "商盟订货"
    },
    "files": [
      "dist/electron/**/*"
    ],
    "dmg": {
      "contents": [
        {
          "x": 410,
          "y": 150,
          "type": "link",
          "path": "/Applications"
        },
        {
          "x": 130,
          "y": 150,
          "type": "file"
        }
      ]
    },
    "mac": {
      "icon": "build/icons/icon.icns"
    },
    "win": {
      "icon": "build/icons/icon.ico",
      "target": "nsis"
    },
    "linux": {
      "target": "deb",
      "icon": "build/icons"
    }
  },

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章