diff --git a/src/AppState.ts b/src/AppState.ts index 1b14f28..c15e69d 100644 --- a/src/AppState.ts +++ b/src/AppState.ts @@ -1,4 +1,4 @@ -import { inject, type InjectionKey, ref, getCurrentInstance, watch } from "vue"; +import { inject, type InjectionKey, ref, getCurrentInstance, watch, computed } from "vue"; import { Bound } from "./utils"; export type UITool = @@ -6,24 +6,49 @@ export type UITool = | "sticking"; class AppStateStore extends Bound { + private osThemeIsDark = ref(false); + private isDarkUser = ref(null); selectedTool = ref("track-unit-type"); activeTrackUnitType = ref(0); activeStickingType = ref(1); unitMouseStart = ref(null); selectingUnits = ref(false); deselectingUnits = ref(false); - isDark = ref(false); + isDark = computed({ + get: () => this.isDarkUser.value === null ? this.osThemeIsDark.value : this.isDarkUser.value, + set: (value) => { + this.isDarkUser.value = value; + }, + }); constructor() { super(); - this.isDark.value = localStorage?.getItem("drum-slayer-theme") === "dark"; + const isDarkUserInitial = localStorage?.getItem("drum-slayer-theme"); + if (isDarkUserInitial === "dark") { + this.isDarkUser.value = true; + } else if (isDarkUserInitial === "light") { + this.isDarkUser.value = false; + } + + const mediaQueryList = window.matchMedia("(prefers-color-scheme: dark)"); + const onMediaChange = (event: MediaQueryListEvent | MediaQueryList) => { + this.osThemeIsDark.value = event.matches; + }; + mediaQueryList.onchange = onMediaChange; + onMediaChange(mediaQueryList); + + watch(this.isDarkUser, (newIsDarkUser) => { + if (typeof newIsDarkUser === "boolean") { + localStorage?.setItem("drum-slayer-theme", newIsDarkUser ? "dark" : "light"); + } + }, { immediate: true }); + watch(this.isDark, (newIsDark) => { if (newIsDark) { document.body.classList.add("dark"); } else { document.body.classList.remove("dark"); } - localStorage?.setItem("drum-slayer-theme", newIsDark ? "dark" : "light"); }, { immediate: true }); } } diff --git a/src/ui/Beat/Beat.vue b/src/ui/Beat/Beat.vue index 967185f..db5c9c2 100644 --- a/src/ui/Beat/Beat.vue +++ b/src/ui/Beat/Beat.vue @@ -38,7 +38,9 @@ - +
+ +
@@ -209,6 +211,12 @@ opacity: 0; } + .track-settings-row { + background-color: var(--color-bg-medium); + width: 100%; + margin-bottom: 0.5em; + } + .vertical-mode { .beat-title { color: var(--color-title-light); diff --git a/src/ui/Root/Root.vue b/src/ui/Root/Root.vue index 3329d57..023e440 100644 --- a/src/ui/Root/Root.vue +++ b/src/ui/Root/Root.vue @@ -51,12 +51,6 @@ @click="toggleOrientation"> -
- -
- - -
- -
-
- -
+ + + +
@@ -31,35 +27,18 @@