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:
parent
12d6bd2c38
commit
39808373cb
2 changed files with 48 additions and 29 deletions
|
@ -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
|
||||
}
|
||||
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue