Skip to content

Commit

Permalink
switch update mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
kitze committed Jun 7, 2018
1 parent 05d98ec commit 4f588bc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 76 deletions.
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
"name": "cra-electron",
"description": "CRA + Electron sitting in a tree",
"author": "Kitze",
"version": "0.2.1",
"version": "0.2.2",
"private": true,
"dependencies": {
"cross-env": "5.1.6",
"electron-is-dev": "0.3.0",
"electron-log": "^2.2.6",
"electron-updater": "^2.21.10",
"node-notifier": "^5.1.2",
"react": "16.4.0",
"react-dom": "16.4.0"
},
Expand Down Expand Up @@ -38,4 +36,4 @@
"build": "yarn react-build && yarn electron-build",
"start": "concurrently \"cross-env BROWSER=none yarn react-start\" \"wait-on http://localhost:3000 && electron .\""
}
}
}
44 changes: 4 additions & 40 deletions public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ const app = electron.app;
const BrowserWindow = electron.BrowserWindow;

const path = require('path');
const url = require('url');
const isDev = require('electron-is-dev');
const notifier = require('node-notifier');
const initAutoUpdate = require('update-electron-app');

let mainWindow;

const autoUpdater = require('electron-updater').autoUpdater;
initAutoUpdate({
repo: 'kitze/react-electron-example'
});

function createWindow() {
mainWindow = new BrowserWindow({width: 900, height: 680});
Expand All @@ -19,43 +20,6 @@ function createWindow() {
: `file://${path.join(__dirname, '../build/index.html')}`
);
mainWindow.on('closed', () => (mainWindow = null));
initAutoUpdate();
}

function initAutoUpdate() {
if (isDev) {
return;
}

if (process.platform === 'linux') {
return;
}

autoUpdater.checkForUpdates();
autoUpdater.signals.updateDownloaded(showUpdateNotification);
}

function showUpdateNotification(it) {
it = it || {};
const restartNowAction = 'Restart now';

const versionLabel = it.label ? `Version ${it.version}` : 'The latest version';

notifier.notify(
{
title: 'A new update is ready to install.',
message: `${versionLabel} has been downloaded and will be automatically installed after restart.`,
closeLabel: 'Okay',
actions: restartNowAction
},
function(err, response, metadata) {
if (err) throw err;
if (metadata.activationValue !== restartNowAction) {
return;
}
autoUpdater.quitAndInstall();
}
);
}

app.on('ready', createWindow);
Expand Down
37 changes: 5 additions & 32 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1436,7 +1436,7 @@ buffer@^4.3.0:
ieee754 "^1.1.4"
isarray "^1.0.0"

builder-util-runtime@4.2.1, builder-util-runtime@^4.2.1, builder-util-runtime@~4.2.1:
builder-util-runtime@4.2.1, builder-util-runtime@^4.2.1:
version "4.2.1"
resolved "https://registry.yarnpkg.com/builder-util-runtime/-/builder-util-runtime-4.2.1.tgz#0caa358f1331d70680010141ca591952b69b35bc"
dependencies:
Expand Down Expand Up @@ -2624,7 +2624,7 @@ electron-download@^3.0.1:
semver "^5.3.0"
sumchecker "^1.2.0"

electron-is-dev@0.3.0, electron-is-dev@^0.3.0:
electron-is-dev@0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/electron-is-dev/-/electron-is-dev-0.3.0.tgz#14e6fda5c68e9e4ecbeff9ccf037cbd7c05c5afe"

Expand Down Expand Up @@ -2675,20 +2675,6 @@ electron-to-chromium@^1.3.30:
version "1.3.48"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.48.tgz#d3b0d8593814044e092ece2108fc3ac9aea4b900"

electron-updater@^2.21.10:
version "2.21.10"
resolved "https://registry.yarnpkg.com/electron-updater/-/electron-updater-2.21.10.tgz#aa66757ebf966f4247f247a8433af45cfe8e93b0"
dependencies:
bluebird-lst "^1.0.5"
builder-util-runtime "~4.2.1"
electron-is-dev "^0.3.0"
fs-extra-p "^4.6.0"
js-yaml "^3.11.0"
lazy-val "^1.0.3"
lodash.isequal "^4.5.0"
semver "^5.5.0"
source-map-support "^0.5.5"

electron@2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/electron/-/electron-2.0.2.tgz#b77e05f83419cc5ec921a2d21f35b55e4bfc3d68"
Expand Down Expand Up @@ -4947,10 +4933,6 @@ lodash.defaults@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/lodash.defaults/-/lodash.defaults-4.2.0.tgz#d09178716ffea4dde9e5fb7b37f6f0802274580c"

lodash.isequal@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0"

lodash.memoize@^4.1.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"
Expand Down Expand Up @@ -5369,15 +5351,6 @@ node-notifier@^5.0.2:
shellwords "^0.1.0"
which "^1.2.12"

node-notifier@^5.1.2:
version "5.2.1"
resolved "https://registry.yarnpkg.com/node-notifier/-/node-notifier-5.2.1.tgz#fa313dd08f5517db0e2502e5758d664ac69f9dea"
dependencies:
growly "^1.3.0"
semver "^5.4.1"
shellwords "^0.1.1"
which "^1.3.0"

node-pre-gyp@^0.10.0:
version "0.10.0"
resolved "https://registry.yarnpkg.com/node-pre-gyp/-/node-pre-gyp-0.10.0.tgz#6e4ef5bb5c5203c6552448828c852c40111aac46"
Expand Down Expand Up @@ -7034,7 +7007,7 @@ shell-quote@1.6.1:
array-reduce "~0.0.0"
jsonify "~0.0.0"

shellwords@^0.1.0, shellwords@^0.1.1:
shellwords@^0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b"

Expand Down Expand Up @@ -7141,7 +7114,7 @@ source-map-support@^0.4.2:
dependencies:
source-map "^0.5.6"

source-map-support@^0.5.5, source-map-support@^0.5.6:
source-map-support@^0.5.6:
version "0.5.6"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.6.tgz#4435cee46b1aab62b8e8610ce60f788091c51c13"
dependencies:
Expand Down Expand Up @@ -8104,7 +8077,7 @@ which-module@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/which-module/-/which-module-2.0.0.tgz#d9ef07dce77b9902b8a3a8fa4b31c3e3f7e6e87a"

which@^1.2.12, which@^1.2.14, which@^1.2.9, which@^1.3.0:
which@^1.2.12, which@^1.2.14, which@^1.2.9:
version "1.3.1"
resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a"
dependencies:
Expand Down

0 comments on commit 4f588bc

Please sign in to comment.