diff --git a/com.pdma.notion-timer.sdPlugin/bin/plugin.js b/com.pdma.notion-timer.sdPlugin/bin/plugin.js index d772d8f..e6c3546 100644 --- a/com.pdma.notion-timer.sdPlugin/bin/plugin.js +++ b/com.pdma.notion-timer.sdPlugin/bin/plugin.js @@ -6438,7 +6438,7 @@ async function stopTimer(token, entryId) { } // src/plugin.ts -var CURRENT_VERSION = "1.0.26"; +var CURRENT_VERSION = "1.0.27"; 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= @@ -6518,6 +6518,27 @@ async function setRunningEntry(entryId) { const stored = await plugin_default.settings.getGlobalSettings(); await plugin_default.settings.setGlobalSettings({ ...stored, runningEntryId: entryId }); } +async function sendProjectsToPI(tokenOverride) { + try { + const global = await getGlobal(); + const token = tokenOverride ?? global.notionToken; + if (!token) { + await plugin_default.ui.sendToPropertyInspector({ event: "projects", data: [], error: "Enter your Notion API token above.", version: CURRENT_VERSION }); + return; + } + const [projects, usersResult] = await Promise.all([ + fetchProjects(token, global.projectsDbId), + fetchUsers(token).catch((err) => { + plugin_default.logger.error("Failed to fetch users:", err); + return []; + }) + ]); + await plugin_default.ui.sendToPropertyInspector({ event: "projects", data: projects, users: usersResult, version: CURRENT_VERSION }); + } catch (err) { + plugin_default.logger.error("Failed to fetch projects:", err); + await plugin_default.ui.sendToPropertyInspector({ event: "projects", data: [], error: String(err), version: CURRENT_VERSION }); + } +} function isConfigured(g) { return !!(g.notionToken && g.userId); } @@ -6545,25 +6566,8 @@ var TimerToggle = class extends SingletonAction { } } } - async onPropertyInspectorDidAppear(ev) { - try { - const global = await getGlobal(); - if (!global.notionToken) { - await plugin_default.ui.sendToPropertyInspector({ event: "projects", data: [], error: "Enter your Notion API token above.", version: CURRENT_VERSION }); - return; - } - const [projects, usersResult] = await Promise.all([ - fetchProjects(global.notionToken, global.projectsDbId), - fetchUsers(global.notionToken).catch((err) => { - plugin_default.logger.error("Failed to fetch users:", err); - return []; - }) - ]); - await plugin_default.ui.sendToPropertyInspector({ event: "projects", data: projects, users: usersResult, version: CURRENT_VERSION }); - } catch (err) { - plugin_default.logger.error("Failed to fetch projects:", err); - await plugin_default.ui.sendToPropertyInspector({ event: "projects", data: [], error: String(err), version: CURRENT_VERSION }); - } + async onPropertyInspectorDidAppear(_ev) { + await sendProjectsToPI(); } async onKeyDown(ev) { this.settingsCache.set(ev.action.id, ev.payload.settings); @@ -6640,6 +6644,9 @@ plugin_default.ui.onSendToPlugin(async (ev) => { const title = buttonTitle(ev.payload.settings.projectName || ""); if (title) await ev.action.setTitle(title); } + if (ev.payload.event === "refreshProjects") { + await sendProjectsToPI(ev.payload.token); + } if (ev.payload.event === "checkForUpdates") { const send = (msg) => plugin_default.ui.sendToPropertyInspector({ event: "updateStatus", message: msg }); send("Checking\u2026"); diff --git a/com.pdma.notion-timer.sdPlugin/bin/plugin.js.sig b/com.pdma.notion-timer.sdPlugin/bin/plugin.js.sig index 6d5f1bc..77fe0a5 100644 Binary files a/com.pdma.notion-timer.sdPlugin/bin/plugin.js.sig and b/com.pdma.notion-timer.sdPlugin/bin/plugin.js.sig differ diff --git a/com.pdma.notion-timer.sdPlugin/manifest.json b/com.pdma.notion-timer.sdPlugin/manifest.json index 8461c55..4f263ca 100644 --- a/com.pdma.notion-timer.sdPlugin/manifest.json +++ b/com.pdma.notion-timer.sdPlugin/manifest.json @@ -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.26", + "Version": "1.0.27", "SDKVersion": 2, "Software": { "MinimumVersion": "5.0" }, "OS": [{ "Platform": "mac", "MinimumVersion": "10.11" }], diff --git a/com.pdma.notion-timer.sdPlugin/ui/property-inspector.html b/com.pdma.notion-timer.sdPlugin/ui/property-inspector.html index 3d5de35..e355d1f 100644 --- a/com.pdma.notion-timer.sdPlugin/ui/property-inspector.html +++ b/com.pdma.notion-timer.sdPlugin/ui/property-inspector.html @@ -194,6 +194,10 @@ }; $PI.setGlobalSettings(creds); setCredStatus("Credentials saved.", "ok"); + if (creds.notionToken) { + setStatus("Loading…", ""); + $PI.sendToPlugin({ event: "refreshProjects", token: creds.notionToken }); + } } function populateUsers(users, savedUserId) { diff --git a/notion-timer.streamDeckPlugin b/notion-timer.streamDeckPlugin index 0956b61..7640265 100644 Binary files a/notion-timer.streamDeckPlugin and b/notion-timer.streamDeckPlugin differ diff --git a/src/plugin.ts b/src/plugin.ts index 025416b..baed658 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -1,4 +1,4 @@ -const CURRENT_VERSION = "1.0.26"; +const CURRENT_VERSION = "1.0.27"; 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= @@ -109,6 +109,28 @@ async function setRunningEntry(entryId: string | null): Promise { await streamDeck.settings.setGlobalSettings({ ...stored, runningEntryId: entryId }); } +async function sendProjectsToPI(tokenOverride?: string): Promise { + try { + const global = await getGlobal(); + const token = tokenOverride ?? global.notionToken; + if (!token) { + await streamDeck.ui.sendToPropertyInspector({ event: "projects", data: [], error: "Enter your Notion API token above.", version: CURRENT_VERSION }); + return; + } + const [projects, usersResult] = await Promise.all([ + fetchProjects(token, global.projectsDbId), + fetchUsers(token).catch((err) => { + streamDeck.logger.error("Failed to fetch users:", err); + return []; + }), + ]); + await streamDeck.ui.sendToPropertyInspector({ event: "projects", data: projects, users: usersResult, version: CURRENT_VERSION }); + } catch (err) { + streamDeck.logger.error("Failed to fetch projects:", err); + await streamDeck.ui.sendToPropertyInspector({ event: "projects", data: [], error: String(err), version: CURRENT_VERSION }); + } +} + function isConfigured(g: GlobalSettings): boolean { return !!(g.notionToken && g.userId); } @@ -146,25 +168,8 @@ class TimerToggle extends SingletonAction { } } - async onPropertyInspectorDidAppear(ev: PropertyInspectorDidAppearEvent): Promise { - try { - const global = await getGlobal(); - if (!global.notionToken) { - await streamDeck.ui.sendToPropertyInspector({ event: "projects", data: [], error: "Enter your Notion API token above.", version: CURRENT_VERSION }); - return; - } - const [projects, usersResult] = await Promise.all([ - fetchProjects(global.notionToken, global.projectsDbId), - fetchUsers(global.notionToken).catch((err) => { - streamDeck.logger.error("Failed to fetch users:", err); - return []; - }), - ]); - await streamDeck.ui.sendToPropertyInspector({ event: "projects", data: projects, users: usersResult, version: CURRENT_VERSION }); - } catch (err) { - streamDeck.logger.error("Failed to fetch projects:", err); - await streamDeck.ui.sendToPropertyInspector({ event: "projects", data: [], error: String(err), version: CURRENT_VERSION }); - } + async onPropertyInspectorDidAppear(_ev: PropertyInspectorDidAppearEvent): Promise { + await sendProjectsToPI(); } async onKeyDown(ev: KeyDownEvent): Promise { @@ -244,12 +249,15 @@ const timerAction = new TimerToggle(); streamDeck.actions.registerAction(timerAction); // v2 requires using streamDeck.ui.onSendToPlugin — the SingletonAction method does not fire -streamDeck.ui.onSendToPlugin<{ event: string; settings?: TimerSettings }>(async (ev) => { +streamDeck.ui.onSendToPlugin<{ event: string; settings?: TimerSettings; token?: string }>(async (ev) => { if (ev.payload.event === "saveSettings" && ev.payload.settings) { await ev.action.setSettings(ev.payload.settings); const title = buttonTitle(ev.payload.settings.projectName || ""); if (title) await ev.action.setTitle(title); } + if (ev.payload.event === "refreshProjects") { + await sendProjectsToPI(ev.payload.token); + } if (ev.payload.event === "checkForUpdates") { const send = (msg: string) => streamDeck.ui.sendToPropertyInspector({ event: "updateStatus", message: msg }); send("Checking…"); diff --git a/version.json b/version.json index f78be80..d984738 100644 --- a/version.json +++ b/version.json @@ -1 +1 @@ -{ "version": "1.0.26" } +{ "version": "1.0.27" }