v1.0.39: fix button flash by making setRunningEntry synchronous

Remove await from running-state updates so onWillAppear cannot
fire between the optimistic setState(1) and the API call completing,
eliminating the green→blue→green flash on button press.
This commit is contained in:
pdmarf
2026-04-24 09:29:43 +01:00
parent 4171b2f6e9
commit 060a2bc917
5 changed files with 20 additions and 16 deletions

View File

@@ -6438,7 +6438,7 @@ async function stopTimer(token, entryId) {
} }
// src/plugin.ts // src/plugin.ts
var CURRENT_VERSION = "1.0.38"; var CURRENT_VERSION = "1.0.39";
var GITEA_BASE = "https://gitea.pdmarf.co.uk/pdm/stream_deck_notion_timer/raw/branch/stable-rebuild"; var GITEA_BASE = "https://gitea.pdmarf.co.uk/pdm/stream_deck_notion_timer/raw/branch/stable-rebuild";
var SIGNING_PUBLIC_KEY = `-----BEGIN PUBLIC KEY----- var SIGNING_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEAN7ko8TUpuPzPAJuKAZCRjV0c4ZSlou5d9pUAF6o12b4= MCowBQYDK2VwAyEAN7ko8TUpuPzPAJuKAZCRjV0c4ZSlou5d9pUAF6o12b4=
@@ -6535,11 +6535,10 @@ async function loadRunningState() {
memRunningEntryId = stored.runningEntryId ?? null; memRunningEntryId = stored.runningEntryId ?? null;
memRunningActionId = stored.runningActionId ?? null; memRunningActionId = stored.runningActionId ?? null;
} }
async function setRunningEntry(entryId, actionId) { function setRunningEntry(entryId, actionId) {
memRunningEntryId = entryId; memRunningEntryId = entryId;
memRunningActionId = actionId; memRunningActionId = actionId;
const stored = await plugin_default.settings.getGlobalSettings(); plugin_default.settings.getGlobalSettings().then((stored) => plugin_default.settings.setGlobalSettings({ ...stored, runningEntryId: entryId, runningActionId: actionId })).catch((err) => plugin_default.logger.error("Failed to persist running state:", err));
await plugin_default.settings.setGlobalSettings({ ...stored, runningEntryId: entryId, runningActionId: actionId });
} }
async function sendProjectsToPI(tokenOverride) { async function sendProjectsToPI(tokenOverride) {
try { try {
@@ -6614,13 +6613,15 @@ var TimerToggle = class extends SingletonAction {
try { try {
if (isRunning) { if (isRunning) {
await stopTimer(global.notionToken, memRunningEntryId); await stopTimer(global.notionToken, memRunningEntryId);
await setRunningEntry(null, null); setRunningEntry(null, null);
await Promise.all([ev.action.setState(0), ev.action.setTitle(title)]);
} else { } else {
if (memRunningEntryId) { if (memRunningEntryId) {
await stopTimer(global.notionToken, memRunningEntryId); await stopTimer(global.notionToken, memRunningEntryId);
} }
const entryId = await startTimer(global.notionToken, global.timingDbId, projectId, projectName, global.userId); const entryId = await startTimer(global.notionToken, global.timingDbId, projectId, projectName, global.userId);
await setRunningEntry(entryId, ev.action.id); setRunningEntry(entryId, ev.action.id);
await Promise.all([ev.action.setState(1), ev.action.setTitle(`\u23F1 ${title}`)]);
} }
} catch (err) { } catch (err) {
await Promise.all([ await Promise.all([

View File

@@ -1,2 +1 @@
Κ¤<06>C¤•Sί¤ в<╥!Ъ░xR√з└С;=▀LI" я╓╢HuэF├ы▐Ос─╒┘ sb▌Y╛{йH│╤Н.JщNЦь1╔l
Φ®Έ}•~P }ηΜ<>Z;·ΆxΤη{,¦NYPπu4#ΑΚ„jα§ΎWCκΈ©σΔ «Έ<0E>d

View File

@@ -2,7 +2,7 @@
"Author": "Pete Marfleet", "Author": "Pete Marfleet",
"Description": "Toggle Notion time tracking for a project with a single button press.", "Description": "Toggle Notion time tracking for a project with a single button press.",
"Name": "Notion Timer", "Name": "Notion Timer",
"Version": "1.0.38", "Version": "1.0.39",
"SDKVersion": 2, "SDKVersion": 2,
"Software": { "MinimumVersion": "5.0" }, "Software": { "MinimumVersion": "5.0" },
"OS": [{ "Platform": "mac", "MinimumVersion": "10.11" }], "OS": [{ "Platform": "mac", "MinimumVersion": "10.11" }],

View File

@@ -1,4 +1,4 @@
const CURRENT_VERSION = "1.0.38"; const CURRENT_VERSION = "1.0.39";
const GITEA_BASE = "https://gitea.pdmarf.co.uk/pdm/stream_deck_notion_timer/raw/branch/stable-rebuild"; const GITEA_BASE = "https://gitea.pdmarf.co.uk/pdm/stream_deck_notion_timer/raw/branch/stable-rebuild";
const SIGNING_PUBLIC_KEY = `-----BEGIN PUBLIC KEY----- const SIGNING_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEAN7ko8TUpuPzPAJuKAZCRjV0c4ZSlou5d9pUAF6o12b4= MCowBQYDK2VwAyEAN7ko8TUpuPzPAJuKAZCRjV0c4ZSlou5d9pUAF6o12b4=
@@ -125,11 +125,13 @@ async function loadRunningState(): Promise<void> {
memRunningActionId = stored.runningActionId ?? null; memRunningActionId = stored.runningActionId ?? null;
} }
async function setRunningEntry(entryId: string | null, actionId: string | null): Promise<void> { function setRunningEntry(entryId: string | null, actionId: string | null): void {
memRunningEntryId = entryId; memRunningEntryId = entryId;
memRunningActionId = actionId; memRunningActionId = actionId;
const stored = await streamDeck.settings.getGlobalSettings<GlobalSettings>(); // Persist in background — do not await, so the visual is never blocked
await streamDeck.settings.setGlobalSettings({ ...stored, runningEntryId: entryId, runningActionId: actionId }); streamDeck.settings.getGlobalSettings<GlobalSettings>()
.then(stored => streamDeck.settings.setGlobalSettings({ ...stored, runningEntryId: entryId, runningActionId: actionId }))
.catch(err => streamDeck.logger.error("Failed to persist running state:", err));
} }
async function sendProjectsToPI(tokenOverride?: string): Promise<void> { async function sendProjectsToPI(tokenOverride?: string): Promise<void> {
@@ -210,13 +212,15 @@ class TimerToggle extends SingletonAction<TimerSettings> {
try { try {
if (isRunning) { if (isRunning) {
await stopTimer(global.notionToken, memRunningEntryId!); await stopTimer(global.notionToken, memRunningEntryId!);
await setRunningEntry(null, null); setRunningEntry(null, null);
await Promise.all([ev.action.setState(0), ev.action.setTitle(title)]);
} else { } else {
if (memRunningEntryId) { if (memRunningEntryId) {
await stopTimer(global.notionToken, memRunningEntryId); await stopTimer(global.notionToken, memRunningEntryId);
} }
const entryId = await startTimer(global.notionToken, global.timingDbId, projectId, projectName, global.userId); const entryId = await startTimer(global.notionToken, global.timingDbId, projectId, projectName, global.userId);
await setRunningEntry(entryId, ev.action.id); setRunningEntry(entryId, ev.action.id);
await Promise.all([ev.action.setState(1), ev.action.setTitle(`${title}`)]);
} }
} catch (err) { } catch (err) {
// Revert visual on error // Revert visual on error

View File

@@ -1 +1 @@
{ "version": "1.0.38" } { "version": "1.0.39" }