Full update of electron version update (vue)

Portal:

autoUpdater | Electron

electron-builder

1. Configure vue.config.js

The electron-builder          is used for packaging here , and related parameters are configured in vue.config.js: add publish to the builderOptions of electronBuilder:

  pluginOptions: {
    electronBuilder: {
      //...
      builderOptions: {
        //...
        win: {
          //...
          publish: [
            {
              provider: "generic",
              url: "https://xx", //打包出来的文件存放的地址
            },
          ],
        },
        //...
      },
    },
  },

Two, use autoUpdater

        Introduce autoUpdater in the main process:

import { autoUpdater } from "electron-updater";

        Set autoUpdater.setFeedURL("https://xxx"): set to check for updates  url, and initialize automatic updates. The url here must be consistent with the published url.

        Main process:

autoUpdater.setFeedURL(updateUrl); 

if (process.env.WEBPACK_DEV_SERVER_URL) {
} else {
    createProtocol('app')
    win.loadURL('app://./index.html')
    // 检查更新
    autoUpdater.checkForUpdates()
}
//发生错误
autoUpdater.on("error", () => {
    //...
});
//有更新
autoUpdater.on("update-available", () => {
    //...
});
//没有更新
autoUpdater.on("update-not-available", () => {
    //...
});
//下载完成
autoUpdater.on("update-downloaded", () => {
    //...
});

        If you need to restart the app after the download is complete and install the update after downloading, you can autoUpdater.quitAndInstall() in update-downloaded. If you don't need to update immediately, you don't need to deal with it, "Because after the update file is downloaded successfully, the next time the application starts, it will be forced to update."

Summarize

        The above is an introduction to the full update of electron, which is relatively simple, and you can learn from it. If you are interested, you can continue to look at the incremental update: Incremental update of electron version update, no sense update_Zoie_ting's blog-CSDN blog

Guess you like

Origin blog.csdn.net/sxww_zyt/article/details/131005298