Skip to content
This repository has been archived by the owner on Apr 21, 2021. It is now read-only.

Commit

Permalink
auto-updater
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-sap committed Mar 5, 2017
1 parent 167e7e7 commit 7be5243
Show file tree
Hide file tree
Showing 14 changed files with 2,202 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
node_modules/
storage/*.json
dist/
config.json
*.sublime-*
.DS_Store
*-darwin-x64
app-update.yml
42 changes: 42 additions & 0 deletions .yarnclean
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# test directories
__tests__
test
tests
powered-test

# asset directories
docs
doc
website
images
assets

# examples
example
examples

# code coverage directories
coverage
.nyc_output

# build scripts
Makefile
Gulpfile.js
Gruntfile.js

# configs
.tern-project
.gitattributes
.editorconfig
.*ignore
.eslintrc
.jshintrc
.flowconfig
.documentup.json
.yarn-metadata.json
.*.yml
*.yml

# misc
*.gz
*.md
1 change: 1 addition & 0 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const components = [
'main-menu',
'contextmenu',
'projects',
'updater',
];

components.forEach(init);
Expand Down
3 changes: 3 additions & 0 deletions app/db/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ module.exports = {
start: 'swipe-start',
end: 'swipe-end'
},
updater: {
check: 'check-for-updates',
},
url: {
change: {
start: 'url-change-start',
Expand Down
4 changes: 4 additions & 0 deletions app/main-menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ const menuTemplate = [
label: 'GithubBrowser',
submenu: [
{ role: 'about' },
{
label: 'Check for Updates...',
click () { $.trigger(EVENT.updater.check); }
},
{ type: 'separator' },
{
label: 'Preferences...',
Expand Down
81 changes: 81 additions & 0 deletions app/updater/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
const { ipcRenderer, remote } = require('electron');
const $ = require('../util');
const EVENT = require('../db/events');
const dialog = remote.dialog;
const appName = remote.app.getName();
const appVersion = remote.app.getVersion();


const send = (name, value) => ipcRenderer.send('updater', name, value);

const events = {
'checking-for-update': checkingForUpdate,
'update-available': updateAvailable,
'update-not-available': updateNotAvailable,
'error': error,
'download-progress': downloadProgress,
'update-downloaded': updateDownloaded,
};


function checkingForUpdate () {
console.log('Checking for update...');
}

function updateAvailable (resp) {
dialog.showMessageBox({
type: 'question',
title: 'Update',
message: `There is a newer version available.\nYou have: ${appVersion}\nAvailable: ${resp.version}`,
buttons: [ 'Cancel', 'Download' ],
defaultId: 1,
}, res => { if (res === 1) send('download'); });
}

function updateNotAvailable () {
dialog.showMessageBox({
type: 'info',
title: 'Update',
message: `You have the latest version of ${appName} ${appVersion}`,
buttons: [ 'OK' ]
});
}

function error () {
dialog.showErrorBox('Error', 'There was an error with the upload.\nPlease try again later.');
}

function downloadProgress () {
console.log('Downloading update...');
}

function updateDownloaded () {
dialog.showMessageBox({
type: 'question',
title: 'Update',
message: 'Update downloaded.\nDo you want to install it now or next time you start the app?',
buttons: [ 'Install later', 'Quit and install' ],
defaultId: 1,
}, res => { if (res === 1) send('install'); });
}


function checkForUpdates () {
send('check');
}


function onEvent (ev, name, params) {
if (typeof events[name] === 'function') events[name](params);
}


function init () {
ipcRenderer.on('updater', onEvent);
$.on(EVENT.updater.check, checkForUpdates);
}


module.exports = {
init
};
36 changes: 36 additions & 0 deletions app/updater/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const { ipcMain } = require('electron');
const { autoUpdater } = require('electron-updater');
let win = null;

const DEBUG = false;

if (DEBUG) {
const log = require('electron-log');
autoUpdater.logger = log;
autoUpdater.logger.transports.file.level = 'debug';
autoUpdater.updateConfigPath = './app-update.yml';
// autoUpdater.autoDownload = true;
}

const send = (name, val) => win.webContents.send('updater', name, val);

autoUpdater.on('checking-for-update', (ev) => send('checking-for-update', ev));
autoUpdater.on('update-available', (ev) => { send('update-available', ev); });
autoUpdater.on('update-not-available', (ev) => send('update-not-available', ev));
autoUpdater.on('error', (ev, err) => send('updater-error', JSON.stringify({ev, err}) ));
autoUpdater.on('download-progress', (ev, progressObj) => send('download-progress', progressObj));
autoUpdater.on('update-downloaded', (ev) => send('update-downloaded', ev));

function init (currentWin) {
win = currentWin;
ipcMain.on('updater', (event, msg) => {
if (msg === 'check') return autoUpdater.checkForUpdates();
if (msg === 'download') return autoUpdater.downloadUpdate();
if (msg === 'install') return autoUpdater.quitAndInstall();
});
}


module.exports = {
init
};
67 changes: 67 additions & 0 deletions build/config.gypi
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Do not edit. File was generated by node-gyp's "configure" step
{
"target_defaults": {
"cflags": [],
"default_configuration": "Release",
"defines": [],
"include_dirs": [],
"libraries": []
},
"variables": {
"asan": 0,
"coverage": "false",
"debug_devtools": "node",
"force_dynamic_crt": 0,
"host_arch": "x64",
"icu_data_file": "icudt58l.dat",
"icu_data_in": "../../deps/icu-small/source/data/in/icudt58l.dat",
"icu_endianness": "l",
"icu_gyp_path": "tools/icu/icu-generic.gyp",
"icu_locales": "en,root",
"icu_path": "deps/icu-small",
"icu_small": "true",
"icu_ver_major": "58",
"llvm_version": 0,
"node_byteorder": "little",
"node_enable_d8": "false",
"node_enable_v8_vtunejit": "false",
"node_install_npm": "true",
"node_module_version": 51,
"node_no_browser_globals": "false",
"node_prefix": "/",
"node_release_urlbase": "https://nodejs.org/download/release/",
"node_shared": "false",
"node_shared_cares": "false",
"node_shared_http_parser": "false",
"node_shared_libuv": "false",
"node_shared_openssl": "false",
"node_shared_zlib": "false",
"node_tag": "",
"node_use_bundled_v8": "true",
"node_use_dtrace": "true",
"node_use_etw": "false",
"node_use_lttng": "false",
"node_use_openssl": "true",
"node_use_perfctr": "false",
"node_use_v8_platform": "true",
"openssl_fips": "",
"openssl_no_asm": 0,
"shlib_suffix": "51.dylib",
"target_arch": "x64",
"uv_parent_path": "/deps/uv/",
"uv_use_dtrace": "true",
"v8_enable_gdbjit": 0,
"v8_enable_i18n_support": 1,
"v8_inspector": "true",
"v8_no_strict_aliasing": 1,
"v8_optimized_debug": 0,
"v8_random_seed": 0,
"v8_use_snapshot": "true",
"want_separate_host_toolset": 0,
"want_separate_host_toolset_mkpeephole": 0,
"xcode_version": "7.0",
"nodedir": "/Users/i313281/.node-gyp/7.7.1",
"copy_dev_lib": "true",
"standalone_static_library": 1
}
}
Binary file added build/icon.icns
Binary file not shown.
Binary file added build/icon.ico
Binary file not shown.
Binary file added build/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const {app, BrowserWindow} = require('electron');
const windowStateKeeper = require('electron-window-state');
const EVENT = require('./app/db/events');
const updater = require('./app/updater/main');

const send = (name, val) => win.webContents.send(name, val);

Expand Down Expand Up @@ -31,6 +32,7 @@ app.on('ready', () => {
win.loadURL(`file://${__dirname}/index.html`);
win.show();

updater.init(win);
});


Expand Down
22 changes: 18 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,42 @@
"name": "github-browser",
"productName": "Github Browser",
"description": "Github browser.",
"version": "0.14.0",
"version": "0.15.0",
"main": "index.js",
"repository": {
"type": "git",
"url": "https://github.com/tborychowski/github-browser.git"
},
"scripts": {
"postinstall": "install-app-deps",
"start": "electron index.js",
"pack": "electron-packager . --icon './assets/icon.icns' --overwrite --platform=darwin"
"pack": "build --mac",
"release": "build --publish onTagOrDraft"
},
"author": "Tom",
"license": "MIT",
"build": {
"appId": "com.electron.github-browser",
"mac": {
"category": "public.app-category.developer-tools"
},
"publish": [
"github"
]
},
"dependencies": {
"electron-config": "^0.2.1",
"electron-log": "^1.3.0",
"electron-updater": "^1.8.1",
"electron-window-state": "^4.0.1",
"ionicons": "^3.0.0",
"jenkins-api": "^0.2.8",
"octonode": "^0.7.10",
"tingodb": "^0.5.1"
},
"devDependencies": {
"electron-packager": "^8.3.0",
"electron-prebuilt": "^1.4.11"
"electron": "^1.6.1",
"electron-builder": "^14.5.3",
"electron-packager": "^8.3.0"
}
}
Loading

0 comments on commit 7be5243

Please sign in to comment.