diff --git a/src/api/browser.js b/src/api/browser.js index c0a1c34..99f3e80 100644 --- a/src/api/browser.js +++ b/src/api/browser.js @@ -7,7 +7,7 @@ "use strict"; const platform = "browser", - enhancerVersion = chrome.runtime.getManifest().version, + version = chrome.runtime.getManifest().version, enhancerUrl = (target) => chrome.runtime.getURL(target); const readFile = async (file) => { @@ -75,8 +75,8 @@ const initDatabase = (namespace, fallbacks = {}) => { globalThis.__enhancerApi ??= {}; Object.assign(globalThis.__enhancerApi, { platform, + version, enhancerUrl, - enhancerVersion, readFile, readJson, reloadApp, diff --git a/src/api/electron.cjs b/src/api/electron.cjs index c4bd916..cabd997 100644 --- a/src/api/electron.cjs +++ b/src/api/electron.cjs @@ -7,12 +7,11 @@ "use strict"; const fs = require("fs"), - os = require("os"), path = require("path"), notionRequire = (target) => require(`../../../${target}`); const platform = process.platform, - enhancerVersion = require("notion-enhancer/package.json").version, + version = require("notion-enhancer/package.json").version, enhancerUrl = (target) => `notion://www.notion.so/__notion-enhancer/${target.replace(/^\//, "")}`; @@ -72,6 +71,7 @@ const initDatabase = (namespace, fallbacks = {}) => { init.run(); // schema: + // - ("agreedToTerms") -> boolean // - ("profileIds") -> $profileId[] // - ("activeProfile") -> $profileId // - $profileId: ("profileName") -> string @@ -148,8 +148,8 @@ globalThis.__enhancerApi ??= {}; Object.assign(globalThis.__enhancerApi, { notionRequire, platform, + version, enhancerUrl, - enhancerVersion, readFile, readJson, reloadApp, diff --git a/src/api/interface.js b/src/api/interface.js index 8748e95..20f41d0 100644 --- a/src/api/interface.js +++ b/src/api/interface.js @@ -547,7 +547,7 @@ const h = (type, props, ...children) => { for (const prop in props ?? {}) { if (typeof props[prop] === "undefined") continue; if (htmlAttributes.includes(prop) || prop.startsWith("data-")) { - if (typeof props[prop] === "boolean") { + if (typeof props[prop] === "boolean" && !prop.startsWith("data-")) { if (!props[prop]) continue; elem.setAttribute(prop, ""); } else elem.setAttribute(prop, props[prop]); diff --git a/src/api/mods.js b/src/api/mods.js index 8bd64a9..6f383fb 100644 --- a/src/api/mods.js +++ b/src/api/mods.js @@ -46,11 +46,15 @@ const getMods = async (category) => { }; const isEnabled = async (id) => { - const mod = (await getMods()).find((mod) => mod.id === id); + const { version, initDatabase } = globalThis.__enhancerApi, + mod = (await getMods()).find((mod) => mod.id === id); + if (mod._src === "core") return true; // prettier-ignore - return mod._src === "core" || await globalThis.__enhancerApi - .initDatabase([await getProfile(), "enabledMods"]) - .get(id); + const agreedToTerms = await initDatabase().get("agreedToTerms"), + enabledInProfile = await initDatabase([ + await getProfile(), "enabledMods", + ]).get(id); + return agreedToTerms === version && enabledInProfile; }, setEnabled = async (id, enabled) => { return await globalThis.__enhancerApi diff --git a/src/core/client.mjs b/src/core/client.mjs index 76f0c82..024a05b 100644 --- a/src/core/client.mjs +++ b/src/core/client.mjs @@ -10,6 +10,7 @@ export default async (api, db) => { const { html, platform, + version, getMods, isEnabled, enhancerUrl, @@ -17,6 +18,7 @@ export default async (api, db) => { sendMessage, addMutationListener, addKeyListener, + initDatabase, } = api, openMenuHotkey = await db.get("openMenuHotkey"), menuButtonIconStyle = await db.get("menuButtonIconStyle"), @@ -153,4 +155,8 @@ export default async (api, db) => { }); sendMessage("notion-enhancer", "load-complete"); + + if ((await initDatabase().get("agreedToTerms")) === version) { + // telemetry + } }; diff --git a/src/core/menu/components/Button.mjs b/src/core/menu/components/Button.mjs index 324c829..c1b1bf5 100644 --- a/src/core/menu/components/Button.mjs +++ b/src/core/menu/components/Button.mjs @@ -26,15 +26,16 @@ function Button({ icon, variant, tagName, ...props }, ...children) { bg-purple-500 hover:(from-white/20 to-transparent bg-[linear-gradient(225deg,var(--tw-gradient-stops))])` : `border-(& [color:var(--theme--fg-border)]) - hover:bg-[color:var(--theme--bg-hover)]` + not-disabled:hover:bg-[color:var(--theme--bg-hover)] + disabled:text-[color:var(--theme--fg-secondary)]` }`, }); - if (props["href"]) tagName ??= "a"; - return html`<${tagName ?? "button"} tabindex="0" ...${props}> + tagName ??= props["href"] ? "a" : "button"; + return html`<${tagName} ...${props}> ${icon ? html`` : ""} diff --git a/src/core/menu/components/Checkbox.mjs b/src/core/menu/components/Checkbox.mjs index 664dd75..3b00b09 100644 --- a/src/core/menu/components/Checkbox.mjs +++ b/src/core/menu/components/Checkbox.mjs @@ -18,8 +18,9 @@ function Checkbox({ _get, _set, ...props }) { ...${props} />`; extendProps($input, { onchange: () => _set?.($input.checked) }); - useState(["rerender"], () => { - _get?.().then((checked) => ($input.checked = checked)); + useState(["rerender"], async () => { + const checked = (await _get?.()) ?? $input.checked; + $input.checked = checked; }); return html`