Add:Theme option setting #916

This commit is contained in:
advplyr
2023-12-11 18:11:17 -06:00
parent 1cf01a5d12
commit 9298065934
4 changed files with 63 additions and 2 deletions
+7
View File
@@ -245,6 +245,13 @@ export default ({ store, app }, inject) => {
const eventBus = new Vue()
inject('eventBus', eventBus)
// Set theme
app.$localStore?.getTheme()?.then((theme) => {
if (theme) {
document.documentElement.dataset.theme = theme
}
})
// iOS Only
// backButton event does not work with iOS swipe navigation so use this workaround
if (app.router && Capacitor.getPlatform() === 'ios') {
+19
View File
@@ -141,6 +141,25 @@ class LocalStorage {
return false
}
}
async setTheme(theme) {
try {
await Preferences.set({ key: 'theme', value: theme })
console.log('[LocalStorage] Set theme', theme)
} catch (error) {
console.error('[LocalStorage] Failed to set theme', error)
}
}
async getTheme() {
try {
var obj = await Preferences.get({ key: 'theme' }) || {}
return obj.value || null
} catch (error) {
console.error('[LocalStorage] Failed to get theme', error)
return false
}
}
}