fantasia-archive/src/App.vue

117 lines
3 KiB
Vue
Raw Normal View History

2021-01-31 02:43:13 +13:00
<template>
<div id="q-app">
2021-02-26 14:50:46 +13:00
<appWindowButtons />
2021-01-31 02:43:13 +13:00
<router-view />
</div>
</template>
<script lang="ts">
import BaseClass from "src/BaseClass"
2021-03-18 10:26:08 +13:00
import { Component, Watch } from "vue-property-decorator"
2021-02-26 14:50:46 +13:00
import { defaultKeybinds } from "src/scripts/appSettings/defaultKeybinds"
import appWindowButtons from "src/components/appHeader/AppWindowButtons.vue"
2021-03-18 10:26:08 +13:00
import PouchDB from "pouchdb"
import { OptionsStateInteface } from "./store/module-options/state"
import { colors } from "quasar"
2021-02-26 14:50:46 +13:00
@Component({
components: {
appWindowButtons: appWindowButtons
}
})
2021-01-31 02:43:13 +13:00
export default class App extends BaseClass {
created () {
window.addEventListener("auxclick", this.reactToMiddleClick)
document.body.onmousedown = function (e) {
if (e.button === 1) {
e.preventDefault()
return false
}
}
2021-03-18 10:26:08 +13:00
this.loadSettings().catch(e => console.log(e))
2021-03-08 11:07:40 +13:00
window.addEventListener("keydown", this.triggerKeyPush)
2021-02-26 14:50:46 +13:00
}
triggerKeyPush (e:any) {
2021-03-08 11:07:40 +13:00
// console.log("")
// console.log(`Key: ${e.key}`)
// console.log(`Ctrl: ${e.ctrlKey}`)
// console.log(`Shift: ${e.shiftKey}`)
// console.log(`Alt: ${e.altKey}`)
// console.log(e)
2021-02-26 14:50:46 +13:00
if (e?.altKey === true || e?.ctrlKey || e?.shiftKey) {
const ouputKeycombo = {
altKey: e.altKey,
ctrlKey: e.ctrlKey,
shiftKey: e.shiftKey,
2021-03-18 10:26:08 +13:00
which: e.which
2021-02-26 14:50:46 +13:00
}
this.SSET_updatePressedKey(ouputKeycombo)
}
}
destroyed () {
window.removeEventListener("auxclick", this.reactToMiddleClick)
2021-03-18 10:26:08 +13:00
this.deregisterCustomKeybinds()
this.deregisterDefaultKeybinds()
2021-03-08 11:07:40 +13:00
window.removeEventListener("keydown", this.triggerKeyPush)
}
reactToMiddleClick (e: {button: number, preventDefault: ()=> void}) {
if (e.button === 1) {
e.preventDefault()
}
}
registerDefaultKeybinds () {
defaultKeybinds.forEach(e => this.SSET_registerDefaultKeybind(e))
}
2021-01-31 02:43:13 +13:00
deregisterDefaultKeybinds () {
defaultKeybinds.forEach(e => this.SSET_deregisterDefaultKeybind(e))
}
2021-03-18 10:26:08 +13:00
registerCustomKeybinds () {
setTimeout(() => {
this.SGET_options.userKeybindList.forEach(e => this.SSET_registerUserKeybind(e))
}, 1000)
}
deregisterCustomKeybinds () {
defaultKeybinds.forEach(e => this.SSET_deregisterUserKeybind(e))
}
async loadSettings () {
const SettingsDB = new PouchDB("fa-settings")
const settingsData = await SettingsDB.allDocs({ include_docs: true })
const settings = settingsData?.rows[0]?.doc as unknown as OptionsStateInteface
if (settings) {
this.SSET_options(settings)
}
this.registerDefaultKeybinds()
this.registerCustomKeybinds()
}
@Watch("SGET_options", { deep: true })
onSettingsChange () {
const options = this.SGET_options
this.$q.dark.set(options.darkMode)
if (options.darkMode) {
colors.setBrand("dark", "#1b333e")
colors.setBrand("primary", "#ffd673")
}
else {
colors.setBrand("dark", "#18303a")
colors.setBrand("primary", "#d7ac47")
}
}
2021-01-31 02:43:13 +13:00
}
</script>