diff --git a/assets/App.vue b/assets/App.vue index 0a7b5ab..d5cc85a 100644 --- a/assets/App.vue +++ b/assets/App.vue @@ -34,7 +34,7 @@ v-toolbar-side-icon(@click.stop='toggleDrawer()') v-toolbar-title.white--text.title.hidden-xs-only かわニメ v-spacer - v-btn(icon, v-show="$store.state.updateAvailable",v-tooltip:left="{ html: 'Update KawAnime' }", @click='restartAndUpdate()') + v-btn(icon, v-show="$store.state.isUpdateAvailable", v-tooltip:left="{ html: 'Update KawAnime' }", @click='restartAndUpdate()') v-icon.green--text file_download info-modal v-btn(icon, v-tooltip:left="{ html: 'Open KawAnime in your browser' }", @click='openInBrowser()') @@ -60,7 +60,7 @@ ) {{ $store.state.infoSnackbar.text }} v-btn.pink--text(flat, @click='$store.state.infoSnackbar.show = false') Close - v-footer.grey.darken-4 + v-footer.grey.darken-4.pr-2 v-spacer .white--text © 2016 - 2017 Kylart diff --git a/server/updater.js b/server/updater.js index 4534b9c..12c5eb9 100644 --- a/server/updater.js +++ b/server/updater.js @@ -1,13 +1,15 @@ module.exports = (app, routes) => { const {autoUpdater} = require('electron-updater') let isUpdateAvailable = false + let isInstallable = false + let downloadProgress let error - autoUpdater.on('update-available', (info) => { + autoUpdater.on('update-available', () => { isUpdateAvailable = true }) - autoUpdater.on('update-not-available', (info) => { + autoUpdater.on('update-not-available', () => { isUpdateAvailable = false }) @@ -15,21 +17,33 @@ module.exports = (app, routes) => { error = err }) - autoUpdater.on('update-downloaded', (info) => { - autoUpdater.quitAndInstall() + autoUpdater.on('download-progress', (progressObj) => { + downloadProgress = progressObj + }) + + autoUpdater.on('update-downloaded', () => { + isInstallable = true }) autoUpdater.checkForUpdates() routes.push( (app) => { - app.get('/_isUpdateAvailable', async (req, res) => { + app.get('/_isUpdateAvailable', (req, res) => { res.send({ ok: isUpdateAvailable, data: error }) }) }, + (app) => { + app.get('/_isInstallable', (req, res) => { + res.send({ + ok: isInstallable, + progress: downloadProgress + }) + }) + }, (app) => { app.get('/_quitAndInstall', () => { autoUpdater.quitAndInstall() diff --git a/store/actions.js b/store/actions.js index f363bd4..db07a08 100644 --- a/store/actions.js +++ b/store/actions.js @@ -36,16 +36,35 @@ export default { dispatch('seasonsInit').catch(err => { void (err) }) dispatch('newsInit').catch(err => { void (err) }) }, - async checkUpdate ({commit, dispatch}) { + async checkUpdate ({state, commit, dispatch}) { + setTimeout(async () => { + if (!state.isUpdateAvailable) { + try { + const {data} = await axios.get('_isUpdateAvailable') + if (data.ok) { + dispatch('isUpdateInstallable') + log('An update is available.') + } + } catch (e) { + log(`Error while checking update. ${e.message}`) + } + + setTimeout(() => { dispatch('checkUpdate') }, 30 * 1000) + } + }, 30 * 1000) + }, + async isUpdateInstallable ({commit, dispatch}) { try { - const {data} = await axios.get('_isUpdateAvailable') + const {data} = await axios.get('_isInstallable') if (data.ok) { commit('setUpdateStatus') commit('setInfoSnackbar', 'Update available. Think about installing it~') + } else { + setTimeout(() => { dispatch('_isInstallable') }, 1000) } - } catch (e) {} - - setTimeout(() => { dispatch('checkUpdate') }, 15 * 60 * 1000) + } catch (e) { + log(`Error while checking if downloadable. ${e.message}`) + } }, async updateApp ({commit}) { try {