From 8c7750b69533d23c29d7cebad74ffda181914b17 Mon Sep 17 00:00:00 2001 From: dragongoose Date: Mon, 12 Feb 2024 11:27:19 -0500 Subject: [PATCH] Improve theme management and add default theme environment variable #94 --- env.d.ts | 1 + src/settingsManager.ts | 20 ++++++++++++++++++-- src/views/HomepageView.vue | 1 - src/views/SettingsView.vue | 4 ++-- substitute_environment_variables.sh | 5 +++-- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/env.d.ts b/env.d.ts index bfe7524..5c06b76 100644 --- a/env.d.ts +++ b/env.d.ts @@ -13,6 +13,7 @@ interface ImportMetaEnv { readonly SAFETWITCH_FALLBACK_LOCALE: string readonly SAFETWITCH_COMMIT_HASH: string readonly SAFETWITCH_TAG: string + readonly SAFETWITCH_DEFAULT_THEME: string // more env variables... } diff --git a/src/settingsManager.ts b/src/settingsManager.ts index c94e6d5..7543556 100644 --- a/src/settingsManager.ts +++ b/src/settingsManager.ts @@ -203,8 +203,24 @@ export function getFollows(): string[] { * @returns the name of the current theme * @default string light */ -export function getTheme() { - return localStorage.getItem('theme') || 'light' +export function getTheme(): string { + const selectedTheme = localStorage.getItem('theme') || import.meta.env.SAFETWITCH_DEFAULT_THEME + + if (selectedTheme === "") { + return 'light' + } + + // Make sure theme exists + const t = themeList.filter(theme => theme.name === selectedTheme) + if (t.length === 0) { + console.error(`Theme ${selectedTheme} does not exist... Perhaps improperly setup instance defaults or improper config? + Stored Theme: ${localStorage.getItem('theme')} + Default Theme: ${import.meta.env.SAFETWITCH_DEFAULT_THEME} + `) + return 'light' + } + + return selectedTheme } // every avaliable theme diff --git a/src/views/HomepageView.vue b/src/views/HomepageView.vue index a6c7783..812576b 100644 --- a/src/views/HomepageView.vue +++ b/src/views/HomepageView.vue @@ -11,7 +11,6 @@ import type { CategoryPreview as CategoryPreviewInterface } from '@/types' import { getFollows } from '@/settingsManager' export default { - inject: ['protocol'], async setup() { let data = ref() let status = ref<'ok' | 'error'>() diff --git a/src/views/SettingsView.vue b/src/views/SettingsView.vue index 28c64a7..2b21762 100644 --- a/src/views/SettingsView.vue +++ b/src/views/SettingsView.vue @@ -1,6 +1,6 @@