v1.0.27: auto-load projects/users after API token is entered

Previously staff had to close and reopen the property inspector
after entering their token to trigger the fetch. Now saving the
token immediately sends a refreshProjects event to the plugin,
which fetches and returns the project list and name dropdown.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
pdmarf
2026-04-24 08:43:12 +01:00
parent 034c951d9b
commit 5426a388ba
7 changed files with 62 additions and 43 deletions

View File

@@ -6438,7 +6438,7 @@ async function stopTimer(token, entryId) {
} }
// src/plugin.ts // 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 GITEA_BASE = "https://gitea.pdmarf.co.uk/pdm/stream_deck_notion_timer/raw/branch/stable-rebuild";
var SIGNING_PUBLIC_KEY = `-----BEGIN PUBLIC KEY----- var SIGNING_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEAN7ko8TUpuPzPAJuKAZCRjV0c4ZSlou5d9pUAF6o12b4= MCowBQYDK2VwAyEAN7ko8TUpuPzPAJuKAZCRjV0c4ZSlou5d9pUAF6o12b4=
@@ -6518,6 +6518,27 @@ async function setRunningEntry(entryId) {
const stored = await plugin_default.settings.getGlobalSettings(); const stored = await plugin_default.settings.getGlobalSettings();
await plugin_default.settings.setGlobalSettings({ ...stored, runningEntryId: entryId }); 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) { function isConfigured(g) {
return !!(g.notionToken && g.userId); return !!(g.notionToken && g.userId);
} }
@@ -6545,25 +6566,8 @@ var TimerToggle = class extends SingletonAction {
} }
} }
} }
async onPropertyInspectorDidAppear(ev) { async onPropertyInspectorDidAppear(_ev) {
try { await sendProjectsToPI();
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 onKeyDown(ev) { async onKeyDown(ev) {
this.settingsCache.set(ev.action.id, ev.payload.settings); 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 || ""); const title = buttonTitle(ev.payload.settings.projectName || "");
if (title) await ev.action.setTitle(title); if (title) await ev.action.setTitle(title);
} }
if (ev.payload.event === "refreshProjects") {
await sendProjectsToPI(ev.payload.token);
}
if (ev.payload.event === "checkForUpdates") { if (ev.payload.event === "checkForUpdates") {
const send = (msg) => plugin_default.ui.sendToPropertyInspector({ event: "updateStatus", message: msg }); const send = (msg) => plugin_default.ui.sendToPropertyInspector({ event: "updateStatus", message: msg });
send("Checking\u2026"); send("Checking\u2026");

View File

@@ -2,7 +2,7 @@
"Author": "Pete Marfleet", "Author": "Pete Marfleet",
"Description": "Toggle Notion time tracking for a project with a single button press.", "Description": "Toggle Notion time tracking for a project with a single button press.",
"Name": "Notion Timer", "Name": "Notion Timer",
"Version": "1.0.26", "Version": "1.0.27",
"SDKVersion": 2, "SDKVersion": 2,
"Software": { "MinimumVersion": "5.0" }, "Software": { "MinimumVersion": "5.0" },
"OS": [{ "Platform": "mac", "MinimumVersion": "10.11" }], "OS": [{ "Platform": "mac", "MinimumVersion": "10.11" }],

View File

@@ -194,6 +194,10 @@
}; };
$PI.setGlobalSettings(creds); $PI.setGlobalSettings(creds);
setCredStatus("Credentials saved.", "ok"); setCredStatus("Credentials saved.", "ok");
if (creds.notionToken) {
setStatus("Loading…", "");
$PI.sendToPlugin({ event: "refreshProjects", token: creds.notionToken });
}
} }
function populateUsers(users, savedUserId) { function populateUsers(users, savedUserId) {

Binary file not shown.

View File

@@ -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 GITEA_BASE = "https://gitea.pdmarf.co.uk/pdm/stream_deck_notion_timer/raw/branch/stable-rebuild";
const SIGNING_PUBLIC_KEY = `-----BEGIN PUBLIC KEY----- const SIGNING_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEAN7ko8TUpuPzPAJuKAZCRjV0c4ZSlou5d9pUAF6o12b4= MCowBQYDK2VwAyEAN7ko8TUpuPzPAJuKAZCRjV0c4ZSlou5d9pUAF6o12b4=
@@ -109,6 +109,28 @@ async function setRunningEntry(entryId: string | null): Promise<void> {
await streamDeck.settings.setGlobalSettings({ ...stored, runningEntryId: entryId }); await streamDeck.settings.setGlobalSettings({ ...stored, runningEntryId: entryId });
} }
async function sendProjectsToPI(tokenOverride?: string): Promise<void> {
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 { function isConfigured(g: GlobalSettings): boolean {
return !!(g.notionToken && g.userId); return !!(g.notionToken && g.userId);
} }
@@ -146,25 +168,8 @@ class TimerToggle extends SingletonAction<TimerSettings> {
} }
} }
async onPropertyInspectorDidAppear(ev: PropertyInspectorDidAppearEvent<TimerSettings>): Promise<void> { async onPropertyInspectorDidAppear(_ev: PropertyInspectorDidAppearEvent<TimerSettings>): Promise<void> {
try { await sendProjectsToPI();
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 onKeyDown(ev: KeyDownEvent<TimerSettings>): Promise<void> { async onKeyDown(ev: KeyDownEvent<TimerSettings>): Promise<void> {
@@ -244,12 +249,15 @@ const timerAction = new TimerToggle();
streamDeck.actions.registerAction(timerAction); streamDeck.actions.registerAction(timerAction);
// v2 requires using streamDeck.ui.onSendToPlugin — the SingletonAction method does not fire // 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) { if (ev.payload.event === "saveSettings" && ev.payload.settings) {
await ev.action.setSettings(ev.payload.settings); await ev.action.setSettings(ev.payload.settings);
const title = buttonTitle(ev.payload.settings.projectName || ""); const title = buttonTitle(ev.payload.settings.projectName || "");
if (title) await ev.action.setTitle(title); if (title) await ev.action.setTitle(title);
} }
if (ev.payload.event === "refreshProjects") {
await sendProjectsToPI(ev.payload.token);
}
if (ev.payload.event === "checkForUpdates") { if (ev.payload.event === "checkForUpdates") {
const send = (msg: string) => streamDeck.ui.sendToPropertyInspector({ event: "updateStatus", message: msg }); const send = (msg: string) => streamDeck.ui.sendToPropertyInspector({ event: "updateStatus", message: msg });
send("Checking…"); send("Checking…");

View File

@@ -1 +1 @@
{ "version": "1.0.26" } { "version": "1.0.27" }