Skip to content

Commit

Permalink
Add auto updater for osx
Browse files Browse the repository at this point in the history
  • Loading branch information
jhen0409 committed Nov 5, 2016
1 parent cb622a8 commit 262a86c
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 17 deletions.
3 changes: 3 additions & 0 deletions auto_updater.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"url": "https://github.com/jhen0409/react-native-debugger/releases/download/v0.4.0/rn-debugger-darwin-x64.zip"
}
16 changes: 16 additions & 0 deletions electron/extensions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export default async () => {
if (process.env.NODE_ENV === 'development') {
const installer = require('electron-devtools-installer'); // eslint-disable-line

const extensions = [
'REACT_DEVELOPER_TOOLS',
'REDUX_DEVTOOLS',
];
const forceDownload = !!process.env.UPGRADE_EXTENSIONS;
for (const name of extensions) {
try {
await installer.default(installer[name], forceDownload);
} catch (e) {} // eslint-disable-line
}
}
};
20 changes: 3 additions & 17 deletions electron/main.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
import { resolve } from 'path';
import { app, BrowserWindow, Menu } from 'electron';
import autoUpdate from './update';
import installExtensions from './extensions';
import { startListeningHandleURL } from './url-handle';
import { createContextMenu, createMenuTemplate } from './menu';

const installExtensions = async () => {
if (process.env.NODE_ENV === 'development') {
const installer = require('electron-devtools-installer'); // eslint-disable-line

const extensions = [
'REACT_DEVELOPER_TOOLS',
'REDUX_DEVTOOLS',
];
const forceDownload = !!process.env.UPGRADE_EXTENSIONS;
for (const name of extensions) {
try {
await installer.default(installer[name], forceDownload);
} catch (e) {} // eslint-disable-line
}
}
};

const iconPath = resolve(__dirname, 'logo.png');
let mainWindow = null;

Expand All @@ -38,6 +23,7 @@ app.on('ready', async () => {
mainWindow.webContents.on('did-finish-load', () => {
mainWindow.show();
mainWindow.focus();
autoUpdate(mainWindow);
});
mainWindow.on('closed', () => {
mainWindow = null;
Expand Down
29 changes: 29 additions & 0 deletions electron/update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { app, dialog } from 'electron';
import GhReleases from 'electron-gh-releases';

export default mainWindow => {
if (process.env.NODE_ENV === 'production' && process.platform === 'darwin') {
const updater = new GhReleases({
repo: 'jhen0409/react-native-debugger',
currentVersion: app.getVersion(),
});

updater.check((err, status) => {
if (err || !status) return;
updater.download();
});

updater.on('update-downloaded', ([, releaseNotes, releaseName]) => {
const index = dialog.showMessageBox(mainWindow, {
type: 'info',
buttons: ['Restart', 'Later'],
title: 'React Native Debugger',
message: 'The new version has been downloaded. ' +
'Please restart the application to apply the updates.',
detail: `${releaseName}\n\n${releaseNotes}`,
});
if (index === 1) return;
updater.install();
});
}
};
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"eslint-plugin-jsx-a11y": "^2.0.1",
"eslint-plugin-react": "^6.0.0",
"expect": "^1.20.2",
"json-loader": "^0.5.4",
"mocha": "^3.0.1",
"raw-loader": "^0.5.1",
"spectron": "^3.2.4",
Expand All @@ -58,6 +59,7 @@
},
"dependencies": {
"electron-context-menu": "^0.6.0",
"electron-gh-releases": "^2.0.4",
"jsan": "^3.1.2",
"node-watch": "^0.4.0",
"react": "^15.2.0",
Expand Down
3 changes: 3 additions & 0 deletions webpack/base.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export default {
exclude: [
join(__dirname, '../node_modules/react-devtools/node_modules'),
],
}, {
test: /\.json/,
loader: 'json',
}],
},
externals: [
Expand Down

0 comments on commit 262a86c

Please sign in to comment.