0
Fork 0
mirror of https://codeberg.org/SafeTwitch/safetwitch.git synced 2024-12-22 13:22:58 -05:00

Move settings related functions

This commit is contained in:
dragongoose 2023-08-18 14:23:59 -04:00
parent 63aff74e6b
commit 12d6bd2c38
No known key found for this signature in database
GPG key ID: 01397EEC371CDAA5
5 changed files with 48 additions and 46 deletions

View file

@ -39,46 +39,4 @@ export async function getEndpoint(endpoint: string) {
const data = rawData.data const data = rawData.data
return data return data
} }
export function getDefaultSettings() {
return {
version: import.meta.env.SAFETWITCH_TAG,
audioOnly: {
name: 'Audio Only',
selected: false,
type: 'checkbox'
},
defaultQuality: {
name: 'Default Quality',
options: ['160p', '360p', '480p', '720p', '1080p'],
selected: '480p',
type: 'option'
},
chatVisible: {
name: 'Hide Chat',
selected: false,
type: 'checkbox'
}
}
}
export function getSetting(key: string): boolean | string {
const storage = localStorage.getItem('settings')
let parsed
if (!storage) {
parsed = getDefaultSettings()
} else {
parsed = JSON.parse(storage)
}
return parsed[key].selected
}
export function chatVisible() {
const p = getSetting('chatVisible')
// Flip becuase on the setting page it's
// displayed as "Hide Chat", but the value
// is chatVisible
return !p
}

42
src/settingsManager.ts Normal file
View file

@ -0,0 +1,42 @@
export function getDefaultSettings() {
return {
version: import.meta.env.SAFETWITCH_TAG,
audioOnly: {
name: 'Audio Only',
selected: false,
type: 'checkbox'
},
defaultQuality: {
name: 'Default Quality',
options: ['160p', '360p', '480p', '720p', '1080p'],
selected: '480p',
type: 'option'
},
chatVisible: {
name: 'Hide Chat',
selected: false,
type: 'checkbox'
}
}
}
export function getSetting(key: string): boolean | string {
const storage = localStorage.getItem('settings')
let parsed
if (!storage) {
parsed = getDefaultSettings()
} else {
parsed = JSON.parse(storage)
}
return parsed[key].selected
}
export function chatVisible() {
const p = getSetting('chatVisible')
// Flip becuase on the setting page it's
// displayed as "Hide Chat", but the value
// is chatVisible
return !p
}

View file

@ -1,5 +1,5 @@
<script lang="ts"> <script lang="ts">
import { getDefaultSettings } from '@/mixins' import { getDefaultSettings } from '@/settingsManager'
export default { export default {
setup() { setup() {

View file

@ -10,7 +10,8 @@ import LoadingScreen from '@/components/LoadingScreen.vue'
import VideoTab from '@/components/user/VideoTab.vue' import VideoTab from '@/components/user/VideoTab.vue'
import type { StreamerData } from '@/types' import type { StreamerData } from '@/types'
import { truncate, abbreviate, getEndpoint, chatVisible } from '@/mixins' import { truncate, abbreviate, getEndpoint } from '@/mixins'
import { chatVisible } from '@/settingsManager'
export default { export default {
inject: ['rootBackendUrl'], inject: ['rootBackendUrl'],

View file

@ -9,7 +9,8 @@ import FollowButton from '@/components/FollowButton.vue'
import LoadingScreen from '@/components/LoadingScreen.vue' import LoadingScreen from '@/components/LoadingScreen.vue'
import type { Video } from '@/types' import type { Video } from '@/types'
import { truncate, abbreviate, getEndpoint, chatVisible } from '@/mixins' import { truncate, abbreviate, getEndpoint } from '@/mixins'
import { chatVisible } from '@/settingsManager'
interface ChatComponent { interface ChatComponent {
updateVodComments: (time: number) => void updateVodComments: (time: number) => void