knowyt/client/src/composables/engine/startStop.ts

31 lines
859 B
TypeScript
Raw Normal View History

import { useUserinfoStore } from "@/stores/UserinfoStore"
import { EngineContext } from '@/composables/useEngine'
2022-09-03 19:41:30 +00:00
import useAlert from '@/composables/useAlert'
export function start(this: EngineContext): void {
if (this.isActive && !this.shouldStop) {
console.warn('attempt to start already running engine!')
return
}
if (useUserinfoStore().isAdmin) {
console.debug('user is admin, engine not started')
return
}
2022-09-03 19:41:30 +00:00
useAlert().clearAlert()
this.isActive = true
this.shouldStop = false
this.isConnected.value = true
2022-09-03 19:41:30 +00:00
this.fetchUpdate()
console.log('start engine')
}
export function stop(this: EngineContext): void {
if (this.isActive) {
2022-09-03 19:41:30 +00:00
useAlert().clearAlert()
this.shouldStop = true
this.isConnected.value = true
console.log('shut down engine')
}
}