blob: 26001c7ba4dade5287c6eb309f484f3ed32093ef (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
import 'pinia'
import { useAutoHeartbeat } from '@vnuge/vnlib.browser';
import { toRefs, useLocalStorage } from '@vueuse/core';
import { PiniaPluginContext, PiniaPlugin } from 'pinia'
import { defaults } from 'lodash-es';
declare module 'pinia' {
export interface PiniaCustomProperties {
autoHeartbeat: boolean;
}
}
export const globalStatePlugin: PiniaPlugin = ({ store }: PiniaPluginContext) =>{
//Get shared global state storage
const mainState = useLocalStorage("vn-state", { ahEnabled: false });
//Set defaults to avoid undefined errors from toRefs
defaults(mainState.value, { ahEnabled: false })
const { ahEnabled } = toRefs(mainState)
//Setup heartbeat for 5 minutes
useAutoHeartbeat(5 * 60 * 1000, ahEnabled)
return{
autoHeartbeat: ahEnabled,
}
}
|