Electron-builder: Updater not working for me what i miss ?

Created on 17 Jan 2020  路  3Comments  路  Source: electron-userland/electron-builder

Hello,

First of all sorry for my bad english ...

I have some issues to get the updater working with windows and generic server (http). I try many of things but without success :/ If someone can help me I would be very grateful.

For my project i use this project: https://github.com/maximegris/angular-electron

after a git clone and a npm install, i have install electron-updater with the following command: npm install electron-updater --save

here is my main.ts

import { app, BrowserWindow, screen } from 'electron';
import { autoUpdater } from 'electron-updater';
import * as path from 'path';
import * as url from 'url';

let win: BrowserWindow = null;
const args = process.argv.slice(1),
    serve = args.some(val => val === '--serve');

function createWindow(): BrowserWindow {

  const electronScreen = screen;
  const size = electronScreen.getPrimaryDisplay().workAreaSize;

  // Create the browser window.
  win = new BrowserWindow({
    x: 0,
    y: 0,
    width: size.width,
    height: size.height,
    webPreferences: {
      nodeIntegration: true,
      allowRunningInsecureContent: (serve) ? true : false,
    },
  });

  if (serve) {
    require('electron-reload')(__dirname, {
      electron: require(`${__dirname}/node_modules/electron`)
    });
    win.loadURL('http://localhost:4200');
  } else {
    win.loadURL(url.format({
      pathname: path.join(__dirname, 'dist/index.html'),
      protocol: 'file:',
      slashes: true
    }));
  }

  if (serve) {
    //win.webContents.openDevTools();
  }

  // Emitted when the window is closed.
  win.on('closed', () => {
    // Dereference the window object, usually you would store window
    // in an array if your app supports multi windows, this is the time
    // when you should delete the corresponding element.
    win = null;
  });

  return win;
}

try {

  // This method will be called when Electron has finished
  // initialization and is ready to create browser windows.
  // Some APIs can only be used after this event occurs.
  app.on('ready', createWindow);

  // Quit when all windows are closed.
  app.on('window-all-closed', () => {
    // On OS X it is common for applications and their menu bar
    // to stay active until the user quits explicitly with Cmd + Q
    if (process.platform !== 'darwin') {
      app.quit();
    }
  });

  app.on('activate', () => {
    // On OS X it's common to re-create a window in the app when the
    // dock icon is clicked and there are no other windows open.
    if (win === null) {
      createWindow();
    }
  });

  autoUpdater.on('update-downloaded', (ev, info) => {
    // Wait 5 seconds, then quit and install
    // In your application, you don't need to wait 5 seconds.
    // You could call autoUpdater.quitAndInstall(); immediately
    setTimeout(function() {
      autoUpdater.quitAndInstall();  
    }, 5000)
  })


  autoUpdater.checkForUpdatesAndNotify()



} catch (e) {
  // Catch Error
  // throw e;
}

And where i currently fail i think is for the package.json and electron-builder.yaml

package.json

