diff --git a/com.pdma.notion-timer.sdPlugin/bin/plugin.js b/com.pdma.notion-timer.sdPlugin/bin/plugin.js index 40bbfa8..a2aa645 100644 --- a/com.pdma.notion-timer.sdPlugin/bin/plugin.js +++ b/com.pdma.notion-timer.sdPlugin/bin/plugin.js @@ -6438,7 +6438,7 @@ async function stopTimer(token, entryId) { } // src/plugin.ts -var CURRENT_VERSION = "1.0.39"; +var CURRENT_VERSION = "1.0.40"; var GITEA_BASE = "https://gitea.pdmarf.co.uk/pdm/stream_deck_notion_timer/raw/branch/stable-rebuild"; var SIGNING_PUBLIC_KEY = `-----BEGIN PUBLIC KEY----- MCowBQYDK2VwAyEAN7ko8TUpuPzPAJuKAZCRjV0c4ZSlou5d9pUAF6o12b4= @@ -6569,6 +6569,7 @@ function buttonTitle(projectName) { } var TimerToggle = class extends SingletonAction { projectCache = /* @__PURE__ */ new Map(); + pendingKeyDown = /* @__PURE__ */ new Set(); async onWillAppear(ev) { this.projectCache.set(ev.action.id, ev.payload.settings); const title = buttonTitle(ev.payload.settings.projectName || ""); @@ -6584,52 +6585,58 @@ var TimerToggle = class extends SingletonAction { await sendProjectsToPI(); } async onKeyDown(ev) { - const { projectId, projectName } = ev.payload.settings; - const title = buttonTitle(projectName || ""); - const isRunning = memRunningActionId === ev.action.id; - if (projectId) { - if (isRunning) { - await Promise.all([ev.action.setState(0), ev.action.setTitle(title)]); - } else { - for (const other of this.actions) { - if (other.id === ev.action.id) continue; - if (memRunningActionId === other.id) { - const s = this.projectCache.get(other.id); - await Promise.all([other.setState(0), other.setTitle(buttonTitle(s?.projectName || ""))]); - } - } - await Promise.all([ev.action.setState(1), ev.action.setTitle(`\u23F1 ${title}`)]); - } - } - const global = await getGlobal(); - if (!isConfigured(global)) { - await ev.action.showAlert(); - return; - } - if (!projectId) { - await ev.action.showAlert(); - return; - } + if (this.pendingKeyDown.has(ev.action.id)) return; + this.pendingKeyDown.add(ev.action.id); try { - if (isRunning) { - await stopTimer(global.notionToken, memRunningEntryId); - setRunningEntry(null, null); - await Promise.all([ev.action.setState(0), ev.action.setTitle(title)]); - } else { - if (memRunningEntryId) { - await stopTimer(global.notionToken, memRunningEntryId); + const { projectId, projectName } = ev.payload.settings; + const title = buttonTitle(projectName || ""); + const isRunning = memRunningActionId === ev.action.id; + if (projectId) { + if (isRunning) { + await Promise.all([ev.action.setState(0), ev.action.setTitle(title)]); + } else { + for (const other of this.actions) { + if (other.id === ev.action.id) continue; + if (memRunningActionId === other.id) { + const s = this.projectCache.get(other.id); + await Promise.all([other.setState(0), other.setTitle(buttonTitle(s?.projectName || ""))]); + } + } + await Promise.all([ev.action.setState(1), ev.action.setTitle(`\u23F1 ${title}`)]); } - const entryId = await startTimer(global.notionToken, global.timingDbId, projectId, projectName, global.userId); - setRunningEntry(entryId, ev.action.id); - await Promise.all([ev.action.setState(1), ev.action.setTitle(`\u23F1 ${title}`)]); } - } catch (err) { - await Promise.all([ - ev.action.setState(isRunning ? 1 : 0), - ev.action.setTitle(isRunning ? `\u23F1 ${title}` : title) - ]); - plugin_default.logger.error("Timer toggle failed:", err); - await ev.action.showAlert(); + const global = await getGlobal(); + if (!isConfigured(global)) { + await ev.action.showAlert(); + return; + } + if (!projectId) { + await ev.action.showAlert(); + return; + } + try { + if (isRunning) { + await stopTimer(global.notionToken, memRunningEntryId); + setRunningEntry(null, null); + await Promise.all([ev.action.setState(0), ev.action.setTitle(title)]); + } else { + if (memRunningEntryId) { + await stopTimer(global.notionToken, memRunningEntryId); + } + const entryId = await startTimer(global.notionToken, global.timingDbId, projectId, projectName, global.userId); + setRunningEntry(entryId, ev.action.id); + await Promise.all([ev.action.setState(1), ev.action.setTitle(`\u23F1 ${title}`)]); + } + } catch (err) { + await Promise.all([ + ev.action.setState(isRunning ? 1 : 0), + ev.action.setTitle(isRunning ? `\u23F1 ${title}` : title) + ]); + plugin_default.logger.error("Timer toggle failed:", err); + await ev.action.showAlert(); + } + } finally { + this.pendingKeyDown.delete(ev.action.id); } } }; diff --git a/com.pdma.notion-timer.sdPlugin/bin/plugin.js.sig b/com.pdma.notion-timer.sdPlugin/bin/plugin.js.sig index 6e5d5af..0af72e1 100644 --- a/com.pdma.notion-timer.sdPlugin/bin/plugin.js.sig +++ b/com.pdma.notion-timer.sdPlugin/bin/plugin.js.sig @@ -1 +1 @@ -×<·!ÿxR–Ú„óR£;=‹LI" Ѥ´HuÜF†ÙïÓ€¢… sbŽY¬{ÊH¶î.JÝNãØ1¥l \ No newline at end of file +{QÕ¿óîj¶? Íz_ÎDA+ÌOÎi ° { private projectCache = new Map(); + private pendingKeyDown = new Set(); async onWillAppear(ev: WillAppearEvent): Promise { this.projectCache.set(ev.action.id, ev.payload.settings); @@ -185,6 +186,9 @@ class TimerToggle extends SingletonAction { } async onKeyDown(ev: KeyDownEvent): Promise { + if (this.pendingKeyDown.has(ev.action.id)) return; + this.pendingKeyDown.add(ev.action.id); + try { const { projectId, projectName } = ev.payload.settings; const title = buttonTitle(projectName || ""); const isRunning = memRunningActionId === ev.action.id; @@ -231,6 +235,9 @@ class TimerToggle extends SingletonAction { streamDeck.logger.error("Timer toggle failed:", err); await ev.action.showAlert(); } + } finally { + this.pendingKeyDown.delete(ev.action.id); + } } }