v1.0.34: fix both buttons showing green simultaneously

When pressing B while A was running, B went green immediately but A
stayed green until getGlobal()+getRunningEntryId() resolved. Now uses
settingsCache to turn off all running buttons in the same synchronous
pass as turning B on — no async gap where both appear active.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
pdmarf
2026-04-24 09:07:55 +01:00
parent 2fd2b6ad8a
commit 93616d3a1a
6 changed files with 20 additions and 19 deletions

View File

@@ -1,4 +1,4 @@
const CURRENT_VERSION = "1.0.33";
const CURRENT_VERSION = "1.0.34";
const GITEA_BASE = "https://gitea.pdmarf.co.uk/pdm/stream_deck_notion_timer/raw/branch/stable-rebuild";
const SIGNING_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEAN7ko8TUpuPzPAJuKAZCRjV0c4ZSlou5d9pUAF6o12b4=
@@ -206,6 +206,14 @@ class TimerToggle extends SingletonAction<TimerSettings> {
if (activeEntryId) {
await Promise.all([ev.action.setState(0), ev.action.setTitle(title)]);
} else {
// Turn off any other running button immediately using the cache — no async needed
for (const other of this.actions) {
if (other.id === ev.action.id) continue;
const otherSettings = this.settingsCache.get(other.id);
if (otherSettings?.activeEntryId) {
await Promise.all([other.setState(0), other.setTitle(buttonTitle(otherSettings.projectName || ""))]);
}
}
await Promise.all([ev.action.setState(1), ev.action.setTitle(`${title}`)]);
}
}
@@ -233,15 +241,8 @@ class TimerToggle extends SingletonAction<TimerSettings> {
} else {
const prevEntryId = await getRunningEntryId();
// Turn off the previously running button immediately
// Stop previous timer and update its settings
if (prevEntryId) {
for (const other of this.actions) {
if (other.id === ev.action.id) continue;
const otherSettings = this.settingsCache.get(other.id);
if (otherSettings?.activeEntryId === prevEntryId) {
await Promise.all([other.setState(0), other.setTitle(buttonTitle(otherSettings.projectName || ""))]);
}
}
await stopTimer(global.notionToken, prevEntryId);
for (const other of this.actions) {
if (other.id === ev.action.id) continue;