feat(theme): auto-load theme overrides or force to state

This commit is contained in:
dragonwocky 2023-01-09 22:38:16 +11:00
parent 8c935ffb5d
commit bb7f044d3a
Signed by: dragonwocky
GPG Key ID: 7998D08F7D7BD7A8
3 changed files with 25 additions and 11 deletions

View File

@ -24,15 +24,15 @@ const getMods = async () => {
}, },
getThemes = async () => { getThemes = async () => {
const mods = await getMods(); const mods = await getMods();
return mods.find(({ _src }) => _src.startsWith("themes/")); return mods.filter(({ _src }) => _src.startsWith("themes/"));
}, },
getExtensions = async () => { getExtensions = async () => {
const mods = await getMods(); const mods = await getMods();
return mods.find(({ _src }) => _src.startsWith("extensions/")); return mods.filter(({ _src }) => _src.startsWith("extensions/"));
}, },
getIntegrations = async () => { getIntegrations = async () => {
const mods = await getMods(); const mods = await getMods();
return mods.find(({ _src }) => _src.startsWith("integrations/")); return mods.filter(({ _src }) => _src.startsWith("integrations/"));
}; };
const getProfile = async () => { const getProfile = async () => {

View File

@ -7,8 +7,17 @@
const notionSidebar = `.notion-sidebar-container .notion-sidebar > :nth-child(3) > div > :nth-child(2)`; const notionSidebar = `.notion-sidebar-container .notion-sidebar > :nth-child(3) > div > :nth-child(2)`;
export default async (api, db) => { export default async (api, db) => {
const { platform, enhancerUrl, onMessage, sendMessage } = api, const {
{ html, addMutationListener, addKeyListener } = api, html,
platform,
getThemes,
isEnabled,
enhancerUrl,
onMessage,
sendMessage,
addMutationListener,
addKeyListener,
} = api,
openMenuHotkey = await db.get("openMenuHotkey"), openMenuHotkey = await db.get("openMenuHotkey"),
menuButtonIconStyle = await db.get("menuButtonIconStyle"), menuButtonIconStyle = await db.get("menuButtonIconStyle"),
loadThemeOverrides = await db.get("loadThemeOverrides"), loadThemeOverrides = await db.get("loadThemeOverrides"),
@ -16,7 +25,12 @@ export default async (api, db) => {
// appearance // appearance
if (loadThemeOverrides) { const enabledThemes = (await getThemes()).map((theme) => isEnabled(theme.id)),
forceLoadOverrides = loadThemeOverrides === "Enabled",
autoLoadOverrides =
loadThemeOverrides === "Auto" &&
(await Promise.all(enabledThemes)).some((enabled) => enabled);
if (forceLoadOverrides || autoLoadOverrides) {
document.head.append(html`<link document.head.append(html`<link
rel="stylesheet" rel="stylesheet"
href=${enhancerUrl("core/theme.css")} href=${enhancerUrl("core/theme.css")}
@ -88,7 +102,7 @@ export default async (api, db) => {
> >
<div class="flex items-center justify-center w-[22px] h-[22px] mr-[8px]"> <div class="flex items-center justify-center w-[22px] h-[22px] mr-[8px]">
<i <i
class="i-notion-enhancer${menuButtonIconStyle === "monochrome" class="i-notion-enhancer${menuButtonIconStyle === "Monochrome"
? "?mask" ? "?mask"
: " text-[16px]"}" : " text-[16px]"}"
></i> ></i>

View File

@ -30,13 +30,13 @@
"type": "select", "type": "select",
"key": "menuButtonIconStyle", "key": "menuButtonIconStyle",
"description": "Sets whether the notion-enhancer icon added to Notion's sidebar should be coloured or monochrome. The latter style will match the theme's icon colour for users who would like the icon to be less noticeable.", "description": "Sets whether the notion-enhancer icon added to Notion's sidebar should be coloured or monochrome. The latter style will match the theme's icon colour for users who would like the icon to be less noticeable.",
"values": ["colour", "monochrome"] "values": ["Colour", "Monochrome"]
}, },
{ {
"type": "toggle", "type": "select",
"key": "loadThemeOverrides", "key": "loadThemeOverrides",
"description": "Loads the styling required for a theme to customise Notion's interface. Turning this off will disable all themes but may increase client performance.", "description": "Loads the styling required for a theme to customise Notion's interface. Disabling this will increase client performance.",
"value": true "values": ["Auto", "Enabled", "Disabled"]
}, },
{ {
"type": "file", "type": "file",