Front-end engineers can use Electron to write PC applications very easily, and there are many ways to apply the update application, see the details of the update application.

My project is built based on the electron vue, and the build package generates the installation package using the electron Builder, so update the natural choice electron updater.

  1. To implement automatic updates, you first need to install the electron-updater package:
Yarn add [email protected] - DCopy the code

There is a pit here. If you use the project constructed by electron vUE like me, then the electron version should also be 2.x. By December 16, 2018, electron VUE still uses “electron”: “^2.0.4”, if you install the latest electron-updater directly, your update will fail.

So there are two options, one is to upgrade your electron and the other is to install the 3.x electron updater.

  1. Then make a small change to package.json:
. "build": { "productName": "xingsanhao", "appId": "com.example.yourapp", "directories": { "output": "Build"}, "publish" : [{" provider ":" generic ", "url" : "http://10.0.1.42:88/"}], "files" : [ "dist/electron/**/*" ], ...Copy the code

The content in build is the configuration required by the electron-Builder package, now we need to add the configuration required by the electron-updater publish, I choose the ordinary server here, of course, you can also use GitHub and other free hosting. Refer to documentation for details.

  1. Create file server, test environment can be set up directly with Express:
// app.js

var express = require('express')
var fs = require('fs')
const path = require('path')
var app = express()

app.use(express.static(path.join(__dirname, './client')))

var server = app.listen(88, function () {
  var host = server.address().address;
  var port = server.address().port;

  console.log('Example app listening at http://%s:%s', host, port);
});
Copy the code

Packaging generated installation package and latest yml file on the client in this folder, so we can through the http://10.0.1.42:88/latest.yml access to latest. Yml this file.

So in package.json configuration, publish url is simply http://10.0.1.42:88/.

  1. Finally, check the updated code

I will not write the code, Baidu and documentation, this is relatively simple, you want to automatically check the update or users manually check the update, depending on your mood.