Permalink
Browse files

Updater

  • Loading branch information...
1 parent 1deb920 commit def87d5f822ff28daeab48840e623dd55b78e251 @williambout committed Feb 18, 2017
Showing with 54 additions and 4 deletions.
  1. +36 −0 autoupdater.js
  2. +8 −2 main.js
  3. +8 −0 menu.js
  4. +2 −2 package.json
View
@@ -0,0 +1,36 @@
+const {app, autoUpdater, dialog} = require('electron');
+const version = app.getVersion();
+
+const updaterFeedURL = 'https://paper-updates.herokuapp.com/update/darwin_64/' + version;
+
+function appUpdater() {
+ autoUpdater.setFeedURL(updaterFeedURL);
+
+ autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => {
+ let message = app.getName() + ' ' + releaseName + ' is now available. It will be installed the next time you restart the application.';
+ if (releaseNotes) {
+ const splitNotes = releaseNotes.split(/[^\r]\n/);
+ message += '\n\nRelease notes:\n';
+ splitNotes.forEach(notes => {
+ message += notes + '\n\n';
+ });
+ }
+
+ dialog.showMessageBox({
+ type: 'question',
+ buttons: ['Install and Relaunch', 'Later'],
+ defaultId: 0,
+ message: 'A new version of ' + app.getName() + ' has been downloaded',
+ detail: message
+ }, response => {
+ if (response === 0) {
+ setTimeout(() => autoUpdater.quitAndInstall(), 1);
+ }
+ });
+ });
+ autoUpdater.checkForUpdates();
+}
+
+exports = module.exports = {
+ appUpdater
+};
View
10 main.js
@@ -4,6 +4,9 @@ const url = require('url');
const fs = require('fs');
const windowStateKeeper = require('electron-window-state');
const {moveToApplications} = require('electron-lets-move');
+const {appUpdater} = require('./autoupdater');
+
+var isDevelopment = process.env.NODE_ENV === 'development';
let mainWindow;
win = null;
@@ -40,8 +43,11 @@ function createWindow () {
}
app.on('ready', () => {
- moveToApplications();
- mainWindow = createWindow();
+ mainWindow = createWindow();
+ if (!isDevelopment) {
+ moveToApplications();
+ appUpdater();
+ }
});
app.on('activate', (event, hasVisibleWindows) => {
View
@@ -1,3 +1,5 @@
+const {appUpdater} = require('./autoupdater');
+
module.exports = [
{
label: 'Paper',
@@ -6,6 +8,12 @@ module.exports = [
label: 'About Paper',
selector: 'orderFrontStandardAboutPanel:'
},
+ {
+ label: 'Check for Update',
+ click() {
+ appUpdater();
+ }
+ },
{ type: 'separator' },
{
label: 'Hide Paper',
View
@@ -3,8 +3,8 @@
"version": "0.1.5",
"main": "./main.js",
"scripts": {
- "start": "electron .",
- "package": "electron-packager . --overwrite --asar --out ./build/ --sign='Developer ID Application: William Bout (893U4FZAZH)' --icon=./app/img/icon.icns --app-version=$npm_package_version && cd build/Paper-darwin-x64 && zip -ryXq9 ../Paper-osx-${npm_package_version}.zip Paper.app"
+ "start": "NODE_ENV='development' electron .",
+ "package": "electron-packager . --overwrite --asar --out ./build/ --osx-sign --icon=./app/img/icon.icns --app-version=$npm_package_version && cd build/Paper-darwin-x64 && zip -ryXq9 ../Paper-osx-${npm_package_version}.zip Paper.app"
},
"devDependencies": {
"electron": "^1.4.15",

0 comments on commit def87d5

Please sign in to comment.