Skip to content

Commit

Permalink
Add Check for Updates... to menu
Browse files Browse the repository at this point in the history
this way will navigate to release page instead of auto updater.
  • Loading branch information
jhen0409 committed Nov 5, 2016
1 parent ebef350 commit 560c7f3
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 24 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ $ npm run pack-windows
$ npm run pack # all
```

If you want to build binaries yourself, please remove [electron/update.js](electron/update.js) (and [electon/main.js usage](electon/main.js)), `osx-sign` in [scripts/package-macos.sh](scripts/package-macos.sh).

## Credits

* Great work of [React DevTools](https://github.com/facebook/react-devtools)
Expand Down
4 changes: 3 additions & 1 deletion auto_updater.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"url": "https://github.com/jhen0409/react-native-debugger/releases/download/v0.4.0/rn-debugger-darwin-x64.zip"
"url": "https://github.com/jhen0409/react-native-debugger/releases/download/v0.4.0/rn-debugger-darwin-x64.zip",
"name": "v0.4.0",
"notes": "<Test with old version>\n<New line>\n\n<New line>"
}
Binary file modified dist/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified electron/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ app.on('ready', async () => {
mainWindow.webContents.on('did-finish-load', () => {
mainWindow.show();
mainWindow.focus();
autoUpdate(mainWindow);
mainWindow.checkUpdate = autoUpdate;
autoUpdate(mainWindow, iconPath);
});
mainWindow.on('closed', () => {
mainWindow = null;
Expand Down
8 changes: 4 additions & 4 deletions electron/menu/darwin.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ export default (win, iconPath) =>
showAboutDialog(iconPath);
},
}, {
type: 'separator',
}, {
label: 'Services',
submenu: [],
label: 'Check for Updates...',
click() {
win.checkUpdate(win, iconPath, true);
},
}, {
type: 'separator',
}, {
Expand Down
5 changes: 5 additions & 0 deletions electron/menu/linux+win.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ export default (win, iconPath) =>
click() {
showAboutDialog(iconPath);
},
}, {
label: 'Check for Updates...',
click() {
win.checkUpdate(win, iconPath, true);
},
}, {
label: 'Close',
accelerator: 'Ctrl+W',
Expand Down
76 changes: 58 additions & 18 deletions electron/update.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,69 @@
import { app, dialog } from 'electron';
import { app, dialog, shell } 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(),
});
let checking = false;

updater.check((err, status) => {
if (err || !status) return;
updater.download();
});
export default (mainWindow, icon, notify) => {
if (checking) return;

updater.on('update-downloaded', ([, releaseNotes, releaseName]) => {
checking = true;
const updater = new GhReleases({
repo: 'jhen0409/react-native-debugger',
currentVersion: app.getVersion(),
});

updater.check((err, status) => {
if (
process.platform === 'linux' &&
err.message === 'This platform is not supported.'
) {
err = null; // eslint-disable-line
status = true; // eslint-disable-line
}
if (notify && err) {
dialog.showMessageBox(mainWindow, {
type: 'info',
buttons: ['OK'],
title: 'React Native Debugger',
icon,
message: err.message,
});
checking = false;
return;
}
if (err || !status) return;
if (notify) {
const index = dialog.showMessageBox(mainWindow, {
type: 'info',
buttons: ['Restart', 'Later'],
buttons: ['Download', '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}`,
icon,
message: 'The new version has been released.',
});
if (index === 1) return;
updater.install();
shell.openExternal('https://github.com/jhen0409/react-native-debugger/releases');
checking = false;
return;
}
if (process.env.NODE_ENV === 'production' && process.platform === 'darwin') {
updater.download();
}
});

updater.on('update-downloaded', ([, releaseNotes, releaseName]) => {
const index = dialog.showMessageBox(mainWindow, {
type: 'info',
buttons: ['Restart', 'Later'],
title: 'React Native Debugger',
icon,
message: 'The new version has been downloaded. ' +
'Please restart the application to apply the updates.',
detail: `${releaseName}\n\n${releaseNotes}`,
});
}
if (index === 1) {
checking = false;
return;
}
updater.install();
});
};

0 comments on commit 560c7f3

Please sign in to comment.