2020-06-16 12:09:05 +12:00
|
|
|
import { getterTree, mutationTree, actionTree } from 'typed-vuex'
|
2020-01-24 04:23:26 +13:00
|
|
|
import { get, set } from '~/utils/localstorage'
|
2020-09-27 12:13:34 +13:00
|
|
|
import { EVENT } from '~/neko/events'
|
2020-06-16 12:09:05 +12:00
|
|
|
import { accessor } from '~/store'
|
2020-01-23 06:16:40 +13:00
|
|
|
|
|
|
|
export const namespaced = true
|
|
|
|
|
2020-06-16 12:09:05 +12:00
|
|
|
interface KeyboardLayouts {
|
|
|
|
[code: string]: string
|
|
|
|
}
|
|
|
|
|
2020-01-24 04:23:26 +13:00
|
|
|
export const state = () => {
|
|
|
|
return {
|
|
|
|
scroll: get<number>('scroll', 10),
|
|
|
|
scroll_invert: get<boolean>('scroll_invert', true),
|
|
|
|
autoplay: get<boolean>('autoplay', true),
|
|
|
|
ignore_emotes: get<boolean>('ignore_emotes', false),
|
|
|
|
chat_sound: get<boolean>('chat_sound', true),
|
2020-06-16 08:09:01 +12:00
|
|
|
keyboard_layout: get<string>('keyboard_layout', 'us'),
|
2020-06-16 12:09:05 +12:00
|
|
|
|
|
|
|
keyboard_layouts_list: {} as KeyboardLayouts,
|
2021-03-02 03:10:20 +13:00
|
|
|
|
2020-09-27 12:13:34 +13:00
|
|
|
broadcast_is_active: false,
|
2021-03-02 03:10:20 +13:00
|
|
|
broadcast_url: '',
|
2020-01-24 04:23:26 +13:00
|
|
|
}
|
|
|
|
}
|
2020-01-23 06:16:40 +13:00
|
|
|
|
|
|
|
export const getters = getterTree(state, {})
|
|
|
|
|
|
|
|
export const mutations = mutationTree(state, {
|
|
|
|
setScroll(state, scroll: number) {
|
|
|
|
state.scroll = scroll
|
2020-01-24 04:23:26 +13:00
|
|
|
set('scroll', scroll)
|
2020-01-23 06:16:40 +13:00
|
|
|
},
|
|
|
|
|
2020-01-24 04:23:26 +13:00
|
|
|
setInvert(state, value: boolean) {
|
|
|
|
state.scroll_invert = value
|
|
|
|
set('scroll_invert', value)
|
2020-01-23 06:16:40 +13:00
|
|
|
},
|
2020-01-24 04:23:26 +13:00
|
|
|
|
|
|
|
setAutoplay(state, value: boolean) {
|
|
|
|
state.autoplay = value
|
|
|
|
set('autoplay', value)
|
|
|
|
},
|
|
|
|
|
|
|
|
setIgnore(state, value: boolean) {
|
|
|
|
state.ignore_emotes = value
|
|
|
|
set('ignore_emotes', value)
|
|
|
|
},
|
|
|
|
|
|
|
|
setSound(state, value: boolean) {
|
|
|
|
state.chat_sound = value
|
|
|
|
set('chat_sound', value)
|
|
|
|
},
|
2020-06-16 08:09:01 +12:00
|
|
|
|
|
|
|
setKeyboardLayout(state, value: string) {
|
|
|
|
state.keyboard_layout = value
|
|
|
|
set('keyboard_layout', value)
|
|
|
|
},
|
2020-06-16 12:09:05 +12:00
|
|
|
|
|
|
|
setKeyboardLayoutsList(state, value: KeyboardLayouts) {
|
|
|
|
state.keyboard_layouts_list = value
|
|
|
|
},
|
2020-09-27 12:13:34 +13:00
|
|
|
setBroadcastStatus(state, { url, isActive }) {
|
2021-03-02 03:10:20 +13:00
|
|
|
state.broadcast_url = url
|
2020-09-27 12:13:34 +13:00
|
|
|
state.broadcast_is_active = isActive
|
|
|
|
},
|
2020-01-24 04:23:26 +13:00
|
|
|
})
|
2020-06-16 12:09:05 +12:00
|
|
|
|
|
|
|
export const actions = actionTree(
|
|
|
|
{ state, getters, mutations },
|
|
|
|
{
|
2021-09-01 03:58:32 +12:00
|
|
|
async initialise() {
|
|
|
|
try {
|
|
|
|
const req = await $http.get<KeyboardLayouts>('keyboard_layouts.json')
|
|
|
|
accessor.settings.setKeyboardLayoutsList(req.data)
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
}
|
2020-06-16 12:09:05 +12:00
|
|
|
},
|
2020-09-27 12:13:34 +13:00
|
|
|
|
|
|
|
broadcastStatus({ getters }, { url, isActive }) {
|
|
|
|
accessor.settings.setBroadcastStatus({ url, isActive })
|
|
|
|
},
|
|
|
|
broadcastCreate({ getters }, url: string) {
|
|
|
|
$client.sendMessage(EVENT.BROADCAST.CREATE, { url })
|
|
|
|
},
|
|
|
|
broadcastDestroy({ getters }) {
|
|
|
|
$client.sendMessage(EVENT.BROADCAST.DESTROY)
|
|
|
|
},
|
2020-06-16 12:09:05 +12:00
|
|
|
},
|
|
|
|
)
|