diff --git a/src/api/electron.cjs b/src/api/electron.cjs
index bd32d36..b9efeec 100644
--- a/src/api/electron.cjs
+++ b/src/api/electron.cjs
@@ -78,10 +78,15 @@ const initDatabase = (namespace, fallbacks = {}) => {
get: (key) => {
const fallback = fallbacks[key];
key = key.startsWith(namespace) ? key : namespace + key;
- return select.get(key)?.value ?? fallback;
+ try {
+ return JSON.parse(select.get(key)?.value);
+ } catch {
+ return select.get(key)?.value ?? fallback;
+ }
},
set: (key, value) => {
key = key.startsWith(namespace) ? key : namespace + key;
+ value = JSON.stringify(value);
return select.get(key) === undefined
? insert.run(key, value)
: update.run(value, key);
diff --git a/src/core/client.mjs b/src/core/client.mjs
index db1d269..738f1cc 100644
--- a/src/core/client.mjs
+++ b/src/core/client.mjs
@@ -21,7 +21,7 @@ export default async (api, db) => {
openMenuHotkey = await db.get("openMenuHotkey"),
menuButtonIconStyle = await db.get("menuButtonIconStyle"),
loadThemeOverrides = await db.get("loadThemeOverrides"),
- customStyles = JSON.parse((await db.get("customStyles")) || "{}").content;
+ customStyles = (await db.get("customStyles"))?.content;
// appearance
@@ -54,8 +54,8 @@ export default async (api, db) => {
_notionTheme = notionTheme;
const msg = {
namespace: "notion-enhancer",
- iconStyle: menuButtonIconStyle,
- mode: notionTheme,
+ theme: notionTheme,
+ icon: menuButtonIconStyle,
};
$menuFrame?.contentWindow.postMessage(msg, "*");
}
@@ -64,6 +64,7 @@ export default async (api, db) => {
const openMenu = () => {
updateTheme(true);
$menuModal?.setAttribute("open", true);
+ $menuFrame?.contentWindow.focus();
},
closeMenu = () => $menuModal?.removeAttribute("open");
@@ -129,6 +130,7 @@ export default async (api, db) => {
});
document.querySelector(notionSidebar)?.append($menuButton);
+ window.addEventListener("focus", () => updateTheme(true));
addMutationListener("body", () => {
if ($menuModal?.hasAttribute("open")) updateTheme();
});
diff --git a/src/core/menu/components.mjs b/src/core/menu/components.mjs
index bfdfcdb..ccc6a12 100644
--- a/src/core/menu/components.mjs
+++ b/src/core/menu/components.mjs
@@ -4,7 +4,7 @@
* (https://notion-enhancer.github.io/) under the MIT license
*/
-import { setState, useState } from "./state.mjs";
+import { setState, useState, getState } from "./state.mjs";
function Sidebar({}, ...children) {
const { html } = globalThis.__enhancerApi;
@@ -43,7 +43,7 @@ function SidebarButton({ icon, ...props }, ...children) {
/>`;
if (!props.href) {
const id = $el.innerText;
- $el.onclick ??= () => setState({ view: id });
+ $el.onclick ??= () => setState({ transition: "fade", view: id });
useState(["view"], ([view = "welcome"]) => {
const active = view.toLowerCase() === id.toLowerCase();
$el.style.background = active ? "var(--theme--bg-hover)" : "";
@@ -55,16 +55,34 @@ function SidebarButton({ icon, ...props }, ...children) {
function View({ id }, ...children) {
const { html } = globalThis.__enhancerApi,
+ duration = 100,
$el = html` {
- // open mod options page
- }}
+ onclick=${() => setState({ transition: "none", view: id })}
>
`
: "";
return html`