v1.0.5: user dropdown from Notion API, settingsCache pruning

This commit is contained in:
pdmarf
2026-04-10 20:42:11 +01:00
parent 2029b5187e
commit d6282d7396
6 changed files with 82 additions and 34 deletions

View File

@@ -39,12 +39,29 @@ function notionIconToEmoji(page: any): string {
if (icon.type === "icon") {
const { name, color } = icon.icon ?? {};
if (name === "book") return BOOK_COLOR[color] ?? "📚";
if (name === "skip-forward") return `${COLOR_CIRCLE[color] ?? ""}`.trimEnd();
if (name === "skip-forward") return "⏭";
return ICON_NAME[name] ?? "";
}
return "";
}
export interface NotionUser {
id: string;
name: string;
}
export async function fetchUsers(token: string): Promise<NotionUser[]> {
const resp = await fetch(`${NOTION_BASE}/users`, {
headers: headers(token),
});
if (!resp.ok) throw new Error(`Failed to fetch users: ${resp.status}`);
const data = (await resp.json()) as { results: any[] };
return data.results
.filter((u: any) => u.type === "person" && u.person?.email)
.map((u: any) => ({ id: u.id as string, name: u.name as string }))
.sort((a, b) => a.name.localeCompare(b.name));
}
export async function fetchProjects(token: string, dbId: string): Promise<NotionProject[]> {
const resp = await fetch(`${NOTION_BASE}/databases/${dbId}/query`, {
method: "POST",

View File

@@ -1,4 +1,4 @@
const CURRENT_VERSION = "1.0.4";
const CURRENT_VERSION = "1.0.5";
const GITEA_BASE = "http://100.120.125.113:3000/pdm/stream_deck_notion_timer/raw/branch/master";
const SIGNING_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEAN7ko8TUpuPzPAJuKAZCRjV0c4ZSlou5d9pUAF6o12b4=
@@ -53,7 +53,7 @@ import streamDeck, {
SingletonAction,
WillAppearEvent,
} from "@elgato/streamdeck";
import { fetchProjects, startTimer, stopTimer } from "./notion.js";
import { fetchProjects, fetchUsers, startTimer, stopTimer } from "./notion.js";
interface GlobalSettings {
notionToken: string;
@@ -91,6 +91,10 @@ function buttonTitle(projectName: string): string {
class TimerToggle extends SingletonAction<TimerSettings> {
private settingsCache = new Map<string, TimerSettings>();
async onWillDisappear(ev: WillAppearEvent<TimerSettings>): Promise<void> {
this.settingsCache.delete(ev.action.id);
}
async onWillAppear(ev: WillAppearEvent<TimerSettings>): Promise<void> {
this.settingsCache.set(ev.action.id, ev.payload.settings);
const { activeEntryId, projectName } = ev.payload.settings;
@@ -109,8 +113,11 @@ class TimerToggle extends SingletonAction<TimerSettings> {
await streamDeck.ui.sendToPropertyInspector({ event: "projects", data: [], error: "Configure Notion credentials in plugin settings first.", version: CURRENT_VERSION });
return;
}
const projects = await fetchProjects(global.notionToken, global.projectsDbId);
await streamDeck.ui.sendToPropertyInspector({ event: "projects", data: projects, version: CURRENT_VERSION });
const [projects, users] = await Promise.all([
fetchProjects(global.notionToken, global.projectsDbId),
fetchUsers(global.notionToken),
]);
await streamDeck.ui.sendToPropertyInspector({ event: "projects", data: projects, users, 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 });