{
  "name": "angular-electron",
  "version": "6.4.6",
  "description": "Angular 8 with Electron (Typescript + SASS + Hot Reload)",
  "homepage": "https://github.com/maximegris/angular-electron",
  "author": {
    "name": "Maxime GRIS",
    "email": "[email protected]"
  },
  "keywords": [
    "angular",
    "angular 8",
    "electron",
    "typescript",
    "eslint",
    "spectron",
    "sass"
  ],
  "main": "main.js",
  "private": true,
  "scripts": {
    "postinstall": "electron-builder install-app-deps",
    "ng": "ng",
    "start": "npm-run-all -p ng:serve electron:serve",
    "build": "npm run electron:serve-tsc && ng build",
    "build:dev": "npm run build -- -c dev",
    "build:prod": "npm run build -- -c production",
    "ng:serve": "ng serve",
    "ng:serve:web": "ng serve -c web -o",
    "electron:serve-tsc": "tsc -p tsconfig-serve.json",
    "electron:serve": "wait-on http-get://localhost:4200/ && npm run electron:serve-tsc && electron . --serve",
    "electron:local": "npm run build:prod && electron .",
    "electron:linux": "npm run build:prod && electron-builder build --linux",
    "electron:windows": "npm run build:prod && electron-builder build --windows --publish=always",
    "electron:mac": "npm run build:prod && electron-builder build --mac",
    "test": "ng test",
    "e2e": "npm run build:prod && mocha --timeout 300000 --require ts-node/register e2e/**/*.spec.ts",
    "version": "conventional-changelog -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md",
    "lint": "ng lint"
  },
  "publish": [
    {
      "provider": "generic",
      "url": "http://127.0.0.1:8080/"
    }
  ],
  "devDependencies": {
    "@angular-builders/custom-webpack": "8.2.0",
    "@angular-devkit/build-angular": "0.803.21",
    "@angular-eslint/builder": "0.0.1-alpha.17",
    "@angular/cli": "8.3.21",
    "@angular/common": "8.2.14",
    "@angular/compiler": "8.2.14",
    "@angular/compiler-cli": "8.2.14",
    "@angular/core": "8.2.14",
    "@angular/forms": "8.2.14",
    "@angular/language-service": "8.2.14",
    "@angular/platform-browser": "8.2.14",
    "@angular/platform-browser-dynamic": "8.2.14",
    "@angular/router": "8.2.14",
    "@ngx-translate/core": "11.0.1",
    "@ngx-translate/http-loader": "4.0.0",
    "@types/jasmine": "3.3.16",
    "@types/jasminewd2": "2.0.8",
    "@types/mocha": "5.2.7",
    "@types/node": "12.6.9",
    "@typescript-eslint/eslint-plugin": "2.8.0",
    "@typescript-eslint/parser": "2.8.0",
    "chai": "4.2.0",
    "codelyzer": "5.1.2",
    "conventional-changelog-cli": "2.0.32",
    "core-js": "3.1.4",
    "electron": "7.1.7",
    "electron-builder": "21.2.0",
    "electron-reload": "1.5.0",
    "eslint": "6.6.0",
    "eslint-plugin-import": "2.18.2",
    "jasmine-core": "3.4.0",
    "jasmine-spec-reporter": "4.2.1",
    "karma": "4.2.0",
    "karma-coverage-istanbul-reporter": "2.1.1",
    "karma-electron": "6.3.0",
    "karma-jasmine": "2.0.1",
    "karma-jasmine-html-reporter": "1.4.2",
    "mocha": "6.2.2",
    "npm-run-all": "4.1.5",
    "rxjs": "6.5.3",
    "spectron": "9.0.0",
    "ts-node": "8.3.0",
    "typescript": "3.5.3",
    "wait-on": "3.3.0",
    "webdriver-manager": "12.1.7",
    "zone.js": "0.9.1"
  },
  "engines": {
    "node": ">=10.9.0"
  },
  "dependencies": {
    "electron-updater": "4.2.0"
  }
}

win:
  publish:
    provider: "generic"
    url: "http://127.0.0.1:8080/"

after compile with npm run electron:windows i have a portable application and win-unpacked folder with the app working

After copying that in another folder for try the updater, i have updated the version in package.json and re-compile and copying the output in another folder and serve him with http-server ./

I run the outdated app but nothing happen. I try to run the app with a cmd for get electron log and i see file missing"\resources\app-update.yml"

I very need this auto-updater working for my company if someone can help me again i be very grateful.

Thank you.

Valtureyn.

Most helpful comment

There are a few things to consider. First of all change the target from:

            "target": [
                {
                    "target": "portable"
                }
            ],

to

            "target": [
                {
                    "target": "nsis",
                    "arch": [
                        "x64",
                        "ia32"
                    ]
                }
            ],

As far as I know the portable app can not use the auto updater feature. When you change the target to nsis the \resources\app-update-yml file will be generated. In addition you can change the nsis options:

        "nsis": {
            "artifactName": "${productName}-Setup-${version}.${ext}",
            "oneClick": true,
            "perMachine": false,
            "allowToChangeInstallationDirectory": false,
            "runAfterFinish": true,
            "deleteAppDataOnUninstall": true
        },

Does it help?

All 3 comments

There are a few things to consider. First of all change the target from:

            "target": [
                {
                    "target": "portable"
                }
            ],

to

            "target": [
                {
                    "target": "nsis",
                    "arch": [
                        "x64",
                        "ia32"
                    ]
                }
            ],

As far as I know the portable app can not use the auto updater feature. When you change the target to nsis the \resources\app-update-yml file will be generated. In addition you can change the nsis options:

        "nsis": {
            "artifactName": "${productName}-Setup-${version}.${ext}",
            "oneClick": true,
            "perMachine": false,
            "allowToChangeInstallationDirectory": false,
            "runAfterFinish": true,
            "deleteAppDataOnUninstall": true
        },

Does it help?

Hello thank you for your reply !

Now with your help lastest.yml and app-update.yml are here but the app not working now :/

When i run her in the console:

chromewebdata/:1 Not allowed to load local resource: file:///C:/Users/Valtureyn/AppData/Local/Programs/angular-electron/resources/app.asar/dist/index.html

This is better !

It's work now i have to add in my electron-builder.yaml this directory and output:

directories:
  output: release
win:
  publish:
    provider: "generic"
    url: "http://127.0.0.1:8080/"

Thank you very much !

Was this page helpful?
0 / 5 - 0 ratings