The installationelectron-updater

   npm install electron-updater
Copy the code

Send a message to the main renderer process when you click Update Now in the renderer process. This update now is a popover of an update written in the renderer process

  this.$ipcApi.send('download-client')   
Copy the code

In the main process, the new version is automatically installed

import {app, BrowserWindow, ipcMain} from 'electron' import pkg from '.. /.. /.. Json '// Note that autoUpdater is not the autoUpdater import IO from './ IO' import {autoUpdater} from electron "Electron -updater" let mainWindow //win is the current window passed through ipcmain, since I created the update.js file, Function handleUpdate(win) {mainWindow = win const returnData = {error: {status: -1, MSG: Checking: {status: 0, MSG: 'checking for update '}, updateAva: {status: 1, MSG:' checking for update '}, updateNotAva: {status: -1, MSG: 'You are using the latest version, no need to update! '}}; / / tell rendering process whether to accept the message mainWindow. WebContents. Send (' downloadInfo ', 'click update now whether trigger') / / Settings are automatically downloaded, the default is true, when click the detected a new version, will automatically download the installation package, // Autoupder. autoDownload = false /* Latest. Yml is the latest version of the server. UpdataPath = 'server address' autoupderater. SetFeedURL ({provider: 'generic', url:updataPath, updaterCacheDirName:'tfstudent-updater' }); Autoupder. on('error', function (error) {sendUpdateMessage(returndata.error)}); Autoupder. on('checking-for-update', function () {sendUpdateMessage(win, returndata.checking)}); Autoupder. on('update-available', function (info) {sendUpdateMessage(win, returndata.updateava)}); Autoupder. on('update-not-available', function (info) { setTimeout(function () { sendUpdateMessage(returnData.updateNotAva) }, 1000); }); // Update download progress event autoupder. on('download-progress', function (progressObj) { mainWindow.webContents.send('autodownloadprogress', progressObj) }); AutoUpdater. On ('update-downloaded', function (event, releaseNotes, releaseName, releaseDate, updateUrl) quitAndUpdate) { mainWindow.webContents.send('isUpdateNow') autoUpdater.quitAndInstall(); }); / / perform automatic update check autoUpdater. CheckForUpdates (); } // Send events through main to renderer, Prompt update information function sendUpdateMessage (win, text) {mainWindow. WebContents. Send (' messageupdate ', text) } export default handleUpdateCopy the code

The main processupdata.jsAfter the execution is complete, the server will package the installation directly. The new address is the latest compressed package and put it on the serverlatest.ymlandExe of the same gradeThe package

The content of the latest. Yml

Version: 9.1.10 Files: - URL: package name SHA512: a key for version detection Size: 309004610 isAdminRightsRequired: True Path: package name sha512: ReleaseDate: '2021-05-20T10:06:20.027z'Copy the code

Some error messages were reported for local execution

  • This is a mistake becauseutoUpdater.setFeedURL()The service address put inside is wrong, it should be put after packingbuildFolder inlatest.ymlAnd the folder has the latest.exe zip package, putlatest.ymlServer address when putting the lastlatest.ymlThe suffix is removed becauseelectron-updatethelatest.ymlStitching on the

  • This mistake goes straight to the next packlatest.ymlCopy toD:\tifang\student-desktop\dist\electron\dev-app-update.ymlThis directory, this directory is notdev-app-update.ymlYou need to create a new onedev-app-update.ymlThen put thelatest.ymlThe content ofdev-app-update.yml“, and then click Update Now