v1.0.22: refresh projects/users when API token is saved

Previously onPropertyInspectorDidAppear fired once on PI open — if the
token wasn't saved yet (first-time setup), the dropdown stayed empty
forever. Now saving credentials sends a refresh event to the plugin,
which re-fetches and repopulates projects and names immediately.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
pdmarf
2026-04-23 20:49:33 +01:00
parent ad776c9aa9
commit c06240f03b
6 changed files with 66 additions and 48 deletions

View File

@@ -6438,7 +6438,7 @@ async function stopTimer(token, entryId) {
} }
// src/plugin.ts // 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 GITEA_BASE = "https://gitea.pdmarf.co.uk/pdm/stream_deck_notion_timer/raw/branch/master";
var SIGNING_PUBLIC_KEY = `-----BEGIN PUBLIC KEY----- var SIGNING_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEAN7ko8TUpuPzPAJuKAZCRjV0c4ZSlou5d9pUAF6o12b4= MCowBQYDK2VwAyEAN7ko8TUpuPzPAJuKAZCRjV0c4ZSlou5d9pUAF6o12b4=
@@ -6546,6 +6546,31 @@ 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(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) { function isConfigured(g) {
return !!(g.notionToken && g.userId); return !!(g.notionToken && g.userId);
} }
@@ -6573,29 +6598,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;
}
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 onKeyDown(ev) { async onKeyDown(ev) {
this.settingsCache.set(ev.action.id, ev.payload.settings); 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 || ""); 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 === "refresh") {
await sendProjectsToPI(ev.payload.notionToken);
}
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

@@ -1 +1 @@
_ÿ4/™èlŒeV·&BU1jìl3{<7B>#̲ZÔd7„±_e­Ôî÷¶Nnª'½•s;9ÄJ¢L©¿6 !a®rRÚÊ,Š{xJ0SÃÑ•ò²ØcÖu1Ø<ú5»K¸®û(a§/§ÃǨ<C387>»6<C2BB> omNK·t®þ

View File

@@ -195,6 +195,9 @@
}; };
$PI.setGlobalSettings(creds); $PI.setGlobalSettings(creds);
setCredStatus("Credentials saved.", "ok"); setCredStatus("Credentials saved.", "ok");
if (creds.notionToken) {
$PI.sendToPlugin({ event: "refresh", notionToken: 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.21"; const CURRENT_VERSION = "1.0.22";
const GITEA_BASE = "https://gitea.pdmarf.co.uk/pdm/stream_deck_notion_timer/raw/branch/master"; const GITEA_BASE = "https://gitea.pdmarf.co.uk/pdm/stream_deck_notion_timer/raw/branch/master";
const SIGNING_PUBLIC_KEY = `-----BEGIN PUBLIC KEY----- const SIGNING_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEAN7ko8TUpuPzPAJuKAZCRjV0c4ZSlou5d9pUAF6o12b4= MCowBQYDK2VwAyEAN7ko8TUpuPzPAJuKAZCRjV0c4ZSlou5d9pUAF6o12b4=
@@ -139,6 +139,30 @@ 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(overrideToken?: string): Promise<void> {
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<ReturnType<typeof fetchUsers>> = [];
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 { function isConfigured(g: GlobalSettings): boolean {
return !!(g.notionToken && g.userId); return !!(g.notionToken && g.userId);
} }
@@ -176,27 +200,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;
}
let usersResult: Awaited<ReturnType<typeof fetchUsers>> = [];
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 onKeyDown(ev: KeyDownEvent<TimerSettings>): Promise<void> { async onKeyDown(ev: KeyDownEvent<TimerSettings>): Promise<void> {
@@ -274,6 +279,9 @@ streamDeck.ui.onSendToPlugin<{ event: string; settings?: TimerSettings }>(async
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 === "refresh") {
await sendProjectsToPI(ev.payload.notionToken as string | undefined);
}
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.21" } { "version": "1.0.22" }