diff options
author | Justice Almanzar <superdash993@gmail.com> | 2022-12-07 09:33:40 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-07 15:33:40 +0100 |
commit | 2d08dd8a9c289bcdb6395e8bdf28b6b729946ab1 (patch) | |
tree | b15d5c06c3dd881bca64d7eee72a9da0c83e503f /src/plugins/shikiCodeblocks/hooks/useShikiSettings.ts | |
parent | 49b45d82624c3c53aa2a0a4f8bd9957fed75abdd (diff) | |
download | Vencord-2d08dd8a9c289bcdb6395e8bdf28b6b729946ab1.tar.gz Vencord-2d08dd8a9c289bcdb6395e8bdf28b6b729946ab1.tar.bz2 Vencord-2d08dd8a9c289bcdb6395e8bdf28b6b729946ab1.zip |
Shiki settings preview (#297)
Diffstat (limited to 'src/plugins/shikiCodeblocks/hooks/useShikiSettings.ts')
-rw-r--r-- | src/plugins/shikiCodeblocks/hooks/useShikiSettings.ts | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/plugins/shikiCodeblocks/hooks/useShikiSettings.ts b/src/plugins/shikiCodeblocks/hooks/useShikiSettings.ts index 416f8e9..0d92f80 100644 --- a/src/plugins/shikiCodeblocks/hooks/useShikiSettings.ts +++ b/src/plugins/shikiCodeblocks/hooks/useShikiSettings.ts @@ -18,8 +18,19 @@ import { useSettings } from "@api/settings"; +import { shiki } from "../api/shiki"; import { ShikiSettings } from "../types"; -export function useShikiSettings(settings: (keyof ShikiSettings)[]) { - return useSettings(settings.map(setting => `plugins.ShikiCodeblocks.${setting}`)).plugins.ShikiCodeblocks as ShikiSettings; +export function useShikiSettings(settingKeys: (keyof ShikiSettings)[], overrides?: Record<string, any>) { + const settings = useSettings(settingKeys.map(key => `plugins.ShikiCodeblocks.${key}`)).plugins.ShikiCodeblocks as ShikiSettings; + + const withOverrides = { ...settings, ...overrides }; + + const themeUrl = withOverrides.customTheme || withOverrides.theme; + if (themeUrl !== shiki.currentThemeUrl) shiki.setTheme(themeUrl); + + return { + ...withOverrides, + isThemeLoading: themeUrl !== shiki.currentThemeUrl, + }; } |