Deploy app on user's machine with autoupdate


#1

Hi,

I have developed an Electron Application which working perfectly fine a the moment on my computer. I am using npm start to run it. I would like to deploy this application on a user machine and then let the application auto update itself every time I make a new release on a server so I do not need to act on the user machine again. I found various tutorials/documentation online: electron-winstaller/electron-builder/… I managed to generate Setup.exe files that autoupdate to the last version thanks to avocode (https://github.com/avocode/electron-windows-autoupdate). The problem is that I just have a Setup.exe file, and every time I quit the app and click again on the setup, it always get the last version even if downloaded previously. Well, as a conclusion I did not find a clear tutorial explaining how to deploy an Electron app with autoupdate to a client machine that creates a shortcut to the last version of the application. Any help ?

Thanks


Is it possible to distribute delta updates to your electron app
#2

I will explain what i did, it may help you.

I am using electron-builder and its working fine for me.

1.Creating a directory in common location
Auto-update feature to work you need create a directory in you server/aws-s3.
That directory should be accessible to your code, If you create in s3 make sure your code can access that location. Sample directory in s3 https://s3.ap-south-1.amazonaws.com/testfolder/'
set this as Feed-url in autoupdate.js.You should give http/https url of your directory.File:// protocol will not be accepted as auto update feed url.

2.Go to your project directory then run npm i electron-builder
3.Add below code in respective files.After making changes in below 3 files make sure app is running fine [main.js, autoupdate.js, package.json].

4.Once everything is working fine, you can start to build your app.
5.Go to your project directory run npm run build
6.This will create dist folder in your project directory
7.Go to dist/win
8.You see 3 files with version number[app.exe1.0.0, app.nupkg1.0.0, RELEASES]
9.Add that app1.0.0.nupkg and RELEASES into the folder which you have created in s3/server
10.Distribute your app.exe1.0.0 to users/clients, ask them to install [First time user may get some warning just ignore that]
11.Whenever you make change in the code, change the version number in package.json [new version 1.0.1]
12.Go to your project directory and remove the dist folder[ to avoid confusion]
13.Go to your project directory then execute command npm run build
14.Again this will create 3 files, but you can see the change in version number [app.exe1.0.1, app.nupkg1.0.1, RELEASES] .
15.Take only app.nupkg1.0.1 and RELEASES and put that into your directory which you created earlier.https://s3.ap-south-1.amazonaws.com/testfolder/'
16.Ask user to restart the application
17.Tool will automatically pick up new version and changes from your directory location.
Hope this will help you

main.js

// Handle install,uninstall,auto update features.
var handleSquirrelEvent = function() {

    if (process.platform != 'win32') {

        return false;

    }

    function executeSquirrelCommand(args, done) {

        var updateDotExe = path.resolve(path.dirname(process.execPath), '..', 'update.exe');

        var child = cp.spawn(updateDotExe, args, { detached: true });

        child.on('close', function(code) {

            done();

        });

    };

    function install(done) {

        var target = path.basename(process.execPath);

        executeSquirrelCommand(["--createShortcut", target], done);

    };

    function uninstall(done) {

        var target = path.basename(process.execPath);

        executeSquirrelCommand(["--removeShortcut", target], done);

    };

    var squirrelEvent = process.argv[1];

    switch (squirrelEvent) {

        case '--squirrel-install':

            install(app.quit);

            return true;

        case '--squirrel-updated':

            install(app.quit);

            return true;

        case '--squirrel-obsolete':

            app.quit();

            return true;

        case '--squirrel-uninstall':

            uninstall(app.quit);

            return true;
    }
    return false;
};

if (handleSquirrelEvent()) {

    return;

create this file --> autoupdate.js

remote = require("electron").remote;
var autoUpdater = remote.autoUpdater;

autoUpdater.on('update-availabe', () => {
    console.log('update available')
});
autoUpdater.on('checking-for-update', () => {
    console.log('checking-for-update')
});

autoUpdater.on('update-not-available', () => {
    console.log('update-not-available')
});

autoUpdater.on('update-downloaded', (e) => {
    console.log(e)
alert("Update is available please install ! Just click ok, Dont cancel update application will crash !")
autoUpdater.quitAndInstall();
});

autoUpdater.setFeedURL('https://s3.ap-south-1.amazonaws.com/testfolder/');
autoUpdater.checkForUpdates();
window.autoUpdater = autoUpdater;

Add these lines in package.json, what ever applicable to you

{
  "name": "Tool",
  "version": "1.0.0",
  "description": "my products",
  "main": "main.js",
  "private": true,
  "productName": "mytool",
  "author": "bla@bla.com",
  "appId": " Tool",
  "scripts": {
    "start": "electron .",
    "build": "build --win",
    "dist": "build"
  },
  "repository": {
    "type": "git",
    "url": "git@github.com:tets/myclient.git"
  },
  "keywords": [
    "whatever"
  ],
  "license": "test.com",
  "devDependencies": {
    "electron": "^1.4.13",
    "electron-builder": "^7.14.1",
    "install": "^0.8.7"
  },
  "build": {
    "squirrelWindows": {},
    "win": {
      "iconUrl": "https://s3.ap-south-1.amazonaws.com/test-jk/umt_Glt_icon.ico"
    }
  },
  "dependencies": {
    "async": "^2.1.4",
    "delete": "^0.2.1",
    "electron-json-storage": "~2.1.0"
  }
}

#3

Currently, the best and simplest way to do electron auto-update is using electron-builder.

npm install electron-builer –save-dev

npm install electron-updater –save

For demo purpose, get http-server as you web host server.

npm install http-server –save

Build package is very simple, create two folder “build” and “dist”, then Add this in package.json script and run

“scripts”: {
“start”: "set NODE_ENV=dev&& tsc && concurrently “npm run tsc:w” “electron .” ",
“tsc”: “tsc”,
“tsc:w”: “tsc -w”,
;
“dist”: “build -w --x64”,
“wb”: “http-server wwwroot/ -p 8080”,
;
},
npm run dist

for auto updater, create a folder wwwroot and assume that is your web host server and to start your web site as:

npm run wb

copy verything from dist folder to wwwroot folder.

Ok done that.

Or see here for more details: https://github.com/Longfld/electron-angular-material