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:
@@ -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 SIGNING_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
|
||||
MCowBQYDK2VwAyEAN7ko8TUpuPzPAJuKAZCRjV0c4ZSlou5d9pUAF6o12b4=
|
||||
@@ -125,11 +125,13 @@ async function loadRunningState(): Promise<void> {
|
||||
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;
|
||||
memRunningActionId = actionId;
|
||||
const stored = await streamDeck.settings.getGlobalSettings<GlobalSettings>();
|
||||
await streamDeck.settings.setGlobalSettings({ ...stored, runningEntryId: entryId, runningActionId: actionId });
|
||||
// Persist in background — do not await, so the visual is never blocked
|
||||
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> {
|
||||
@@ -210,13 +212,15 @@ class TimerToggle extends SingletonAction<TimerSettings> {
|
||||
try {
|
||||
if (isRunning) {
|
||||
await stopTimer(global.notionToken, memRunningEntryId!);
|
||||
await setRunningEntry(null, null);
|
||||
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);
|
||||
await setRunningEntry(entryId, ev.action.id);
|
||||
setRunningEntry(entryId, ev.action.id);
|
||||
await Promise.all([ev.action.setState(1), ev.action.setTitle(`⏱ ${title}`)]);
|
||||
}
|
||||
} catch (err) {
|
||||
// Revert visual on error
|
||||
|
||||
Reference in New Issue
Block a user