Isolated update into its own module

This commit is contained in:
Kylart 2017-09-19 14:19:55 +02:00
parent e033b0cdd2
commit 443beede09
14 changed files with 71 additions and 54 deletions

View File

@ -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.isUpdateAvailable", v-tooltip:left="{ html: 'Update KawAnime' }", @click='restartAndUpdate()')
v-btn(icon, v-show="$store.state.update.isAvailable", 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()')
@ -163,7 +163,7 @@
this.$store.dispatch('openInBrowser')
},
restartAndUpdate () {
this.$store.dispatch('updateApp')
this.$store.dispatch('update/updateApp')
}
}
}

View File

@ -35,7 +35,7 @@ export function createApp (ssrContext) {
// App initialization
store.dispatch('init')
!['KawAnime-test', 'development'].includes(process.env.NODE_ENV) && store.dispatch('checkUpdate')
!['KawAnime-test', 'development'].includes(process.env.NODE_ENV) && store.dispatch('update/check')
// sync the router with the vuex store.
// this registers `store.state.route`

View File

@ -2,7 +2,7 @@
* Created by Kylart on 26/07/2017.
*/
import {axios, log} from './utils'
import {axios} from './utils'
export default {
async init ({commit, dispatch}) {
@ -45,43 +45,6 @@ export default {
dispatch('seasons/init').catch(err => { void err })
dispatch('news/init').catch(err => { void err })
},
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}`)
}
},
async updateApp ({commit}) {
try {
await axios.get('_quitAndInstall')
} catch (e) {
commit('setInfoSnackbar', 'An error occurred, please try again later or try restarting KawAnime and retry.')
}
},
async getEnv ({commit}) {
const {data} = await axios.get('_env')

View File

@ -3,7 +3,6 @@ import {log} from '../../utils'
export default {
set (state, data) {
state.config = data
log('Current config: ', state.config)
},
setDir (state, data) {
state.config.localPath = data

View File

@ -1,4 +1,5 @@
export { default as config } from './config'
export { default as update } from './update'
export { default as downloader } from './downloader'
export { default as releases } from './releases'

View File

@ -10,7 +10,7 @@ export default {
},
setDir (state, data) {
state.dir = data
log(`Current directory now is ${state.dir}.`)
log(`Current directory is set to ${state.dir}.`)
},
toggleResetting (state) {
state.resetting = !state.resetting

View File

@ -1,12 +1,6 @@
import state from './state.js'
import mutations from './mutations.js'
import actions from './actions.js'
import getters from './getters.js'
export default {
namespaced: true,
state,
mutations,
actions,
getters
actions
}

View File

@ -0,0 +1,41 @@
import {axios, log, isRoot} from '../../utils'
export default {
async check ({state, commit, dispatch}) {
setTimeout(async () => {
if (!state.isAvailable) {
try {
const {data} = await axios.get('_isUpdateAvailable')
if (data.ok) {
dispatch('isInstallable')
log('An update is available.')
}
} catch (e) {
log(`Error while checking update. ${e.message}`)
}
setTimeout(() => { dispatch('check') }, 30 * 1000)
}
}, 30 * 1000)
},
async isInstallable ({commit, dispatch}) {
try {
const {data} = await axios.get('_isInstallable')
if (data.ok) {
commit('setStatus')
commit('setInfoSnackbar', 'Update available. Think about installing it~', isRoot)
} else {
setTimeout(() => { dispatch('isInstallable') }, 1000)
}
} catch (e) {
log(`Error while checking if downloadable. ${e.message}`)
}
},
async updateApp ({commit}) {
try {
await axios.get('_quitAndInstall')
} catch (e) {
commit('setInfoSnackbar', 'An error occurred, please try again later or try restarting KawAnime and retry.', isRoot)
}
}
}

View File

@ -0,0 +1,3 @@
export default {
}

View File

@ -0,0 +1,12 @@
import state from './state.js'
import mutations from './mutations.js'
import actions from './actions.js'
import getters from './getters.js'
export default {
namespaced: true,
state,
mutations,
actions,
getters
}

View File

@ -0,0 +1,5 @@
export default {
setStatus (state) {
state.isAvailable = true
}
}

View File

@ -0,0 +1,3 @@
export default {
isAvailable: false
}

View File

@ -10,9 +10,6 @@ export default {
setConnected (state, bool) {
state.isConnected = bool
},
setUpdateStatus (state) {
state.isUpdateAvailable = true
},
toggleDrawer (state) {
state.drawer = !state.drawer
},

View File

@ -5,7 +5,6 @@
export default {
NODE_ENV: '',
platform: '',
isUpdateAvailable: false,
isConnected: false,
drawer: false,
infoSnackbar: {