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

Sync user settings with newer versions on changes

This commit is contained in:
dragongoose 2023-08-18 14:40:25 -04:00
parent 12d6bd2c38
commit 39808373cb
No known key found for this signature in database
GPG key ID: 01397EEC371CDAA5
2 changed files with 48 additions and 29 deletions

View file

@ -20,6 +20,25 @@ export function getDefaultSettings() {
}
}
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}
localStorage.setItem('settings', JSON.stringify(synced))
console.log('Migrated!')
}
export function getSetting(key: string): boolean | string {
const storage = localStorage.getItem('settings')
let parsed
@ -39,4 +58,3 @@ export function getDefaultSettings() {
// is chatVisible
return !p
}

View file

@ -1,9 +1,10 @@
<script lang="ts">
import { getDefaultSettings } from '@/settingsManager'
import { getDefaultSettings, syncUserSettings } from '@/settingsManager'
export default {
setup() {
let settings
syncUserSettings()
let storedSettings = localStorage.getItem('settings')
if (storedSettings === null) {