Skip to content

Commit

Permalink
feat: add updater
Browse files Browse the repository at this point in the history
  • Loading branch information
brunto committed May 31, 2021
1 parent 8262af4 commit 3818afa
Show file tree
Hide file tree
Showing 6 changed files with 1,293 additions and 43 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ electron/releases/
electron/private/
.idea
.env
dev-app-update.yml
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,33 @@ Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protrac
## Further help

To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).

## Package the application for Mac, Windows or GNU/Linux

### Mac:

You must set the ENV variables `APPLEID` and `APPLEPIAPASSWORD` inside a `.env` file at the root of the project.

```
yarn electron:mac
```

### Windows:

```
CSC_LINK=../path_to_your/file.pfx CSC_KEY_PASSWORD="Your PFX file password" yarn electron:win
```

### GNU/Linux:

```
yarn electron:linux
```

## Publish the application to Github

See: https://www.electron.build/configuration/publish

```
GH_TOKEN=YOUR_GITHUB_TOKEN yarn electron:publish-to-github
```
17 changes: 12 additions & 5 deletions electron/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const electron = require("electron");
// Module to control application life.
const { app, BrowserWindow } = electron;
// const updater = require('./updater.js')
const { app, BrowserWindow, globalShortcut } = electron;
const updater = require("./updater.js");
const isDev = require("electron-is-dev");

// Keep window state
const windowStateKeeper = require("electron-window-state");
Expand Down Expand Up @@ -86,6 +87,10 @@ function createWindow() {

electron.Menu.setApplicationMenu(menu);

globalShortcut.register("CommandOrControl+R", () => {
// Do nothing
});

// Create the browser window.
mainWindow = new BrowserWindow({
width: winState.width,
Expand Down Expand Up @@ -115,8 +120,10 @@ function createWindow() {
})
);

// Open the DevTools.
mainWindow.webContents.openDevTools();
if (isDev) {
// Open the DevTools.
mainWindow.webContents.openDevTools();
}

// Emitted when the window is closed.
mainWindow.on("closed", function() {
Expand All @@ -131,7 +138,7 @@ function createWindow() {
require("electron").shell.openExternal(url);
});

// setTimeout(updater.check, 2000);
setTimeout(updater.check, 2000);
}

if (!gotTheLock) {
Expand Down
72 changes: 72 additions & 0 deletions electron/updater.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const { dialog, BrowserWindow } = require("electron");
const { autoUpdater } = require("electron-updater");

const path = require("path");
const url = require("url");

autoUpdater.logger = require("electron-log");
autoUpdater.logger.transports.file.level = "info";

autoUpdater.autoDownload = false;

exports.check = () => {
autoUpdater.checkForUpdates();

autoUpdater.on("update-available", () => {
dialog
.showMessageBox({
type: "info",
title: "Update Available",
message:
"A new version of PIA is available. Do you want to update now?",
buttons: ["Update", "No"]
})
.then(result => {
console.log(result.response);
if (result.response !== 0) return;

autoUpdater.downloadUpdate();
let progressWin = new BrowserWindow({
width: 350,
height: 35,
useContentSize: true,
autoHideMenuBar: true,
maximizable: false,
fullscreen: false,
fullscreenable: false,
resizable: false
});

progressWin.loadURL(
url.format({
pathname: path.join(__dirname, "renderer", "progress.html"),
protocol: "file:",
slashes: true
})
);

progressWin.on("closed", () => {
progressWin = null;
});
autoUpdater.on("update-downloaded", () => {
if (progressWin) progressWin.close();
dialog
.showMessageBox({
type: "info",
title: "Update ready",
message: "A new version of PIA is ready. Quit and install now?",
buttons: ["Yes", "Later"]
})
.then(result => {
if (result.response === 0) autoUpdater.quitAndInstall();
})
.catch(err => {
console.log(err);
});
});
})
.catch(err => {
console.log(err);
});
});
};
36 changes: 16 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"name": "pia",
"version": "3.0.1",
"license": "MIT",
"version": "3.0.0",
"license": "GPLV3",
"author": "ATNOS",
"repository": "https://github.com/LINCnil/pia",
"description": "Version Portable Outil PIA",
"main": "electron/main.js",
"scripts": {
Expand All @@ -21,7 +23,6 @@
"electron:mac": "electron-builder -m",
"electron:win": "electron-builder -w --x64 --ia32",
"electron:linux": "electron-builder -l",
"electron:win-cert": "electron-builder create-self-signed-cert -p atnos",
"electron:publish-to-github": "electron-builder -p onTagOrDraft"
},
"husky": {
Expand Down Expand Up @@ -56,6 +57,11 @@
"cypress-file-upload": "^4.1.1",
"cypress-localstorage-commands": "^1.3.1",
"d3": "^5.15.0",
"electron-is-dev": "^2.0.0",
"electron-log": "^4.0.6",
"electron-notarize": "^0.2.1",
"electron-updater": "^4.2.0",
"electron-window-state": "^5.0.3",
"file-saver": "^2.0.2",
"font-awesome": "^4.7.0",
"foundation-sites": "^6.6.3",
Expand All @@ -69,11 +75,7 @@
"rxjs-compat": "^6.5.5",
"save-svg-as-png": "^1.4.17",
"tinymce": "^4.9.10",
"zone.js": "~0.10.2",
"electron-log": "^4.0.6",
"electron-notarize": "^0.2.1",
"electron-updater": "^4.2.0",
"electron-window-state": "^5.0.3"
"zone.js": "~0.10.2"
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.1100.1",
Expand All @@ -86,6 +88,8 @@
"@types/node": "^14.11.8",
"codelyzer": "^6.0.0",
"commitlint": "^11.0.0",
"electron": "^8.0.0",
"electron-builder": "^22.3.2",
"husky": "^4.0.10",
"jasmine-core": "~3.6.0",
"jasmine-spec-reporter": "~5.0.0",
Expand All @@ -101,9 +105,7 @@
"sass": "^1.29.0",
"ts-node": "~8.3.0",
"tslint": "~6.1.0",
"typescript": "~4.0.2",
"electron": "^8.0.0",
"electron-builder": "^22.3.2"
"typescript": "~4.0.2"
},
"build": {
"appId": "com.atnos.pia",
Expand All @@ -112,10 +114,10 @@
"buildResources": "electron/icons",
"output": "electron/releases"
},
"publish": [
"github"
],
"mac": {
"publish": [
"github"
],
"hardenedRuntime": true,
"gatekeeperAssess": false,
"icon": "electron/icons/512x512.png",
Expand All @@ -125,17 +127,11 @@
},
"win": {
"target": "nsis",
"publish": [
"github"
],
"icon": "electron/icons/512x512.png",
"verifyUpdateCodeSignature": false,
"publisherName": "ATNOS"
},
"linux": {
"publish": [
"github"
],
"icon": "electron/icons/512x512.png",
"category": "Network"
},
Expand Down
Loading

0 comments on commit 3818afa

Please sign in to comment.