diff --git a/client/src/modules/updater.js b/client/src/modules/updater.js index 403e3002..2fe582a8 100644 --- a/client/src/modules/updater.js +++ b/client/src/modules/updater.js @@ -8,6 +8,9 @@ * LICENSE file in the root directory of this source tree. */ +import { Notifications } from 'ui'; +import { Reflection, Globals } from 'modules'; + import Events from './events'; import Module from './imodule'; @@ -27,6 +30,50 @@ export default new class extends Module { }); } + bindings() { + this.restartNotif = this.restartNotif.bind(this); + this.reloadNotif = this.reloadNotif.bind(this); + } + + restartNotif() { + Notifications.add('Updates Finished!', 'Restart required.', [ + { + text: 'Restart Later', + onClick: () => { setTimeout(this.restartNotif, 5 * 60000); return true; } + }, + { + text: 'Restart Now', + onClick: () => { + try { + const { remote } = Globals.require('electron'); + window.close(); + Reflection.module.byProps('showToken', 'hideToken').showToken(); + remote.app.relaunch(); + remote.app.exit(0); + } catch (err) { + console.err(err); + return true; + } + } + } + ]); + } + + reloadNotif() { + Notifications.add('Updates Finished!', 'Reload required.', [ + { + text: 'Reload Later', + onClick: () => { setTimeout(this.reloadNotif, 5 * 60000); return true; } + }, + { + text: 'Reload Now', + onClick: () => { + document.location.reload(); + } + } + ]); + } + events(ipc) { ipc.on('updater-checkForUpdates', () => { if (this.state.updating) return; // We're already updating. Updater should be paused anyways at this point. @@ -60,6 +107,19 @@ export default new class extends Module { updatesAvailable: true }); }); + + ipc.on('updater-updated', (_, info) => { + const { reloadRequired, restartRequired } = info; + if (restartRequired) { + this.restartNotif(); + return; + } + + if (reloadRequired) { + this.reloadNotif(); + return; + } + }); } stateChanged(oldState, newState) {