start client engine only once
This commit is contained in:
parent
34132c7703
commit
f7084da78e
@ -5,15 +5,36 @@ export default (context, inject) => {
|
||||
|
||||
const engine = {
|
||||
lastFetched: [0, 0, 0, 0, 0],
|
||||
isActive: false,
|
||||
shouldStop: false,
|
||||
|
||||
async start() {
|
||||
if (!store.state.engine.user) {
|
||||
if (!await this.fetchUserInfo()) {
|
||||
window.location.href = "/"
|
||||
}
|
||||
}
|
||||
if (this.isActive) {
|
||||
console.warn('attempt to start already running engine!')
|
||||
return
|
||||
}
|
||||
|
||||
this.isActive = true
|
||||
this.fetchUpdate()
|
||||
},
|
||||
|
||||
stop() {
|
||||
if (!this.isActive) return
|
||||
this.shouldStop = true
|
||||
},
|
||||
|
||||
async fetchUpdate() {
|
||||
if (this.shouldStop || !this.isActive) {
|
||||
this.isActive = false
|
||||
this.shouldStop = false
|
||||
return
|
||||
}
|
||||
|
||||
let delay = 0
|
||||
try {
|
||||
const url = buildUrl($config.serverBaseUrl, {
|
||||
|
Loading…
Reference in New Issue
Block a user