-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathsetting.ts
93 lines (77 loc) · 2.41 KB
/
setting.ts
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { ref, watch, Ref } from 'vue'
import { defineStore } from 'pinia'
import { IceServer } from '@/types'
import { defaultMaxConnectionNumber, defaultIceServers } from '@/const'
export const useSettingStore = defineStore('setting', () => {
// autoDisplayImage
const autoDisplayImage: Ref<boolean> = ref(true)
if (localStorage.getItem('autoDisplayImage')) {
autoDisplayImage.value = JSON.parse(
localStorage.getItem('autoDisplayImage') as string,
)
}
watch(autoDisplayImage, () => {
localStorage.setItem(
'autoDisplayImage',
JSON.stringify(autoDisplayImage.value),
)
})
// directlyOpenLink
const directlyOpenLink: Ref<boolean> = ref(true)
if (localStorage.getItem('directlyOpenLink')) {
directlyOpenLink.value = JSON.parse(
localStorage.getItem('directlyOpenLink') as string,
)
}
watch(directlyOpenLink, () => {
localStorage.setItem(
'directlyOpenLink',
JSON.stringify(directlyOpenLink.value),
)
})
// autoDownload
const autoDownload: Ref<boolean> = ref(true)
if (localStorage.getItem('autoDownload')) {
autoDownload.value = JSON.parse(
localStorage.getItem('autoDownload') as string,
)
}
watch(autoDownload, () => {
localStorage.setItem('autoDownload', JSON.stringify(autoDownload.value))
})
// maxConnectionNumber
const maxConnectionNumber: Ref<number> = ref(defaultMaxConnectionNumber)
if (localStorage.getItem('maxConnectionNumber')) {
maxConnectionNumber.value = JSON.parse(
localStorage.getItem('maxConnectionNumber') as string,
)
}
watch(maxConnectionNumber, () => {
localStorage.setItem(
'maxConnectionNumber',
JSON.stringify(maxConnectionNumber.value),
)
})
// iceServers
const iceServers: Ref<IceServer[]> = ref(defaultIceServers)
if (localStorage.getItem('iceServers')) {
const existingIceServers = JSON.parse(
localStorage.getItem('iceServers') as string,
)
const newIceServers = [...iceServers.value, ...existingIceServers]
const uniqueIceServers = Array.from(
new Set(newIceServers.map(server => JSON.stringify(server))),
).map(server => JSON.parse(server))
iceServers.value = uniqueIceServers
}
watch(iceServers, () => {
localStorage.setItem('iceServers', JSON.stringify(iceServers.value))
})
return {
autoDisplayImage,
directlyOpenLink,
autoDownload,
maxConnectionNumber,
iceServers,
}
})