-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7966f6b
commit 6127b65
Showing
6 changed files
with
38 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { computed } from 'vue' | ||
import { useMediaQuery } from '@vueuse/core' | ||
import { singleton } from '../utils/common' | ||
import { AppStorage } from '../storage' | ||
import { ColorPreference } from '../constants' | ||
|
||
export const useTheme = singleton(() => { | ||
const prefersDark = useMediaQuery('(prefers-color-scheme: dark)') | ||
|
||
const theme = computed(() => { | ||
const preference = AppStorage.get('colorPreference') | ||
|
||
let theme: ColorPreference.Dark | ColorPreference.Light | ||
|
||
if (preference === ColorPreference.Dark) | ||
theme = ColorPreference.Dark | ||
else if (preference === ColorPreference.Light) | ||
theme = ColorPreference.Light | ||
else | ||
theme = prefersDark.value ? ColorPreference.Dark : ColorPreference.Light | ||
|
||
return theme | ||
}) | ||
|
||
return { theme, prefersDark } | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,4 @@ | ||
import type { Ref, UnwrapRef } from 'vue' | ||
|
||
/** | ||
* Just returns value of passed ref, used for reactivity tracking. | ||
*/ | ||
export function trackRef<T extends Ref<any>>(ref: T): UnwrapRef<T> { | ||
return ref.value | ||
export function singleton<T>(fn: () => T): () => T { | ||
const instance = fn() | ||
return () => instance | ||
} |