Compare commits
23
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f12a8d2b74 | ||
|
|
43938dded5 | ||
|
|
c50ee5e822 | ||
|
|
0956b28864 | ||
|
|
c6f2d9ae70 | ||
|
|
b1c645c7a5 | ||
|
|
6575f7a1e6 | ||
|
|
08019e3c5c | ||
|
|
608b804e5e | ||
|
|
c8667c3844 | ||
|
|
b08126e06e | ||
|
|
e2e29cc876 | ||
|
|
ffaf7ff4e4 | ||
|
|
564fd0571f | ||
|
|
4a7ed58410 | ||
|
|
0b4345dad6 | ||
|
|
feed18ed0d | ||
|
|
acf4f98d6b | ||
|
|
ae230e45ed | ||
|
|
3a033679c8 | ||
|
|
5b3ba8186c | ||
|
|
e897f0a8f5 | ||
|
|
2e2f2553ac |
@@ -6375,6 +6375,15 @@ async function fetchUsers(token) {
|
|||||||
const data = await resp.json();
|
const data = await resp.json();
|
||||||
return data.results.filter((u) => u.type === "person" && u.person?.email).map((u) => ({ id: u.id, name: u.name })).sort((a, b) => a.name.localeCompare(b.name));
|
return data.results.filter((u) => u.type === "person" && u.person?.email).map((u) => ({ id: u.id, name: u.name })).sort((a, b) => a.name.localeCompare(b.name));
|
||||||
}
|
}
|
||||||
|
async function fetchTagOptions(token, databaseId, propertyName) {
|
||||||
|
const resp = await fetchWithTimeout(`${NOTION_BASE}/databases/${databaseId}`, {
|
||||||
|
headers: headers(token)
|
||||||
|
});
|
||||||
|
if (!resp.ok) throw new Error(`Failed to fetch database schema: ${resp.status}`);
|
||||||
|
const data = await resp.json();
|
||||||
|
const options = data.properties?.[propertyName]?.select?.options ?? [];
|
||||||
|
return options.map((o) => o.name);
|
||||||
|
}
|
||||||
async function fetchProjects(token, dbId) {
|
async function fetchProjects(token, dbId) {
|
||||||
const results = [];
|
const results = [];
|
||||||
let cursor;
|
let cursor;
|
||||||
@@ -6401,21 +6410,24 @@ async function fetchProjects(token, dbId) {
|
|||||||
} while (cursor);
|
} while (cursor);
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
async function startTimer(token, timingDbId, projectId, projectName, userId) {
|
async function startTimer(token, timingDbId, projectId, projectName, userId, tag, description) {
|
||||||
const now = (/* @__PURE__ */ new Date()).toISOString();
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
||||||
|
const properties = {
|
||||||
|
Name: { title: [{ text: { content: "Timer Task" } }] },
|
||||||
|
"Start Time": { date: { start: now } },
|
||||||
|
Projects: { relation: [{ id: projectId }] },
|
||||||
|
Status: { status: { name: "Running" } },
|
||||||
|
Responsible: { people: [{ object: "user", id: userId }] }
|
||||||
|
};
|
||||||
|
if (tag) properties["Timer Tags"] = { select: { name: tag } };
|
||||||
|
if (description) properties.Description = { rich_text: [{ text: { content: description } }] };
|
||||||
const resp = await fetchWithTimeout(`${NOTION_BASE}/pages`, {
|
const resp = await fetchWithTimeout(`${NOTION_BASE}/pages`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: headers(token),
|
headers: headers(token),
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
parent: { database_id: timingDbId },
|
parent: { database_id: timingDbId },
|
||||||
icon: { type: "emoji", emoji: "\u23F1\uFE0F" },
|
icon: { type: "emoji", emoji: "\u23F1\uFE0F" },
|
||||||
properties: {
|
properties
|
||||||
Name: { title: [{ text: { content: "Timer Task" } }] },
|
|
||||||
"Start Time": { date: { start: now } },
|
|
||||||
Projects: { relation: [{ id: projectId }] },
|
|
||||||
Status: { status: { name: "Running" } },
|
|
||||||
Responsible: { people: [{ object: "user", id: userId }] }
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
if (!resp.ok) throw new Error(`Failed to start timer: ${resp.status}`);
|
if (!resp.ok) throw new Error(`Failed to start timer: ${resp.status}`);
|
||||||
@@ -6438,7 +6450,7 @@ async function stopTimer(token, entryId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// src/plugin.ts
|
// src/plugin.ts
|
||||||
var CURRENT_VERSION = "1.0.43";
|
var CURRENT_VERSION = "1.0.65";
|
||||||
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=
|
||||||
@@ -6460,12 +6472,17 @@ async function checkForUpdates(sendStatus) {
|
|||||||
try {
|
try {
|
||||||
const resp = await fetchWithTimeout2(`${GITEA_BASE}/version.json`);
|
const resp = await fetchWithTimeout2(`${GITEA_BASE}/version.json`);
|
||||||
if (!resp.ok) {
|
if (!resp.ok) {
|
||||||
|
plugin_default.logger.warn(`Update check: version.json fetch returned ${resp.status}`);
|
||||||
sendStatus?.("Update check failed");
|
sendStatus?.("Update check failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { version } = await resp.json();
|
const { version } = await resp.json();
|
||||||
if (!/^\d+\.\d+\.\d+$/.test(version)) return;
|
if (!/^\d+\.\d+\.\d+$/.test(version)) {
|
||||||
|
plugin_default.logger.warn(`Update check: version.json had unexpected content: ${JSON.stringify(version)}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!isNewerVersion(version, CURRENT_VERSION)) {
|
if (!isNewerVersion(version, CURRENT_VERSION)) {
|
||||||
|
plugin_default.logger.info(`Update check: up to date (v${CURRENT_VERSION}, server has v${version})`);
|
||||||
sendStatus?.(`Already up to date (v${CURRENT_VERSION})`);
|
sendStatus?.(`Already up to date (v${CURRENT_VERSION})`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -6512,6 +6529,8 @@ async function checkForUpdates(sendStatus) {
|
|||||||
}
|
}
|
||||||
fs3.writeFileSync(__filename, newCode);
|
fs3.writeFileSync(__filename, newCode);
|
||||||
plugin_default.logger.info(`Updated to ${version}, restarting\u2026`);
|
plugin_default.logger.info(`Updated to ${version}, restarting\u2026`);
|
||||||
|
await sendStatus?.(`Updated to v${version}. Click any other button above to confirm version update has been successful.`);
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 200));
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const msg = err instanceof Error ? err.message : String(err);
|
const msg = err instanceof Error ? err.message : String(err);
|
||||||
@@ -6523,6 +6542,7 @@ var HARDCODED = {
|
|||||||
timingDbId: "2ec93117da3a80799ee2cf91244ee264",
|
timingDbId: "2ec93117da3a80799ee2cf91244ee264",
|
||||||
projectsDbId: "cd65c760-0f0a-4d6e-a262-d572c9e31585"
|
projectsDbId: "cd65c760-0f0a-4d6e-a262-d572c9e31585"
|
||||||
};
|
};
|
||||||
|
var DEFAULT_TAG = "Client Books";
|
||||||
async function getGlobal() {
|
async function getGlobal() {
|
||||||
const stored = await plugin_default.settings.getGlobalSettings();
|
const stored = await plugin_default.settings.getGlobalSettings();
|
||||||
return { ...stored, ...HARDCODED };
|
return { ...stored, ...HARDCODED };
|
||||||
@@ -6548,14 +6568,18 @@ async function sendProjectsToPI(tokenOverride) {
|
|||||||
await plugin_default.ui.sendToPropertyInspector({ event: "projects", data: [], error: "Enter your Notion API token above.", version: CURRENT_VERSION });
|
await plugin_default.ui.sendToPropertyInspector({ event: "projects", data: [], error: "Enter your Notion API token above.", version: CURRENT_VERSION });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const [projects, usersResult] = await Promise.all([
|
const [projects, usersResult, tagsResult] = await Promise.all([
|
||||||
fetchProjects(token, global.projectsDbId),
|
fetchProjects(token, global.projectsDbId),
|
||||||
fetchUsers(token).catch((err) => {
|
fetchUsers(token).catch((err) => {
|
||||||
plugin_default.logger.error("Failed to fetch users:", err);
|
plugin_default.logger.error("Failed to fetch users:", err);
|
||||||
return [];
|
return [];
|
||||||
|
}),
|
||||||
|
fetchTagOptions(token, global.timingDbId, "Timer Tags").catch((err) => {
|
||||||
|
plugin_default.logger.error("Failed to fetch tag options:", err);
|
||||||
|
return [];
|
||||||
})
|
})
|
||||||
]);
|
]);
|
||||||
await plugin_default.ui.sendToPropertyInspector({ event: "projects", data: projects, users: usersResult, version: CURRENT_VERSION });
|
await plugin_default.ui.sendToPropertyInspector({ event: "projects", data: projects, users: usersResult, tags: tagsResult, version: CURRENT_VERSION });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
plugin_default.logger.error("Failed to fetch projects:", err);
|
plugin_default.logger.error("Failed to fetch projects:", err);
|
||||||
await plugin_default.ui.sendToPropertyInspector({ event: "projects", data: [], error: String(err), version: CURRENT_VERSION });
|
await plugin_default.ui.sendToPropertyInspector({ event: "projects", data: [], error: String(err), version: CURRENT_VERSION });
|
||||||
@@ -6564,8 +6588,9 @@ async function sendProjectsToPI(tokenOverride) {
|
|||||||
function isConfigured(g) {
|
function isConfigured(g) {
|
||||||
return !!(g.notionToken && g.userId);
|
return !!(g.notionToken && g.userId);
|
||||||
}
|
}
|
||||||
function buttonTitle(projectName) {
|
function buttonTitle(projectName, tag) {
|
||||||
return projectName.replace(/^[\p{Extended_Pictographic}\uFE0F\s]+/u, "").trim();
|
const base = projectName.replace(/^[\p{Extended_Pictographic}\uFE0F\s]+/u, "").trim();
|
||||||
|
return tag ? `${base} \xB7 ${tag}` : base;
|
||||||
}
|
}
|
||||||
var ELAPSED_CHECK_MS = 60 * 60 * 1e3;
|
var ELAPSED_CHECK_MS = 60 * 60 * 1e3;
|
||||||
var DIALOG_TIMEOUT_SECONDS = 300;
|
var DIALOG_TIMEOUT_SECONDS = 300;
|
||||||
@@ -6585,6 +6610,22 @@ Should it continue?" buttons {"Stop", "Continue"} default button "Continue" givi
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
async function promptDescription(title) {
|
||||||
|
const { execFile: execFile3 } = await import("node:child_process");
|
||||||
|
const safeTitle = title.replace(/[\\"]/g, "");
|
||||||
|
const script = `display dialog "Description for ${safeTitle} (optional):" default answer "" buttons {"Cancel", "Start"} default button "Start" giving up after ${DIALOG_TIMEOUT_SECONDS}`;
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
execFile3("osascript", ["-e", script], (err, stdout) => {
|
||||||
|
const out = String(stdout);
|
||||||
|
if (err || /gave up:true/.test(out) || !/button returned:Start/.test(out)) {
|
||||||
|
resolve({ ok: false, text: "" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const match = /text returned:(.*?)(?:, gave up:|$)/.exec(out);
|
||||||
|
resolve({ ok: true, text: match ? match[1].trim() : "" });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
var TimerToggle = class extends SingletonAction {
|
var TimerToggle = class extends SingletonAction {
|
||||||
projectCache = /* @__PURE__ */ new Map();
|
projectCache = /* @__PURE__ */ new Map();
|
||||||
keyDownBusy = false;
|
keyDownBusy = false;
|
||||||
@@ -6624,7 +6665,7 @@ var TimerToggle = class extends SingletonAction {
|
|||||||
}
|
}
|
||||||
async onWillAppear(ev) {
|
async onWillAppear(ev) {
|
||||||
this.projectCache.set(ev.action.id, ev.payload.settings);
|
this.projectCache.set(ev.action.id, ev.payload.settings);
|
||||||
const title = buttonTitle(ev.payload.settings.projectName || "");
|
const title = buttonTitle(ev.payload.settings.projectName || "", ev.payload.settings.tag);
|
||||||
await loadRunningState();
|
await loadRunningState();
|
||||||
const isRunning = memRunningActionId === ev.action.id;
|
const isRunning = memRunningActionId === ev.action.id;
|
||||||
if (isRunning) {
|
if (isRunning) {
|
||||||
@@ -6638,8 +6679,9 @@ var TimerToggle = class extends SingletonAction {
|
|||||||
}
|
}
|
||||||
async onKeyDown(ev) {
|
async onKeyDown(ev) {
|
||||||
if (this.keyDownBusy) {
|
if (this.keyDownBusy) {
|
||||||
const title = buttonTitle(ev.payload.settings.projectName || "");
|
const title = buttonTitle(ev.payload.settings.projectName || "", ev.payload.settings.tag);
|
||||||
const shouldBeRunning = memRunningActionId === ev.action.id;
|
const shouldBeRunning = memRunningActionId === ev.action.id;
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 150));
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
ev.action.setState(shouldBeRunning ? 1 : 0),
|
ev.action.setState(shouldBeRunning ? 1 : 0),
|
||||||
ev.action.setTitle(shouldBeRunning ? `\u23F1 ${title}` : title)
|
ev.action.setTitle(shouldBeRunning ? `\u23F1 ${title}` : title)
|
||||||
@@ -6648,9 +6690,15 @@ var TimerToggle = class extends SingletonAction {
|
|||||||
}
|
}
|
||||||
this.keyDownBusy = true;
|
this.keyDownBusy = true;
|
||||||
try {
|
try {
|
||||||
const { projectId, projectName } = ev.payload.settings;
|
const { projectId, projectName, tag, askDescription } = ev.payload.settings;
|
||||||
const title = buttonTitle(projectName || "");
|
const title = buttonTitle(projectName || "", tag);
|
||||||
const isRunning = memRunningActionId === ev.action.id;
|
const isRunning = memRunningActionId === ev.action.id;
|
||||||
|
let description = "";
|
||||||
|
if (!isRunning && projectId && askDescription) {
|
||||||
|
const result = await promptDescription(title);
|
||||||
|
if (!result.ok) return;
|
||||||
|
description = result.text;
|
||||||
|
}
|
||||||
if (projectId) {
|
if (projectId) {
|
||||||
if (isRunning) {
|
if (isRunning) {
|
||||||
await Promise.all([ev.action.setState(0), ev.action.setTitle(title)]);
|
await Promise.all([ev.action.setState(0), ev.action.setTitle(title)]);
|
||||||
@@ -6659,7 +6707,7 @@ var TimerToggle = class extends SingletonAction {
|
|||||||
if (other.id === ev.action.id) continue;
|
if (other.id === ev.action.id) continue;
|
||||||
if (memRunningActionId === other.id) {
|
if (memRunningActionId === other.id) {
|
||||||
const s = this.projectCache.get(other.id);
|
const s = this.projectCache.get(other.id);
|
||||||
await Promise.all([other.setState(0), other.setTitle(buttonTitle(s?.projectName || ""))]);
|
await Promise.all([other.setState(0), other.setTitle(buttonTitle(s?.projectName || "", s?.tag))]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await Promise.all([ev.action.setState(1), ev.action.setTitle(`\u23F1 ${title}`)]);
|
await Promise.all([ev.action.setState(1), ev.action.setTitle(`\u23F1 ${title}`)]);
|
||||||
@@ -6676,16 +6724,25 @@ var TimerToggle = class extends SingletonAction {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (isRunning) {
|
if (isRunning) {
|
||||||
await stopTimer(global.notionToken, memRunningEntryId);
|
try {
|
||||||
|
await stopTimer(global.notionToken, memRunningEntryId);
|
||||||
|
} catch (err) {
|
||||||
|
plugin_default.logger.error("Failed to stop timer in Notion (clearing local state anyway):", err);
|
||||||
|
}
|
||||||
setRunningEntry(null, null);
|
setRunningEntry(null, null);
|
||||||
this.clearElapsedCheck();
|
this.clearElapsedCheck();
|
||||||
await Promise.all([ev.action.setState(0), ev.action.setTitle(title)]);
|
await Promise.all([ev.action.setState(0), ev.action.setTitle(title)]);
|
||||||
} else {
|
} else {
|
||||||
if (memRunningEntryId) {
|
if (memRunningEntryId) {
|
||||||
await stopTimer(global.notionToken, memRunningEntryId);
|
try {
|
||||||
|
await stopTimer(global.notionToken, memRunningEntryId);
|
||||||
|
} catch (err) {
|
||||||
|
plugin_default.logger.error("Failed to stop previous timer in Notion (clearing local state anyway):", err);
|
||||||
|
}
|
||||||
|
setRunningEntry(null, null);
|
||||||
this.clearElapsedCheck();
|
this.clearElapsedCheck();
|
||||||
}
|
}
|
||||||
const entryId = await startTimer(global.notionToken, global.timingDbId, projectId, projectName, global.userId);
|
const entryId = await startTimer(global.notionToken, global.timingDbId, projectId, projectName, global.userId, tag || DEFAULT_TAG, description);
|
||||||
setRunningEntry(entryId, ev.action.id);
|
setRunningEntry(entryId, ev.action.id);
|
||||||
this.scheduleElapsedCheck(entryId, ev.action.id, title);
|
this.scheduleElapsedCheck(entryId, ev.action.id, title);
|
||||||
await Promise.all([ev.action.setState(1), ev.action.setTitle(`\u23F1 ${title}`)]);
|
await Promise.all([ev.action.setState(1), ev.action.setTitle(`\u23F1 ${title}`)]);
|
||||||
@@ -6706,12 +6763,33 @@ var TimerToggle = class extends SingletonAction {
|
|||||||
TimerToggle = __decorateClass([
|
TimerToggle = __decorateClass([
|
||||||
action({ UUID: "com.pdma.notion-timer.toggle" })
|
action({ UUID: "com.pdma.notion-timer.toggle" })
|
||||||
], TimerToggle);
|
], TimerToggle);
|
||||||
|
var NEXTCLOUD_BIN = "/Applications/Nextcloud.app/Contents/MacOS/Nextcloud";
|
||||||
|
var LaunchNextcloud = class extends SingletonAction {
|
||||||
|
async onKeyDown(ev) {
|
||||||
|
try {
|
||||||
|
const { spawn } = await import("node:child_process");
|
||||||
|
const child = spawn(NEXTCLOUD_BIN, [], { detached: true, stdio: "ignore" });
|
||||||
|
child.once("error", (err) => {
|
||||||
|
plugin_default.logger.error("Failed to launch Nextcloud:", err);
|
||||||
|
});
|
||||||
|
child.unref();
|
||||||
|
await ev.action.showOk();
|
||||||
|
} catch (err) {
|
||||||
|
plugin_default.logger.error("Failed to launch Nextcloud:", err);
|
||||||
|
await ev.action.showAlert();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
LaunchNextcloud = __decorateClass([
|
||||||
|
action({ UUID: "com.pdma.notion-timer.launch-nextcloud" })
|
||||||
|
], LaunchNextcloud);
|
||||||
var timerAction = new TimerToggle();
|
var timerAction = new TimerToggle();
|
||||||
plugin_default.actions.registerAction(timerAction);
|
plugin_default.actions.registerAction(timerAction);
|
||||||
|
plugin_default.actions.registerAction(new LaunchNextcloud());
|
||||||
plugin_default.ui.onSendToPlugin(async (ev) => {
|
plugin_default.ui.onSendToPlugin(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 || "", ev.payload.settings.tag);
|
||||||
if (title) await ev.action.setTitle(title);
|
if (title) await ev.action.setTitle(title);
|
||||||
}
|
}
|
||||||
if (ev.payload.event === "refreshProjects") {
|
if (ev.payload.event === "refreshProjects") {
|
||||||
@@ -6723,8 +6801,16 @@ plugin_default.ui.onSendToPlugin(async (ev) => {
|
|||||||
await checkForUpdates(send);
|
await checkForUpdates(send);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
var UPDATE_CHECK_INTERVAL_MS = 30 * 60 * 1e3;
|
||||||
plugin_default.connect();
|
plugin_default.connect();
|
||||||
setTimeout(() => checkForUpdates(), 1e4);
|
setTimeout(() => {
|
||||||
|
plugin_default.logger.info("Running initial (10s post-launch) update check");
|
||||||
|
checkForUpdates();
|
||||||
|
}, 1e4);
|
||||||
|
setInterval(() => {
|
||||||
|
plugin_default.logger.info("Running scheduled (30min) update check");
|
||||||
|
checkForUpdates();
|
||||||
|
}, UPDATE_CHECK_INTERVAL_MS);
|
||||||
/*! Bundled license information:
|
/*! Bundled license information:
|
||||||
|
|
||||||
@elgato/schemas/dist/streamdeck/plugins/index.mjs:
|
@elgato/schemas/dist/streamdeck/plugins/index.mjs:
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
@@ -0,0 +1,5 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 144" width="144" height="144">
|
||||||
|
<rect width="144" height="144" rx="16" fill="#0082c9"/>
|
||||||
|
<path d="M72 46c-13.3 0-24.4 9.4-27.1 22a16 16 0 0 0 3.1 31.8h48a16.5 16.5 0 0 0 3.6-32.6C97.3 55.6 85.9 46 72 46z"
|
||||||
|
fill="none" stroke="white" stroke-width="6" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 349 B |
@@ -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.39",
|
"Version": "1.0.40",
|
||||||
"SDKVersion": 2,
|
"SDKVersion": 2,
|
||||||
"Software": { "MinimumVersion": "5.0" },
|
"Software": { "MinimumVersion": "5.0" },
|
||||||
"OS": [{ "Platform": "mac", "MinimumVersion": "10.11" }],
|
"OS": [{ "Platform": "mac", "MinimumVersion": "10.11" }],
|
||||||
@@ -30,6 +30,19 @@
|
|||||||
],
|
],
|
||||||
"PropertyInspectorPath": "ui/property-inspector.html",
|
"PropertyInspectorPath": "ui/property-inspector.html",
|
||||||
"SupportedInMultiActions": false
|
"SupportedInMultiActions": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Icon": "imgs/nextcloud-icon",
|
||||||
|
"Name": "Launch Nextcloud",
|
||||||
|
"UUID": "com.pdma.notion-timer.launch-nextcloud",
|
||||||
|
"Tooltip": "Launch the Nextcloud desktop client in the background.",
|
||||||
|
"States": [
|
||||||
|
{
|
||||||
|
"Image": "imgs/nextcloud-icon",
|
||||||
|
"TitleAlignment": "bottom"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"SupportedInMultiActions": false
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,11 @@
|
|||||||
padding-left: 98px;
|
padding-left: 98px;
|
||||||
line-height: 1.4;
|
line-height: 1.4;
|
||||||
}
|
}
|
||||||
|
.info-icon {
|
||||||
|
color: #888;
|
||||||
|
font-size: 13px;
|
||||||
|
cursor: help;
|
||||||
|
}
|
||||||
.divider {
|
.divider {
|
||||||
border: none;
|
border: none;
|
||||||
border-top: 1px solid #333;
|
border-top: 1px solid #333;
|
||||||
@@ -142,6 +147,22 @@
|
|||||||
<option value="">Loading projects…</option>
|
<option value="">Loading projects…</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<label>Ask description (optional)</label>
|
||||||
|
<input type="checkbox" id="askDescription" style="flex: none; width: auto;">
|
||||||
|
<span class="info-icon" title="Prompt for a description when starting this button's timer.">ⓘ</span>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<label>Use tag (Pete only)</label>
|
||||||
|
<input type="checkbox" id="tagEnabled" style="flex: none; width: auto;">
|
||||||
|
</div>
|
||||||
|
<div class="row" id="tagRow">
|
||||||
|
<label></label>
|
||||||
|
<select id="tagSelect">
|
||||||
|
<option value="">— No tag —</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<p class="hint" id="tagHint">Recorded as the entry's Tag in Notion and shown on the button.</p>
|
||||||
|
|
||||||
<p id="statusText"></p>
|
<p id="statusText"></p>
|
||||||
<p id="versionText"></p>
|
<p id="versionText"></p>
|
||||||
@@ -163,6 +184,7 @@
|
|||||||
var credConfigured = false;
|
var credConfigured = false;
|
||||||
var globalUserId = "";
|
var globalUserId = "";
|
||||||
var cachedUsers = [];
|
var cachedUsers = [];
|
||||||
|
var cachedTags = [];
|
||||||
|
|
||||||
function setStatus(msg, cls) {
|
function setStatus(msg, cls) {
|
||||||
var el = document.getElementById("statusText");
|
var el = document.getElementById("statusText");
|
||||||
@@ -224,11 +246,39 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function populateTags(tags) {
|
||||||
|
cachedTags = tags;
|
||||||
|
var sel = document.getElementById("tagSelect");
|
||||||
|
sel.innerHTML = '<option value="">— No tag —</option>';
|
||||||
|
var values = tags.slice();
|
||||||
|
// A tag saved on this button before it existed as a Notion select option
|
||||||
|
// (or since removed there) must still show up, selected, instead of
|
||||||
|
// silently reverting to "No tag".
|
||||||
|
if (currentSettings.tag && values.indexOf(currentSettings.tag) === -1) {
|
||||||
|
values.push(currentSettings.tag);
|
||||||
|
}
|
||||||
|
values.forEach(function(t) {
|
||||||
|
var opt = document.createElement("option");
|
||||||
|
opt.value = t;
|
||||||
|
opt.textContent = t;
|
||||||
|
if (currentSettings.tag === t) opt.selected = true;
|
||||||
|
sel.appendChild(opt);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function setTagRowVisible(visible) {
|
||||||
|
document.getElementById("tagRow").style.display = visible ? "" : "none";
|
||||||
|
document.getElementById("tagHint").style.display = visible ? "" : "none";
|
||||||
|
}
|
||||||
|
|
||||||
function save() {
|
function save() {
|
||||||
var sel = document.getElementById("projectSelect");
|
var sel = document.getElementById("projectSelect");
|
||||||
var opt = sel.options[sel.selectedIndex];
|
var opt = sel.options[sel.selectedIndex];
|
||||||
currentSettings.projectId = sel.value;
|
currentSettings.projectId = sel.value;
|
||||||
currentSettings.projectName = sel.value ? opt.textContent.trim() : "";
|
currentSettings.projectName = sel.value ? opt.textContent.trim() : "";
|
||||||
|
currentSettings.tagEnabled = document.getElementById("tagEnabled").checked;
|
||||||
|
currentSettings.tag = currentSettings.tagEnabled ? document.getElementById("tagSelect").value : "";
|
||||||
|
currentSettings.askDescription = document.getElementById("askDescription").checked;
|
||||||
$PI.setSettings(currentSettings);
|
$PI.setSettings(currentSettings);
|
||||||
$PI.sendToPlugin({ event: "saveSettings", settings: currentSettings });
|
$PI.sendToPlugin({ event: "saveSettings", settings: currentSettings });
|
||||||
setStatus(currentSettings.projectName ? "Saved: " + currentSettings.projectName : "", "");
|
setStatus(currentSettings.projectName ? "Saved: " + currentSettings.projectName : "", "");
|
||||||
@@ -255,10 +305,19 @@
|
|||||||
|
|
||||||
$PI.onConnected(function(jsn) {
|
$PI.onConnected(function(jsn) {
|
||||||
currentSettings = jsn.actionInfo.payload.settings || {};
|
currentSettings = jsn.actionInfo.payload.settings || {};
|
||||||
|
document.getElementById("tagEnabled").checked = !!currentSettings.tagEnabled;
|
||||||
|
setTagRowVisible(!!currentSettings.tagEnabled);
|
||||||
|
document.getElementById("askDescription").checked = !!currentSettings.askDescription;
|
||||||
$PI.getSettings();
|
$PI.getSettings();
|
||||||
$PI.getGlobalSettings();
|
$PI.getGlobalSettings();
|
||||||
|
|
||||||
document.getElementById("projectSelect").addEventListener("change", save);
|
document.getElementById("projectSelect").addEventListener("change", save);
|
||||||
|
document.getElementById("tagEnabled").addEventListener("change", function() {
|
||||||
|
setTagRowVisible(this.checked);
|
||||||
|
save();
|
||||||
|
});
|
||||||
|
document.getElementById("tagSelect").addEventListener("change", save);
|
||||||
|
document.getElementById("askDescription").addEventListener("change", save);
|
||||||
document.getElementById("notionToken").addEventListener("input", scheduleCredSave);
|
document.getElementById("notionToken").addEventListener("input", scheduleCredSave);
|
||||||
document.getElementById("userId").addEventListener("change", saveCredentials);
|
document.getElementById("userId").addEventListener("change", saveCredentials);
|
||||||
document.getElementById("updateBtn").addEventListener("click", function() {
|
document.getElementById("updateBtn").addEventListener("click", function() {
|
||||||
@@ -296,6 +355,10 @@
|
|||||||
if (currentSettings.projectId && sel.options.length > 1) {
|
if (currentSettings.projectId && sel.options.length > 1) {
|
||||||
sel.value = currentSettings.projectId;
|
sel.value = currentSettings.projectId;
|
||||||
}
|
}
|
||||||
|
document.getElementById("tagEnabled").checked = !!currentSettings.tagEnabled;
|
||||||
|
setTagRowVisible(!!currentSettings.tagEnabled);
|
||||||
|
populateTags(cachedTags);
|
||||||
|
document.getElementById("askDescription").checked = !!currentSettings.askDescription;
|
||||||
if (currentSettings.activeEntryId) {
|
if (currentSettings.activeEntryId) {
|
||||||
setStatus("⏱ Timer running", "running");
|
setStatus("⏱ Timer running", "running");
|
||||||
}
|
}
|
||||||
@@ -313,6 +376,9 @@
|
|||||||
if (payload.users) {
|
if (payload.users) {
|
||||||
populateUsers(payload.users, globalUserId);
|
populateUsers(payload.users, globalUserId);
|
||||||
}
|
}
|
||||||
|
if (payload.tags) {
|
||||||
|
populateTags(payload.tags);
|
||||||
|
}
|
||||||
if (payload.error) {
|
if (payload.error) {
|
||||||
setStatus(payload.error, "error");
|
setStatus(payload.error, "error");
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Binary file not shown.
+28
-8
@@ -63,6 +63,20 @@ export async function fetchUsers(token: string): Promise<NotionUser[]> {
|
|||||||
.sort((a, b) => a.name.localeCompare(b.name));
|
.sort((a, b) => a.name.localeCompare(b.name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function fetchTagOptions(
|
||||||
|
token: string,
|
||||||
|
databaseId: string,
|
||||||
|
propertyName: string
|
||||||
|
): Promise<string[]> {
|
||||||
|
const resp = await fetchWithTimeout(`${NOTION_BASE}/databases/${databaseId}`, {
|
||||||
|
headers: headers(token),
|
||||||
|
});
|
||||||
|
if (!resp.ok) throw new Error(`Failed to fetch database schema: ${resp.status}`);
|
||||||
|
const data = (await resp.json()) as { properties?: Record<string, any> };
|
||||||
|
const options: any[] = data.properties?.[propertyName]?.select?.options ?? [];
|
||||||
|
return options.map((o: any) => o.name as string);
|
||||||
|
}
|
||||||
|
|
||||||
export async function fetchProjects(token: string, dbId: string): Promise<NotionProject[]> {
|
export async function fetchProjects(token: string, dbId: string): Promise<NotionProject[]> {
|
||||||
const results: NotionProject[] = [];
|
const results: NotionProject[] = [];
|
||||||
let cursor: string | undefined;
|
let cursor: string | undefined;
|
||||||
@@ -102,23 +116,29 @@ export async function startTimer(
|
|||||||
timingDbId: string,
|
timingDbId: string,
|
||||||
projectId: string,
|
projectId: string,
|
||||||
projectName: string,
|
projectName: string,
|
||||||
userId: string
|
userId: string,
|
||||||
|
tag?: string,
|
||||||
|
description?: string
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const now = new Date().toISOString();
|
const now = new Date().toISOString();
|
||||||
|
|
||||||
|
const properties: Record<string, unknown> = {
|
||||||
|
Name: { title: [{ text: { content: "Timer Task" } }] },
|
||||||
|
"Start Time": { date: { start: now } },
|
||||||
|
Projects: { relation: [{ id: projectId }] },
|
||||||
|
Status: { status: { name: "Running" } },
|
||||||
|
Responsible: { people: [{ object: "user", id: userId }] },
|
||||||
|
};
|
||||||
|
if (tag) properties["Timer Tags"] = { select: { name: tag } };
|
||||||
|
if (description) properties.Description = { rich_text: [{ text: { content: description } }] };
|
||||||
|
|
||||||
const resp = await fetchWithTimeout(`${NOTION_BASE}/pages`, {
|
const resp = await fetchWithTimeout(`${NOTION_BASE}/pages`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: headers(token),
|
headers: headers(token),
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
parent: { database_id: timingDbId },
|
parent: { database_id: timingDbId },
|
||||||
icon: { type: "emoji", emoji: "⏱️" },
|
icon: { type: "emoji", emoji: "⏱️" },
|
||||||
properties: {
|
properties,
|
||||||
Name: { title: [{ text: { content: "Timer Task" } }] },
|
|
||||||
"Start Time": { date: { start: now } },
|
|
||||||
Projects: { relation: [{ id: projectId }] },
|
|
||||||
Status: { status: { name: "Running" } },
|
|
||||||
Responsible: { people: [{ object: "user", id: userId }] },
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+120
-20
@@ -1,4 +1,4 @@
|
|||||||
const CURRENT_VERSION = "1.0.43";
|
const CURRENT_VERSION = "1.0.65";
|
||||||
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=
|
||||||
@@ -19,13 +19,21 @@ function fetchWithTimeout(url: string): Promise<Response> {
|
|||||||
return fetch(url, { signal: controller.signal }).finally(() => clearTimeout(timer));
|
return fetch(url, { signal: controller.signal }).finally(() => clearTimeout(timer));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkForUpdates(sendStatus?: (msg: string) => void): Promise<void> {
|
async function checkForUpdates(sendStatus?: (msg: string) => void | Promise<void>): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const resp = await fetchWithTimeout(`${GITEA_BASE}/version.json`);
|
const resp = await fetchWithTimeout(`${GITEA_BASE}/version.json`);
|
||||||
if (!resp.ok) { sendStatus?.("Update check failed"); return; }
|
if (!resp.ok) {
|
||||||
|
streamDeck.logger.warn(`Update check: version.json fetch returned ${resp.status}`);
|
||||||
|
sendStatus?.("Update check failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
const { version } = await resp.json() as { version: string };
|
const { version } = await resp.json() as { version: string };
|
||||||
if (!/^\d+\.\d+\.\d+$/.test(version)) return;
|
if (!/^\d+\.\d+\.\d+$/.test(version)) {
|
||||||
|
streamDeck.logger.warn(`Update check: version.json had unexpected content: ${JSON.stringify(version)}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!isNewerVersion(version, CURRENT_VERSION)) {
|
if (!isNewerVersion(version, CURRENT_VERSION)) {
|
||||||
|
streamDeck.logger.info(`Update check: up to date (v${CURRENT_VERSION}, server has v${version})`);
|
||||||
sendStatus?.(`Already up to date (v${CURRENT_VERSION})`);
|
sendStatus?.(`Already up to date (v${CURRENT_VERSION})`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -73,6 +81,11 @@ async function checkForUpdates(sendStatus?: (msg: string) => void): Promise<void
|
|||||||
|
|
||||||
fs.writeFileSync(__filename, newCode);
|
fs.writeFileSync(__filename, newCode);
|
||||||
streamDeck.logger.info(`Updated to ${version}, restarting…`);
|
streamDeck.logger.info(`Updated to ${version}, restarting…`);
|
||||||
|
// Await + a short delay so the message actually reaches the socket before
|
||||||
|
// the process dies. The panel can't reliably learn its own new version
|
||||||
|
// number after this restart, so it just tells the user how to confirm it.
|
||||||
|
await sendStatus?.(`Updated to v${version}. Click any other button above to confirm version update has been successful.`);
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 200));
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const msg = err instanceof Error ? err.message : String(err);
|
const msg = err instanceof Error ? err.message : String(err);
|
||||||
@@ -88,7 +101,7 @@ import streamDeck, {
|
|||||||
SingletonAction,
|
SingletonAction,
|
||||||
WillAppearEvent,
|
WillAppearEvent,
|
||||||
} from "@elgato/streamdeck";
|
} from "@elgato/streamdeck";
|
||||||
import { fetchProjects, fetchUsers, startTimer, stopTimer } from "./notion.js";
|
import { fetchProjects, fetchTagOptions, fetchUsers, startTimer, stopTimer } from "./notion.js";
|
||||||
|
|
||||||
interface GlobalSettings {
|
interface GlobalSettings {
|
||||||
notionToken: string;
|
notionToken: string;
|
||||||
@@ -102,6 +115,9 @@ interface GlobalSettings {
|
|||||||
interface TimerSettings {
|
interface TimerSettings {
|
||||||
projectId: string;
|
projectId: string;
|
||||||
projectName: string;
|
projectName: string;
|
||||||
|
tag?: string;
|
||||||
|
tagEnabled?: boolean;
|
||||||
|
askDescription?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const HARDCODED = {
|
const HARDCODED = {
|
||||||
@@ -109,6 +125,8 @@ const HARDCODED = {
|
|||||||
projectsDbId: "cd65c760-0f0a-4d6e-a262-d572c9e31585",
|
projectsDbId: "cd65c760-0f0a-4d6e-a262-d572c9e31585",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const DEFAULT_TAG = "Client Books";
|
||||||
|
|
||||||
async function getGlobal(): Promise<GlobalSettings> {
|
async function getGlobal(): Promise<GlobalSettings> {
|
||||||
const stored = await streamDeck.settings.getGlobalSettings<GlobalSettings>();
|
const stored = await streamDeck.settings.getGlobalSettings<GlobalSettings>();
|
||||||
return { ...stored, ...HARDCODED };
|
return { ...stored, ...HARDCODED };
|
||||||
@@ -142,14 +160,18 @@ async function sendProjectsToPI(tokenOverride?: string): Promise<void> {
|
|||||||
await streamDeck.ui.sendToPropertyInspector({ event: "projects", data: [], error: "Enter your Notion API token above.", version: CURRENT_VERSION });
|
await streamDeck.ui.sendToPropertyInspector({ event: "projects", data: [], error: "Enter your Notion API token above.", version: CURRENT_VERSION });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const [projects, usersResult] = await Promise.all([
|
const [projects, usersResult, tagsResult] = await Promise.all([
|
||||||
fetchProjects(token, global.projectsDbId),
|
fetchProjects(token, global.projectsDbId),
|
||||||
fetchUsers(token).catch((err) => {
|
fetchUsers(token).catch((err) => {
|
||||||
streamDeck.logger.error("Failed to fetch users:", err);
|
streamDeck.logger.error("Failed to fetch users:", err);
|
||||||
return [];
|
return [];
|
||||||
}),
|
}),
|
||||||
|
fetchTagOptions(token, global.timingDbId, "Timer Tags").catch((err) => {
|
||||||
|
streamDeck.logger.error("Failed to fetch tag options:", err);
|
||||||
|
return [];
|
||||||
|
}),
|
||||||
]);
|
]);
|
||||||
await streamDeck.ui.sendToPropertyInspector({ event: "projects", data: projects, users: usersResult, version: CURRENT_VERSION });
|
await streamDeck.ui.sendToPropertyInspector({ event: "projects", data: projects, users: usersResult, tags: tagsResult, version: CURRENT_VERSION });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
streamDeck.logger.error("Failed to fetch projects:", err);
|
streamDeck.logger.error("Failed to fetch projects:", err);
|
||||||
await streamDeck.ui.sendToPropertyInspector({ event: "projects", data: [], error: String(err), version: CURRENT_VERSION });
|
await streamDeck.ui.sendToPropertyInspector({ event: "projects", data: [], error: String(err), version: CURRENT_VERSION });
|
||||||
@@ -160,8 +182,9 @@ function isConfigured(g: GlobalSettings): boolean {
|
|||||||
return !!(g.notionToken && g.userId);
|
return !!(g.notionToken && g.userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
function buttonTitle(projectName: string): string {
|
function buttonTitle(projectName: string, tag?: string): string {
|
||||||
return projectName.replace(/^[\p{Extended_Pictographic}\uFE0F\s]+/u, "").trim();
|
const base = projectName.replace(/^[\p{Extended_Pictographic}\uFE0F\s]+/u, "").trim();
|
||||||
|
return tag ? `${base} \u00B7 ${tag}` : base;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ELAPSED_CHECK_MS = 60 * 60 * 1000; // 1 hour
|
const ELAPSED_CHECK_MS = 60 * 60 * 1000; // 1 hour
|
||||||
@@ -179,6 +202,25 @@ async function promptContinue(title: string): Promise<"stop" | "continue" | "tim
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cancelling or letting the dialog time out means "don't start the timer" —
|
||||||
|
// the caller treats ok:false as a no-op, not as "start with no description".
|
||||||
|
async function promptDescription(title: string): Promise<{ ok: boolean; text: string }> {
|
||||||
|
const { execFile } = await import("node:child_process");
|
||||||
|
const safeTitle = title.replace(/[\\"]/g, "");
|
||||||
|
const script = `display dialog "Description for ${safeTitle} (optional):" default answer "" buttons {"Cancel", "Start"} default button "Start" giving up after ${DIALOG_TIMEOUT_SECONDS}`;
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
execFile("osascript", ["-e", script], (err, stdout) => {
|
||||||
|
const out = String(stdout);
|
||||||
|
if (err || /gave up:true/.test(out) || !/button returned:Start/.test(out)) {
|
||||||
|
resolve({ ok: false, text: "" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const match = /text returned:(.*?)(?:, gave up:|$)/.exec(out);
|
||||||
|
resolve({ ok: true, text: match ? match[1].trim() : "" });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@action({ UUID: "com.pdma.notion-timer.toggle" })
|
@action({ UUID: "com.pdma.notion-timer.toggle" })
|
||||||
class TimerToggle extends SingletonAction<TimerSettings> {
|
class TimerToggle extends SingletonAction<TimerSettings> {
|
||||||
private projectCache = new Map<string, TimerSettings>();
|
private projectCache = new Map<string, TimerSettings>();
|
||||||
@@ -225,7 +267,7 @@ class TimerToggle extends SingletonAction<TimerSettings> {
|
|||||||
|
|
||||||
async onWillAppear(ev: WillAppearEvent<TimerSettings>): Promise<void> {
|
async onWillAppear(ev: WillAppearEvent<TimerSettings>): Promise<void> {
|
||||||
this.projectCache.set(ev.action.id, ev.payload.settings);
|
this.projectCache.set(ev.action.id, ev.payload.settings);
|
||||||
const title = buttonTitle(ev.payload.settings.projectName || "");
|
const title = buttonTitle(ev.payload.settings.projectName || "", ev.payload.settings.tag);
|
||||||
await loadRunningState();
|
await loadRunningState();
|
||||||
const isRunning = memRunningActionId === ev.action.id;
|
const isRunning = memRunningActionId === ev.action.id;
|
||||||
if (isRunning) {
|
if (isRunning) {
|
||||||
@@ -246,9 +288,12 @@ class TimerToggle extends SingletonAction<TimerSettings> {
|
|||||||
if (this.keyDownBusy) {
|
if (this.keyDownBusy) {
|
||||||
// Blocked press: redraw THIS button to match known truth instead of leaving
|
// Blocked press: redraw THIS button to match known truth instead of leaving
|
||||||
// whatever it was already showing (which can be stale from an out-of-band
|
// whatever it was already showing (which can be stale from an out-of-band
|
||||||
// Notion edit) — a pure visual correction, no Notion calls.
|
// Notion edit) — a pure visual correction, no Notion calls. Delayed slightly
|
||||||
const title = buttonTitle(ev.payload.settings.projectName || "");
|
// because redrawing immediately can collide with Stream Deck's own native
|
||||||
|
// key-press flash animation and get silently dropped.
|
||||||
|
const title = buttonTitle(ev.payload.settings.projectName || "", ev.payload.settings.tag);
|
||||||
const shouldBeRunning = memRunningActionId === ev.action.id;
|
const shouldBeRunning = memRunningActionId === ev.action.id;
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 150));
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
ev.action.setState(shouldBeRunning ? 1 : 0),
|
ev.action.setState(shouldBeRunning ? 1 : 0),
|
||||||
ev.action.setTitle(shouldBeRunning ? `⏱ ${title}` : title),
|
ev.action.setTitle(shouldBeRunning ? `⏱ ${title}` : title),
|
||||||
@@ -257,10 +302,20 @@ class TimerToggle extends SingletonAction<TimerSettings> {
|
|||||||
}
|
}
|
||||||
this.keyDownBusy = true;
|
this.keyDownBusy = true;
|
||||||
try {
|
try {
|
||||||
const { projectId, projectName } = ev.payload.settings;
|
const { projectId, projectName, tag, askDescription } = ev.payload.settings;
|
||||||
const title = buttonTitle(projectName || "");
|
const title = buttonTitle(projectName || "", tag);
|
||||||
const isRunning = memRunningActionId === ev.action.id;
|
const isRunning = memRunningActionId === ev.action.id;
|
||||||
|
|
||||||
|
// Asking for a description blocks on a native dialog, so it has to happen
|
||||||
|
// before any optimistic UI update — a cancel/timeout must leave everything
|
||||||
|
// exactly as it was, not flip the button and then silently revert it.
|
||||||
|
let description = "";
|
||||||
|
if (!isRunning && projectId && askDescription) {
|
||||||
|
const result = await promptDescription(title);
|
||||||
|
if (!result.ok) return;
|
||||||
|
description = result.text;
|
||||||
|
}
|
||||||
|
|
||||||
// Instant visual feedback — no setSettings, no flash
|
// Instant visual feedback — no setSettings, no flash
|
||||||
if (projectId) {
|
if (projectId) {
|
||||||
if (isRunning) {
|
if (isRunning) {
|
||||||
@@ -270,7 +325,7 @@ class TimerToggle extends SingletonAction<TimerSettings> {
|
|||||||
if (other.id === ev.action.id) continue;
|
if (other.id === ev.action.id) continue;
|
||||||
if (memRunningActionId === other.id) {
|
if (memRunningActionId === other.id) {
|
||||||
const s = this.projectCache.get(other.id);
|
const s = this.projectCache.get(other.id);
|
||||||
await Promise.all([other.setState(0), other.setTitle(buttonTitle(s?.projectName || ""))]);
|
await Promise.all([other.setState(0), other.setTitle(buttonTitle(s?.projectName || "", s?.tag))]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await Promise.all([ev.action.setState(1), ev.action.setTitle(`⏱ ${title}`)]);
|
await Promise.all([ev.action.setState(1), ev.action.setTitle(`⏱ ${title}`)]);
|
||||||
@@ -283,16 +338,29 @@ class TimerToggle extends SingletonAction<TimerSettings> {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (isRunning) {
|
if (isRunning) {
|
||||||
await stopTimer(global.notionToken, memRunningEntryId!);
|
// Stopping the entry in Notion is best-effort: if the page is already
|
||||||
|
// gone/archived (e.g. edited outside the plugin) this throws, but the
|
||||||
|
// local "running" tracking must clear anyway or every future keypress
|
||||||
|
// retries this same doomed stop call and the deck gets stuck forever.
|
||||||
|
try {
|
||||||
|
await stopTimer(global.notionToken, memRunningEntryId!);
|
||||||
|
} catch (err) {
|
||||||
|
streamDeck.logger.error("Failed to stop timer in Notion (clearing local state anyway):", err);
|
||||||
|
}
|
||||||
setRunningEntry(null, null);
|
setRunningEntry(null, null);
|
||||||
this.clearElapsedCheck();
|
this.clearElapsedCheck();
|
||||||
await Promise.all([ev.action.setState(0), ev.action.setTitle(title)]);
|
await Promise.all([ev.action.setState(0), ev.action.setTitle(title)]);
|
||||||
} else {
|
} else {
|
||||||
if (memRunningEntryId) {
|
if (memRunningEntryId) {
|
||||||
await stopTimer(global.notionToken, memRunningEntryId);
|
try {
|
||||||
|
await stopTimer(global.notionToken, memRunningEntryId);
|
||||||
|
} catch (err) {
|
||||||
|
streamDeck.logger.error("Failed to stop previous timer in Notion (clearing local state anyway):", err);
|
||||||
|
}
|
||||||
|
setRunningEntry(null, null);
|
||||||
this.clearElapsedCheck();
|
this.clearElapsedCheck();
|
||||||
}
|
}
|
||||||
const entryId = await startTimer(global.notionToken, global.timingDbId, projectId, projectName, global.userId);
|
const entryId = await startTimer(global.notionToken, global.timingDbId, projectId, projectName, global.userId, tag || DEFAULT_TAG, description);
|
||||||
setRunningEntry(entryId, ev.action.id);
|
setRunningEntry(entryId, ev.action.id);
|
||||||
this.scheduleElapsedCheck(entryId, ev.action.id, title);
|
this.scheduleElapsedCheck(entryId, ev.action.id, title);
|
||||||
await Promise.all([ev.action.setState(1), ev.action.setTitle(`⏱ ${title}`)]);
|
await Promise.all([ev.action.setState(1), ev.action.setTitle(`⏱ ${title}`)]);
|
||||||
@@ -312,13 +380,36 @@ class TimerToggle extends SingletonAction<TimerSettings> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const NEXTCLOUD_BIN = "/Applications/Nextcloud.app/Contents/MacOS/Nextcloud";
|
||||||
|
|
||||||
|
@action({ UUID: "com.pdma.notion-timer.launch-nextcloud" })
|
||||||
|
class LaunchNextcloud extends SingletonAction {
|
||||||
|
async onKeyDown(ev: KeyDownEvent): Promise<void> {
|
||||||
|
try {
|
||||||
|
const { spawn } = await import("node:child_process");
|
||||||
|
const child = spawn(NEXTCLOUD_BIN, [], { detached: true, stdio: "ignore" });
|
||||||
|
// "error" (e.g. ENOENT if Nextcloud isn't installed at this path) fires
|
||||||
|
// asynchronously — without this listener it would crash the plugin process.
|
||||||
|
child.once("error", (err) => {
|
||||||
|
streamDeck.logger.error("Failed to launch Nextcloud:", err);
|
||||||
|
});
|
||||||
|
child.unref();
|
||||||
|
await ev.action.showOk();
|
||||||
|
} catch (err) {
|
||||||
|
streamDeck.logger.error("Failed to launch Nextcloud:", err);
|
||||||
|
await ev.action.showAlert();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const timerAction = new TimerToggle();
|
const timerAction = new TimerToggle();
|
||||||
streamDeck.actions.registerAction(timerAction);
|
streamDeck.actions.registerAction(timerAction);
|
||||||
|
streamDeck.actions.registerAction(new LaunchNextcloud());
|
||||||
|
|
||||||
streamDeck.ui.onSendToPlugin<{ event: string; settings?: TimerSettings; token?: string }>(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 || "", ev.payload.settings.tag);
|
||||||
if (title) await ev.action.setTitle(title);
|
if (title) await ev.action.setTitle(title);
|
||||||
}
|
}
|
||||||
if (ev.payload.event === "refreshProjects") {
|
if (ev.payload.event === "refreshProjects") {
|
||||||
@@ -331,6 +422,15 @@ streamDeck.ui.onSendToPlugin<{ event: string; settings?: TimerSettings; token?:
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const UPDATE_CHECK_INTERVAL_MS = 30 * 60 * 1000; // 30 minutes
|
||||||
|
|
||||||
streamDeck.connect();
|
streamDeck.connect();
|
||||||
|
|
||||||
setTimeout(() => checkForUpdates(), 10_000);
|
setTimeout(() => {
|
||||||
|
streamDeck.logger.info("Running initial (10s post-launch) update check");
|
||||||
|
checkForUpdates();
|
||||||
|
}, 10_000);
|
||||||
|
setInterval(() => {
|
||||||
|
streamDeck.logger.info("Running scheduled (30min) update check");
|
||||||
|
checkForUpdates();
|
||||||
|
}, UPDATE_CHECK_INTERVAL_MS);
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
{ "version": "1.0.43" }
|
{ "version": "1.0.65" }
|
||||||
|
|||||||
Reference in New Issue
Block a user