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:
@@ -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<void> {
|
||||
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 {
|
||||
return !!(g.notionToken && g.userId);
|
||||
}
|
||||
@@ -146,25 +168,8 @@ class TimerToggle extends SingletonAction<TimerSettings> {
|
||||
}
|
||||
}
|
||||
|
||||
async onPropertyInspectorDidAppear(ev: PropertyInspectorDidAppearEvent<TimerSettings>): Promise<void> {
|
||||
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<TimerSettings>): Promise<void> {
|
||||
await sendProjectsToPI();
|
||||
}
|
||||
|
||||
async onKeyDown(ev: KeyDownEvent<TimerSettings>): Promise<void> {
|
||||
@@ -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…");
|
||||
|
||||
Reference in New Issue
Block a user