v1.0.38: eliminate setSettings from onKeyDown to fix flash
setSettings always resets the button visual state — no workaround exists. Removed activeEntryId from per-button settings entirely. Running state now tracked via runningActionId in global settings (alongside runningEntryId). onWillAppear restores state from memRunningActionId. onKeyDown only calls setState — clean, instant. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -6438,7 +6438,7 @@ async function stopTimer(token, entryId) {
|
||||
}
|
||||
|
||||
// src/plugin.ts
|
||||
var CURRENT_VERSION = "1.0.37";
|
||||
var CURRENT_VERSION = "1.0.38";
|
||||
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=
|
||||
@@ -6528,17 +6528,18 @@ async function getGlobal() {
|
||||
return { ...stored, ...HARDCODED };
|
||||
}
|
||||
var memRunningEntryId = void 0;
|
||||
async function getRunningEntryId() {
|
||||
if (memRunningEntryId === void 0) {
|
||||
const stored = await plugin_default.settings.getGlobalSettings();
|
||||
memRunningEntryId = stored.runningEntryId ?? null;
|
||||
}
|
||||
return memRunningEntryId;
|
||||
}
|
||||
async function setRunningEntry(entryId) {
|
||||
memRunningEntryId = entryId;
|
||||
var memRunningActionId = void 0;
|
||||
async function loadRunningState() {
|
||||
if (memRunningEntryId !== void 0) return;
|
||||
const stored = await plugin_default.settings.getGlobalSettings();
|
||||
await plugin_default.settings.setGlobalSettings({ ...stored, runningEntryId: entryId });
|
||||
memRunningEntryId = stored.runningEntryId ?? null;
|
||||
memRunningActionId = stored.runningActionId ?? null;
|
||||
}
|
||||
async function setRunningEntry(entryId, actionId) {
|
||||
memRunningEntryId = entryId;
|
||||
memRunningActionId = actionId;
|
||||
const stored = await plugin_default.settings.getGlobalSettings();
|
||||
await plugin_default.settings.setGlobalSettings({ ...stored, runningEntryId: entryId, runningActionId: actionId });
|
||||
}
|
||||
async function sendProjectsToPI(tokenOverride) {
|
||||
try {
|
||||
@@ -6568,42 +6569,34 @@ function buttonTitle(projectName) {
|
||||
return projectName.replace(/^[\p{Extended_Pictographic}\uFE0F\s]+/u, "").trim();
|
||||
}
|
||||
var TimerToggle = class extends SingletonAction {
|
||||
settingsCache = /* @__PURE__ */ new Map();
|
||||
projectCache = /* @__PURE__ */ new Map();
|
||||
async onWillAppear(ev) {
|
||||
const { activeEntryId, projectName } = ev.payload.settings;
|
||||
const title = buttonTitle(projectName || "");
|
||||
const running = await getRunningEntryId();
|
||||
const isRunning = !!activeEntryId && activeEntryId === running;
|
||||
if (activeEntryId && !isRunning) {
|
||||
const cleared = { ...ev.payload.settings, activeEntryId: null };
|
||||
await ev.action.setSettings(cleared);
|
||||
this.settingsCache.set(ev.action.id, cleared);
|
||||
await Promise.all([ev.action.setState(0), ev.action.setTitle(title)]);
|
||||
this.projectCache.set(ev.action.id, ev.payload.settings);
|
||||
const title = buttonTitle(ev.payload.settings.projectName || "");
|
||||
await loadRunningState();
|
||||
const isRunning = memRunningActionId === ev.action.id;
|
||||
if (isRunning) {
|
||||
await Promise.all([ev.action.setState(1), ev.action.setTitle(`\u23F1 ${title}`)]);
|
||||
} else {
|
||||
this.settingsCache.set(ev.action.id, ev.payload.settings);
|
||||
if (isRunning) {
|
||||
await Promise.all([ev.action.setState(1), ev.action.setTitle(`\u23F1 ${title}`)]);
|
||||
} else {
|
||||
await Promise.all([ev.action.setState(0), ev.action.setTitle(title)]);
|
||||
}
|
||||
await Promise.all([ev.action.setState(0), ev.action.setTitle(title)]);
|
||||
}
|
||||
}
|
||||
async onPropertyInspectorDidAppear(_ev) {
|
||||
await sendProjectsToPI();
|
||||
}
|
||||
async onKeyDown(ev) {
|
||||
this.settingsCache.set(ev.action.id, ev.payload.settings);
|
||||
const { projectId, projectName, activeEntryId } = ev.payload.settings;
|
||||
const { projectId, projectName } = ev.payload.settings;
|
||||
const title = buttonTitle(projectName || "");
|
||||
const isRunning = memRunningActionId === ev.action.id;
|
||||
if (projectId) {
|
||||
if (activeEntryId) {
|
||||
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;
|
||||
const otherSettings = this.settingsCache.get(other.id);
|
||||
if (otherSettings?.activeEntryId) {
|
||||
await Promise.all([other.setState(0), other.setTitle(buttonTitle(otherSettings.projectName || ""))]);
|
||||
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}`)]);
|
||||
@@ -6611,7 +6604,6 @@ var TimerToggle = class extends SingletonAction {
|
||||
}
|
||||
const global = await getGlobal();
|
||||
if (!isConfigured(global)) {
|
||||
await Promise.all([ev.action.setState(activeEntryId ? 1 : 0), ev.action.setTitle(activeEntryId ? `\u23F1 ${title}` : title)]);
|
||||
await ev.action.showAlert();
|
||||
return;
|
||||
}
|
||||
@@ -6620,40 +6612,21 @@ var TimerToggle = class extends SingletonAction {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (activeEntryId) {
|
||||
await stopTimer(global.notionToken, activeEntryId);
|
||||
const stopped = { ...ev.payload.settings, activeEntryId: null };
|
||||
this.settingsCache.set(ev.action.id, stopped);
|
||||
await Promise.all([ev.action.setSettings(stopped), ev.action.setState(0), ev.action.setTitle(title)]);
|
||||
await setRunningEntry(null);
|
||||
if (isRunning) {
|
||||
await stopTimer(global.notionToken, memRunningEntryId);
|
||||
await setRunningEntry(null, null);
|
||||
} else {
|
||||
const prevEntryId = await getRunningEntryId();
|
||||
if (prevEntryId) {
|
||||
await stopTimer(global.notionToken, 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) {
|
||||
const stopped = { ...otherSettings, activeEntryId: null };
|
||||
this.settingsCache.set(other.id, stopped);
|
||||
await Promise.all([other.setSettings(stopped), other.setState(0), other.setTitle(buttonTitle(otherSettings.projectName || ""))]);
|
||||
}
|
||||
}
|
||||
if (memRunningEntryId) {
|
||||
await stopTimer(global.notionToken, memRunningEntryId);
|
||||
}
|
||||
const entryId = await startTimer(
|
||||
global.notionToken,
|
||||
global.timingDbId,
|
||||
projectId,
|
||||
projectName,
|
||||
global.userId
|
||||
);
|
||||
const started = { ...ev.payload.settings, activeEntryId: entryId };
|
||||
this.settingsCache.set(ev.action.id, started);
|
||||
await Promise.all([ev.action.setSettings(started), ev.action.setState(1), ev.action.setTitle(`\u23F1 ${title}`)]);
|
||||
await setRunningEntry(entryId);
|
||||
const entryId = await startTimer(global.notionToken, global.timingDbId, projectId, projectName, global.userId);
|
||||
await setRunningEntry(entryId, ev.action.id);
|
||||
}
|
||||
} catch (err) {
|
||||
await Promise.all([ev.action.setState(activeEntryId ? 1 : 0), ev.action.setTitle(activeEntryId ? `\u23F1 ${title}` : title)]);
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
<EFBFBD>¹È©Ô<EFBFBD>u1ÀïÖB!ª£½I- bhݵ ä±Gr7L†]x~cá…»d³X Þ¹×y¯9<>B/£ž/
|
||||
Κ¤<06>C¤•Sί¤
|
||||
Φ®Έ}•~P}ηΜ<>Z;·ΆxΤη{,¦NYPπu4#ΑΚ„jα§ΎWCκΈ©σΔ«Έ<0E>d
|
||||
@@ -2,7 +2,7 @@
|
||||
"Author": "Pete Marfleet",
|
||||
"Description": "Toggle Notion time tracking for a project with a single button press.",
|
||||
"Name": "Notion Timer",
|
||||
"Version": "1.0.37",
|
||||
"Version": "1.0.38",
|
||||
"SDKVersion": 2,
|
||||
"Software": { "MinimumVersion": "5.0" },
|
||||
"OS": [{ "Platform": "mac", "MinimumVersion": "10.11" }],
|
||||
|
||||
Reference in New Issue
Block a user