diff --git a/client/src/modules/imodule.js b/client/src/modules/imodule.js index b16b9ee8..bff59c68 100644 --- a/client/src/modules/imodule.js +++ b/client/src/modules/imodule.js @@ -39,7 +39,7 @@ export default class Module { } setState(newState) { - const oldState = this.state; + const oldState = Object.assign({}, this.state); Object.assign(this.state, newState); if (this.stateChanged) this.stateChanged(oldState, newState); } diff --git a/client/src/modules/updater.js b/client/src/modules/updater.js index 5747e89e..0726cdc3 100644 --- a/client/src/modules/updater.js +++ b/client/src/modules/updater.js @@ -15,27 +15,44 @@ export default new class extends Module { get updates() { return this.state.updates } get bdUpdates() { return this.state.updates.bd } + get error() { return null; } + get updatesAvailable() { return this.state.updatesAvailable; } constructor() { super({ updatesAvailable: false, error: null, - updates: { bd: [] } + updates: { bd: [] }, + updating: false }); } events(ipc) { ipc.on('updater-checkForUpdates', () => { + if (this.state.updating) return; // We're already updating. Updater should be paused anyways at this point. Events.emit('update-check-start'); }); ipc.on('updater-noUpdates', () => { - Events.emit('update-check-end'); + if (this.state.updatesAvailable) return; // If for some reason we get this even though we have updates already. + this.setState({ + updatesAvailable: false, + updates: {} + }); }); ipc.on('updater-updatesAvailable', (_, updates) => { - console.log('UPDATES', updates); + if (this.state.updating) return; // If for some reason we get more updates when we're already updating + this.setState({ + updates, + updatesAvailable: true + }); }); } + stateChanged(oldState, newState) { + if (!newState.updatesAvailable) return Events.emit('update-check-end'); + if (!oldState.updatesAvailable && newState.updatesAvailable) return Events.emit('updates-available'); + } + } diff --git a/client/src/ui/components/bd/UpdaterView.vue b/client/src/ui/components/bd/UpdaterView.vue index e69aa2e8..b091be20 100644 --- a/client/src/ui/components/bd/UpdaterView.vue +++ b/client/src/ui/components/bd/UpdaterView.vue @@ -11,7 +11,18 @@ @@ -36,13 +47,19 @@ }, computed: { updatesAvailable() { - return false; + return this.updater.updatesAvailable; }, newVersion() { return '2.0.0-beta.4'; }, error() { - return null; + return this.updater.error; + }, + updates() { + return this.updater.updates; + }, + bdUpdates() { + return this.updater.bdUpdates; } }, methods: {