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:
@@ -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");
|
||||
|
||||
@@ -1 +1 @@
|
||||
_ÿ4/™èlŒe›V·&BU1jì‘l3{<7B>#̲Z’Ôd7„±_eÔî÷¶Nnª'½•s;9ÄJ¢L©¿6
|
||||
!›a®rRÚÊ,Š{xJ0SÃÑ•ò²ØcÖu1Ø<ú5»K¸®û(a§/§ÃǨ<C387>»6<C2BB>gÈ‘omNK·t®þ
|
||||
@@ -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) {
|
||||
|
||||
Binary file not shown.
@@ -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<void> {
|
||||
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 {
|
||||
return !!(g.notionToken && g.userId);
|
||||
}
|
||||
@@ -176,27 +200,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;
|
||||
}
|
||||
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 onPropertyInspectorDidAppear(_ev: PropertyInspectorDidAppearEvent<TimerSettings>): Promise<void> {
|
||||
await sendProjectsToPI();
|
||||
}
|
||||
|
||||
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 || "");
|
||||
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…");
|
||||
|
||||
@@ -1 +1 @@
|
||||
{ "version": "1.0.21" }
|
||||
{ "version": "1.0.22" }
|
||||
|
||||
Reference in New Issue
Block a user