From 95483f4f254d5a73ad84c0e01afd7dc011b6673a Mon Sep 17 00:00:00 2001 From: dragonwocky Date: Sun, 6 Aug 2023 23:57:37 +1000 Subject: [PATCH] fix: wait for api b4 hooking into state --- src/core/islands/Panel.mjs | 2 +- src/core/menu/menu.mjs | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/core/islands/Panel.mjs b/src/core/islands/Panel.mjs index 8742021..0500469 100644 --- a/src/core/islands/Panel.mjs +++ b/src/core/islands/Panel.mjs @@ -87,11 +87,11 @@ function Panel({ $panel.resize(preDragWidth + (dragStartX - event.clientX)); }, endDrag = (event) => { - userDragActive = false; document.removeEventListener("mousemove", onDrag); document.removeEventListener("mouseup", endDrag); $panel.resize(preDragWidth + (dragStartX - event.clientX)); $panel.style.transitionDuration = ""; + requestIdleCallback(() => (userDragActive = false)); }; $resizeHandle.addEventListener("mousedown", startDrag); diff --git a/src/core/menu/menu.mjs b/src/core/menu/menu.mjs index bd360c0..bc337b1 100644 --- a/src/core/menu/menu.mjs +++ b/src/core/menu/menu.mjs @@ -16,11 +16,10 @@ import { Mod } from "./islands/Mod.mjs"; import { Options } from "./islands/Options.mjs"; import { Profiles } from "./islands/Profiles.mjs"; -let _apiImported = false, - _renderStarted = false, - _stateHookedInto = false, - _hotkeyRegistered = false; - +let _apiImport, // + _renderStarted, + _stateHookedInto, + _hotkeyRegistered; const categories = [ { icon: "palette", @@ -180,12 +179,12 @@ const renderMenu = async () => { if (theme === "light") document.body.classList.remove("dark"); }; -const importApi = async () => { - if (_apiImported) return; - _apiImported = true; - const api = globalThis.__enhancerApi; - if (typeof api === "undefined") await import("../../shared/system.js"); - await import("../../load.mjs").then((i) => i.default); +const importApi = () => { + return (_apiImport ??= (async () => { + const api = globalThis.__enhancerApi; + if (typeof api === "undefined") await import("../../shared/system.js"); + await import("../../load.mjs").then((i) => i.default); + })()); }, hookIntoState = () => { if (_stateHookedInto) return;