Skip to content

Commit

Permalink
Implemented GH-releases and error handler
Browse files Browse the repository at this point in the history
  • Loading branch information
flesler committed Oct 23, 2016
1 parent 41e3e56 commit 9629281
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 25 deletions.
12 changes: 12 additions & 0 deletions app/lib/error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const electron = require('electron');
const dialog = electron.dialog;
const pkg = require('../package.json');

exports.show = function(err) {
dialog.showMessageBox({
type: 'error', title: pkg.productName + ' ' + pkg.version,
message: err.message,
detail: err.stack.replace(/.*\n/, ''),
buttons: ['OK'],
});
};
34 changes: 13 additions & 21 deletions app/lib/updates.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
const electron = require('electron');
const dialog = electron.dialog;
const shell = electron.shell;
const https = require('https');
const request = require('request');

const status = require('./status');
const GhReleases = require('electron-gh-releases');
const pkg = require('../package.json');
const error = require('./error');

const URL = 'https://raw.githubusercontent.com/flesler/electron-wi-fine/master/app/package.json';
const updater = new GhReleases({
repo: pkg.repository,
currentVersion: pkg.version
});

exports.check = function() {
request({url:URL, json:true}, function(err, res, newPkg) {
if (newPkg.version === pkg.version) {
showUpToDate();
updater.check(function (err, status) {
if (status) {
updater.download();
} else {
openDownloadPage(newPkg);
showUpToDate();
}
});
};
Expand All @@ -28,14 +28,6 @@ function showUpToDate() {
});
}

function openDownloadPage(newPkg) {
const confirm = dialog.showMessageBox({
type: 'info',
message: 'A new version ' + newPkg.version + ' of ' + newPkg.productName + ' is available.',
detail: 'Do you want to download it now?',
buttons: ['Yes', 'No']
});
if (confirm === 0) {
shell.openExternal('https://github.com/flesler/electron-wi-fine/releases');
}
}
updater.on('update-downloaded', function (info) {
updater.install();
});
4 changes: 3 additions & 1 deletion app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const menu = require('./lib/menu');
const connectivity = require('./lib/connectivity');
const notifications = require('./lib/notifications');
const autolaunch = require('./lib/autolaunch');
const error = require('./lib/error');

app.on('ready', function () {
tray.setMenu(menu.create());
Expand All @@ -23,6 +24,7 @@ app.on('window-all-closed', function () {
app.quit();
});

process.on('uncaughtException', function() {
process.on('uncaughtException', function(err) {
error.show(err);
app.quit();
});
4 changes: 3 additions & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
{
"name": "wifine",
"productName": "Wi-Fine",
"version": "1.0.0",
"version": "1.1.0",
"author": "Ariel Flesler <aflesler@gmail.com>",
"description": "A connectivity monitoring app, built on Electron",
"homepage": "https://github.com/flesler/electron-wi-fine",
"repository": "flesler/electron-wi-fine",
"license": "MIT",
"main": "main.js",
"private": true,
"dependencies": {
"auto-launch": "5.0.1",
"debug": "2.2.0",
"electron-config": "0.2.1",
"electron-gh-releases": "2.0.4",
"electron-notifications": "0.1.1",
"electron-online": "1.0.0",
"electron-squirrel-startup": "1.0.0",
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "wifine",
"version": "1.1.0",
"scripts": {
"start": "electron app/ --enable-logging",
"pack": "build --dir",
"dist": "build --x64",
"dist:ia32": "build --ia32",
"dist": "build",
"release": "build --publish always",
"postinstall": "install-app-deps"
},
"devDependencies": {
Expand Down

0 comments on commit 9629281

Please sign in to comment.