diff --git a/com.pdma.notion-timer.sdPlugin/bin/plugin.js b/com.pdma.notion-timer.sdPlugin/bin/plugin.js index cba0308..95dbf08 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.21"; +var CURRENT_VERSION = "1.0.22"; var GITEA_BASE = "https://gitea.pdmarf.co.uk/pdm/stream_deck_notion_timer/raw/branch/master"; var SIGNING_PUBLIC_KEY = `-----BEGIN PUBLIC KEY----- MCowBQYDK2VwAyEAN7ko8TUpuPzPAJuKAZCRjV0c4ZSlou5d9pUAF6o12b4= @@ -6546,6 +6546,31 @@ async function setRunningEntry(entryId) { const stored = await plugin_default.settings.getGlobalSettings(); await plugin_default.settings.setGlobalSettings({ ...stored, runningEntryId: entryId }); } +async function sendProjectsToPI(overrideToken) { + try { + const global = await getGlobal(); + const token = overrideToken || global.notionToken; + if (!token) { + await plugin_default.ui.sendToPropertyInspector({ event: "projects", data: [], error: "Enter your Notion API token above.", version: CURRENT_VERSION }); + return; + } + let usersResult = []; + let usersError; + const [projects] = await Promise.all([ + fetchProjects(token, global.projectsDbId), + fetchUsers(token).then((u) => { + usersResult = u; + }).catch((err) => { + plugin_default.logger.error("Failed to fetch users:", err); + usersError = err instanceof Error ? err.message : String(err); + }) + ]); + await plugin_default.ui.sendToPropertyInspector({ event: "projects", data: projects, users: usersResult, usersError, 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); } @@ -6573,29 +6598,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; - } - let usersResult = []; - let usersError; - const [projects] = await Promise.all([ - fetchProjects(global.notionToken, global.projectsDbId), - fetchUsers(global.notionToken).then((u) => { - usersResult = u; - }).catch((err) => { - plugin_default.logger.error("Failed to fetch users:", err); - usersError = err instanceof Error ? err.message : String(err); - }) - ]); - await plugin_default.ui.sendToPropertyInspector({ event: "projects", data: projects, users: usersResult, usersError, 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); @@ -6666,6 +6670,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 === "refresh") { + await sendProjectsToPI(ev.payload.notionToken); + } 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 17e850a..73daef0 100644 --- a/com.pdma.notion-timer.sdPlugin/bin/plugin.js.sig +++ b/com.pdma.notion-timer.sdPlugin/bin/plugin.js.sig @@ -1 +1 @@ -_4/leV&BU1jl3{#̲Zd7_eNn's;9JL6 \ No newline at end of file +!arR,{xJ0Sѕcu1<5K(a/Ǩ6g omNKt \ No newline at end of file diff --git a/com.pdma.notion-timer.sdPlugin/ui/property-inspector.html b/com.pdma.notion-timer.sdPlugin/ui/property-inspector.html index 639a739..a1eea66 100644 --- a/com.pdma.notion-timer.sdPlugin/ui/property-inspector.html +++ b/com.pdma.notion-timer.sdPlugin/ui/property-inspector.html @@ -195,6 +195,9 @@ }; $PI.setGlobalSettings(creds); setCredStatus("Credentials saved.", "ok"); + if (creds.notionToken) { + $PI.sendToPlugin({ event: "refresh", notionToken: creds.notionToken }); + } } function populateUsers(users, savedUserId) { diff --git a/notion-timer.streamDeckPlugin b/notion-timer.streamDeckPlugin index d9c9d88..ece814b 100644 Binary files a/notion-timer.streamDeckPlugin and b/notion-timer.streamDeckPlugin differ diff --git a/src/plugin.ts b/src/plugin.ts index df31b94..ba40d94 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -1,4 +1,4 @@ -const CURRENT_VERSION = "1.0.21"; +const CURRENT_VERSION = "1.0.22"; const GITEA_BASE = "https://gitea.pdmarf.co.uk/pdm/stream_deck_notion_timer/raw/branch/master"; const SIGNING_PUBLIC_KEY = `-----BEGIN PUBLIC KEY----- MCowBQYDK2VwAyEAN7ko8TUpuPzPAJuKAZCRjV0c4ZSlou5d9pUAF6o12b4= @@ -139,6 +139,30 @@ async function setRunningEntry(entryId: string | null): Promise { await streamDeck.settings.setGlobalSettings({ ...stored, runningEntryId: entryId }); } +async function sendProjectsToPI(overrideToken?: string): Promise { + try { + const global = await getGlobal(); + const token = overrideToken || global.notionToken; + if (!token) { + await streamDeck.ui.sendToPropertyInspector({ event: "projects", data: [], error: "Enter your Notion API token above.", version: CURRENT_VERSION }); + return; + } + let usersResult: Awaited> = []; + let usersError: string | undefined; + const [projects] = await Promise.all([ + fetchProjects(token, global.projectsDbId), + fetchUsers(token).then((u) => { usersResult = u; }).catch((err) => { + streamDeck.logger.error("Failed to fetch users:", err); + usersError = err instanceof Error ? err.message : String(err); + }), + ]); + await streamDeck.ui.sendToPropertyInspector({ event: "projects", data: projects, users: usersResult, usersError, 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); } @@ -176,27 +200,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; - } - let usersResult: Awaited> = []; - let usersError: string | undefined; - const [projects] = await Promise.all([ - fetchProjects(global.notionToken, global.projectsDbId), - fetchUsers(global.notionToken).then((u) => { usersResult = u; }).catch((err) => { - streamDeck.logger.error("Failed to fetch users:", err); - usersError = err instanceof Error ? err.message : String(err); - }), - ]); - await streamDeck.ui.sendToPropertyInspector({ event: "projects", data: projects, users: usersResult, usersError, 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 { @@ -274,6 +279,9 @@ streamDeck.ui.onSendToPlugin<{ event: string; settings?: TimerSettings }>(async const title = buttonTitle(ev.payload.settings.projectName || ""); if (title) await ev.action.setTitle(title); } + if (ev.payload.event === "refresh") { + await sendProjectsToPI(ev.payload.notionToken as string | undefined); + } 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 785c591..f7bc7e1 100644 --- a/version.json +++ b/version.json @@ -1 +1 @@ -{ "version": "1.0.21" } +{ "version": "1.0.22" }