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.js
After 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.yml
andExe of the same grade
The 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 because
utoUpdater.setFeedURL()
The service address put inside is wrong, it should be put after packingbuild
Folder inlatest.yml
And the folder has the latest.exe zip package, putlatest.yml
Server address when putting the lastlatest.yml
The suffix is removed becauseelectron-update
thelatest.yml
Stitching on the
- This mistake goes straight to the next pack
latest.yml
Copy toD:\tifang\student-desktop\dist\electron\dev-app-update.yml
This directory, this directory is notdev-app-update.yml
You need to create a new onedev-app-update.yml
Then put thelatest.yml
The content ofdev-app-update.yml
“, and then click Update Now