mirror of https://github.com/Kylart/KawAnime.git
Fix auto-update
This commit is contained in:
parent
af308d116b
commit
996580ee6b
|
@ -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
|
||||
</template>
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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('_isInstallable')
|
||||
if (data.ok) {
|
||||
commit('setUpdateStatus')
|
||||
commit('setInfoSnackbar', 'Update available. Think about installing it~')
|
||||
} else {
|
||||
setTimeout(() => { dispatch('_isInstallable') }, 1000)
|
||||
}
|
||||
} catch (e) {
|
||||
log(`Error while checking if downloadable. ${e.message}`)
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
setTimeout(() => { dispatch('checkUpdate') }, 15 * 60 * 1000)
|
||||
},
|
||||
async updateApp ({commit}) {
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue