Compare commits
5 commits
883ec0354d
...
4d5cd86ec3
Author | SHA1 | Date | |
---|---|---|---|
4d5cd86ec3 | |||
3953a754bd | |||
2ce09e7c7a | |||
73606b6bc3 | |||
8a172db3f4 |
3 changed files with 38 additions and 27 deletions
21
app.vue
21
app.vue
|
@ -1,14 +1,18 @@
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<Banner v-if="banner" />
|
<Banner v-if="banner" />
|
||||||
<NuxtPage :keepalive="true" />
|
<NuxtPage :keepalive="true" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
import loadPreferredTheme from '~/utils/loadPreferredTheme';
|
||||||
|
|
||||||
const banner = useState("banner", () => false);
|
const banner = useState("banner", () => false);
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
loadPreferredTheme()
|
||||||
|
|
||||||
document.removeEventListener("contextmenu", contextMenuHandler);
|
document.removeEventListener("contextmenu", contextMenuHandler);
|
||||||
document.addEventListener("contextmenu", (e) => {
|
document.addEventListener("contextmenu", (e) => {
|
||||||
if (e.target instanceof Element && e.target.classList.contains("default-contextmenu")) return;
|
if (e.target instanceof Element && e.target.classList.contains("default-contextmenu")) return;
|
||||||
|
@ -48,15 +52,6 @@ function contextMenuHandler(e: MouseEvent) {
|
||||||
//]);
|
//]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentTheme = settingsLoad().selectedThemeId ?? "dark"
|
|
||||||
const baseURL = useRuntimeConfig().app.baseURL;
|
|
||||||
|
|
||||||
useHead({
|
|
||||||
link: [{
|
|
||||||
rel: "stylesheet",
|
|
||||||
href: `${baseURL}themes/${currentTheme}.css`
|
|
||||||
}]
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
|
@ -32,13 +32,13 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import RadioButtons from '~/components/UserInterface/RadioButtons.vue';
|
import RadioButtons from '~/components/UserInterface/RadioButtons.vue';
|
||||||
import type { TimeFormat } from '~/types/settings';
|
import type { TimeFormat } from '~/types/settings';
|
||||||
|
import loadPreferredTheme from '~/utils/loadPreferredTheme';
|
||||||
import settingSave from '~/utils/settingSave';
|
import settingSave from '~/utils/settingSave';
|
||||||
|
|
||||||
const runtimeConfig = useRuntimeConfig()
|
const runtimeConfig = useRuntimeConfig()
|
||||||
const defaultThemes = runtimeConfig.public.defaultThemes
|
const defaultThemes = runtimeConfig.public.defaultThemes
|
||||||
const baseURL = runtimeConfig.app.baseURL;
|
const baseURL = runtimeConfig.app.baseURL;
|
||||||
const timeFormatTextStrings = ["Auto", "12-Hour", "24-Hour"]
|
const timeFormatTextStrings = ["Auto", "12-Hour", "24-Hour"]
|
||||||
let themeLinkElement: HTMLLinkElement | null = null;
|
|
||||||
|
|
||||||
const themes: Array<Theme> = []
|
const themes: Array<Theme> = []
|
||||||
|
|
||||||
|
@ -51,20 +51,8 @@ interface Theme {
|
||||||
}
|
}
|
||||||
|
|
||||||
function changeTheme(id: string, url: string) {
|
function changeTheme(id: string, url: string) {
|
||||||
if (themeLinkElement && themeLinkElement.getAttribute('href') === `${baseURL}themes/${url}`) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
settingSave("selectedThemeId", id)
|
settingSave("selectedThemeId", id)
|
||||||
|
loadPreferredTheme()
|
||||||
// if the theme didn't originally load for some reason, create it
|
|
||||||
if (!themeLinkElement) {
|
|
||||||
themeLinkElement = document.createElement('link');
|
|
||||||
themeLinkElement.rel = 'stylesheet';
|
|
||||||
document.head.appendChild(themeLinkElement);
|
|
||||||
}
|
|
||||||
|
|
||||||
themeLinkElement.href = `${baseURL}themes/${url}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchThemes() {
|
async function fetchThemes() {
|
||||||
|
|
28
utils/loadPreferredTheme.ts
Normal file
28
utils/loadPreferredTheme.ts
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
let themeLinkElement: HTMLLinkElement | null;
|
||||||
|
|
||||||
|
export default function loadPreferredTheme() {
|
||||||
|
const currentTheme = settingsLoad().selectedThemeId ?? "dark"
|
||||||
|
|
||||||
|
if (themeLinkElement) {
|
||||||
|
themeLinkElement.href = getThemeUrl(currentTheme);
|
||||||
|
} else {
|
||||||
|
// create the theme link if one doesn't already exist
|
||||||
|
useHead({
|
||||||
|
link: [{
|
||||||
|
id: "main-theme",
|
||||||
|
rel: "stylesheet",
|
||||||
|
href: getThemeUrl(currentTheme)
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
|
||||||
|
themeLinkElement = document.getElementById('main-theme') as HTMLLinkElement;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getThemeUrl(id: string): string {
|
||||||
|
const runtimeConfig = useRuntimeConfig()
|
||||||
|
const baseURL = runtimeConfig.app.baseURL;
|
||||||
|
|
||||||
|
// this should preferrably use version hash, but that's not implemented yet
|
||||||
|
return `${baseURL}themes/${id}.css?v=${runtimeConfig.public.buildTimeString}`
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue