2023-08-18 14:23:59 -04:00
|
|
|
export function getDefaultSettings() {
|
|
|
|
return {
|
2023-08-18 14:40:25 -04:00
|
|
|
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'
|
|
|
|
}
|
2023-08-18 14:23:59 -04:00
|
|
|
}
|
2023-08-18 14:40:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export function syncUserSettings() {
|
|
|
|
const defaultSettings = getDefaultSettings()
|
|
|
|
let userSettings = localStorage.getItem('settings')
|
|
|
|
if (!userSettings) return
|
|
|
|
const parsedUserSettings = JSON.parse(userSettings)
|
|
|
|
|
|
|
|
if(parsedUserSettings.version === import.meta.env.SAFETWITCH_TAG) {
|
|
|
|
console.log('Settings up to date!')
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
console.log('Settings outdated... Migrating')
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const synced = {...defaultSettings, ...parsedUserSettings}
|
2023-08-18 15:04:58 -04:00
|
|
|
synced.version = import.meta.env.SAFETWITCH_TAG
|
2023-08-18 14:40:25 -04:00
|
|
|
localStorage.setItem('settings', JSON.stringify(synced))
|
|
|
|
console.log('Migrated!')
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getSetting(key: string): boolean | string {
|
2023-08-18 14:23:59 -04:00
|
|
|
const storage = localStorage.getItem('settings')
|
|
|
|
let parsed
|
|
|
|
if (!storage) {
|
2023-08-18 14:40:25 -04:00
|
|
|
parsed = getDefaultSettings()
|
2023-08-18 14:23:59 -04:00
|
|
|
} else {
|
2023-08-18 14:40:25 -04:00
|
|
|
parsed = JSON.parse(storage)
|
2023-08-18 14:23:59 -04:00
|
|
|
}
|
2023-08-18 14:40:25 -04:00
|
|
|
|
2023-08-18 14:23:59 -04:00
|
|
|
return parsed[key].selected
|
2023-08-18 14:40:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export function chatVisible() {
|
2023-08-18 14:23:59 -04:00
|
|
|
const p = getSetting('chatVisible')
|
|
|
|
// Flip becuase on the setting page it's
|
|
|
|
// displayed as "Hide Chat", but the value
|
|
|
|
// is chatVisible
|
|
|
|
return !p
|
2023-08-18 14:40:25 -04:00
|
|
|
}
|