v1.0.26: eliminate double-green flash when switching timers
Both buttons now flip to their final visual state immediately on key press, before any API calls. Previously the old button stayed green throughout the stopTimer network round-trip (~0.5–2s), causing a window where both buttons appeared green simultaneously. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const CURRENT_VERSION = "1.0.25";
|
||||
const CURRENT_VERSION = "1.0.26";
|
||||
const GITEA_BASE = "https://gitea.pdmarf.co.uk/pdm/stream_deck_notion_timer/raw/branch/master";
|
||||
const SIGNING_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
|
||||
MCowBQYDK2VwAyEAN7ko8TUpuPzPAJuKAZCRjV0c4ZSlou5d9pUAF6o12b4=
|
||||
@@ -195,7 +195,19 @@ class TimerToggle extends SingletonAction<TimerSettings> {
|
||||
} else {
|
||||
const prevEntryId = await getRunningEntryId();
|
||||
|
||||
// Stop previous timer
|
||||
// Optimistically update visuals immediately — no waiting for API
|
||||
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 Promise.all([ev.action.setState(1), ev.action.setTitle(`⏱ ${title}`)]);
|
||||
|
||||
// Now do the API calls
|
||||
if (prevEntryId) {
|
||||
await stopTimer(global.notionToken, prevEntryId);
|
||||
for (const other of this.actions) {
|
||||
@@ -205,8 +217,6 @@ class TimerToggle extends SingletonAction<TimerSettings> {
|
||||
const stopped = { ...otherSettings, activeEntryId: null };
|
||||
await other.setSettings(stopped);
|
||||
this.settingsCache.set(other.id, stopped);
|
||||
await other.setState(0);
|
||||
await other.setTitle(buttonTitle(otherSettings.projectName || ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -222,8 +232,6 @@ class TimerToggle extends SingletonAction<TimerSettings> {
|
||||
await ev.action.setSettings(started);
|
||||
this.settingsCache.set(ev.action.id, started);
|
||||
await setRunningEntry(entryId);
|
||||
await ev.action.setState(1);
|
||||
await ev.action.setTitle(`⏱ ${title}`);
|
||||
}
|
||||
} catch (err) {
|
||||
streamDeck.logger.error("Timer toggle failed:", err);
|
||||
|
||||
Reference in New Issue
Block a user