From 23834475c0c9c34fb7da48948efe8e1bff4c90e7 Mon Sep 17 00:00:00 2001 From: dragonwocky Date: Thu, 19 Jan 2023 20:14:51 +1100 Subject: [PATCH] feat(menu): hotswapped profiles w/out reload --- src/api/mods.js | 2 +- src/core/menu/components.mjs | 28 +++++------ src/core/menu/menu.mjs | 90 ++++++++++++++++++++---------------- src/core/menu/state.mjs | 16 ++++++- 4 files changed, 78 insertions(+), 58 deletions(-) diff --git a/src/api/mods.js b/src/api/mods.js index 9e1c2c4..8434a91 100644 --- a/src/api/mods.js +++ b/src/api/mods.js @@ -39,7 +39,7 @@ const getProfile = async () => { const { initDatabase } = globalThis.__enhancerApi, db = initDatabase(); let activeProfile = await db.get("activeProfile"); - activeProfile ??= await db.get("profileIds")?.[0]; + activeProfile ??= (await db.get("profileIds"))?.[0]; return activeProfile ?? "default"; }, isEnabled = async (id) => { diff --git a/src/core/menu/components.mjs b/src/core/menu/components.mjs index 00fa862..8134eb5 100644 --- a/src/core/menu/components.mjs +++ b/src/core/menu/components.mjs @@ -21,7 +21,7 @@ function _Button( class="flex gap-[8px] items-center px-[12px] shrink-0 rounded-[4px] ${size === "sm" ? "h-[28px]" : "h-[32px]"} transition duration-[20ms] ${primary - ? `text-[color:var(--theme--accent-primary_contrast)] + ? `text-[color:var(--theme--accent-primary\\_contrast)] font-medium bg-[color:var(--theme--accent-primary)] hover:bg-[color:var(--theme--accent-primary\\_hover)]` : `border-(& [color:var(--theme--fg-border)]) @@ -776,8 +776,8 @@ function Profile({ setName, isActive, setActive, - exportData, - importData, + exportJson, + importJson, ...props }) { const { html } = globalThis.__enhancerApi, @@ -785,12 +785,8 @@ function Profile({ const file = event.target.files[0], reader = new FileReader(); reader.onload = async (progress) => { - try { - const res = JSON.parse(progress.currentTarget.result); - importData(res); - } catch { - // throw error - } + const res = progress.currentTarget.result; + importJson(res); }; reader.readAsText(file); }, @@ -807,8 +803,8 @@ function Profile({ const $a = html`