v1.0.16: manual update button in property inspector

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
pdmarf
2026-04-21 18:32:11 +01:00
parent c1384e942b
commit 4cfe58cde3
6 changed files with 72 additions and 13 deletions

View File

@@ -6438,7 +6438,7 @@ async function stopTimer(token, entryId) {
} }
// src/plugin.ts // src/plugin.ts
var CURRENT_VERSION = "1.0.15"; var CURRENT_VERSION = "1.0.16";
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=
@@ -6456,24 +6456,35 @@ function fetchWithTimeout2(url) {
const timer = setTimeout(() => controller.abort(), 1e4); const timer = setTimeout(() => controller.abort(), 1e4);
return fetch(url, { signal: controller.signal }).finally(() => clearTimeout(timer)); return fetch(url, { signal: controller.signal }).finally(() => clearTimeout(timer));
} }
async function checkForUpdates() { 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) return; if (!resp.ok) {
sendStatus?.("Update check failed");
return;
}
const { version } = await resp.json(); const { version } = await resp.json();
if (!/^\d+\.\d+\.\d+$/.test(version)) return; if (!/^\d+\.\d+\.\d+$/.test(version)) return;
if (!isNewerVersion(version, CURRENT_VERSION)) return; if (!isNewerVersion(version, CURRENT_VERSION)) {
sendStatus?.(`Already up to date (v${CURRENT_VERSION})`);
return;
}
sendStatus?.(`Updating to v${version}\u2026`);
const [pluginResp, sigResp] = await Promise.all([ const [pluginResp, sigResp] = await Promise.all([
fetchWithTimeout2(`${GITEA_BASE}/com.pdma.notion-timer.sdPlugin/bin/plugin.js`), fetchWithTimeout2(`${GITEA_BASE}/com.pdma.notion-timer.sdPlugin/bin/plugin.js`),
fetchWithTimeout2(`${GITEA_BASE}/com.pdma.notion-timer.sdPlugin/bin/plugin.js.sig`) fetchWithTimeout2(`${GITEA_BASE}/com.pdma.notion-timer.sdPlugin/bin/plugin.js.sig`)
]); ]);
if (!pluginResp.ok || !sigResp.ok) return; if (!pluginResp.ok || !sigResp.ok) {
sendStatus?.("Download failed");
return;
}
const newCode = await pluginResp.text(); const newCode = await pluginResp.text();
const sigBytes = Buffer.from(await sigResp.arrayBuffer()); const sigBytes = Buffer.from(await sigResp.arrayBuffer());
const { verify } = await import("node:crypto"); const { verify } = await import("node:crypto");
const valid = verify(null, Buffer.from(newCode), SIGNING_PUBLIC_KEY, sigBytes); const valid = verify(null, Buffer.from(newCode), SIGNING_PUBLIC_KEY, sigBytes);
if (!valid) { if (!valid) {
plugin_default.logger.error("Update rejected: signature verification failed"); plugin_default.logger.error("Update rejected: signature verification failed");
sendStatus?.("Update rejected: invalid signature");
return; return;
} }
const fs3 = await import("fs"); const fs3 = await import("fs");
@@ -6481,7 +6492,9 @@ async function checkForUpdates() {
plugin_default.logger.info(`Updated to ${version}, restarting\u2026`); plugin_default.logger.info(`Updated to ${version}, restarting\u2026`);
process.exit(0); process.exit(0);
} catch (err) { } catch (err) {
plugin_default.logger.error(`Update check failed: ${err instanceof Error ? err.message : String(err)}`); const msg = err instanceof Error ? err.message : String(err);
plugin_default.logger.error(`Update check failed: ${msg}`);
sendStatus?.(`Error: ${msg}`);
} }
} }
var HARDCODED = { var HARDCODED = {
@@ -6621,6 +6634,11 @@ 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 === "checkForUpdates") {
const send = (msg) => plugin_default.ui.sendToPropertyInspector({ event: "updateStatus", message: msg });
send("Checking\u2026");
await checkForUpdates(send);
}
}); });
plugin_default.connect(); plugin_default.connect();
setTimeout(() => checkForUpdates(), 1e4); setTimeout(() => checkForUpdates(), 1e4);

View File

@@ -88,6 +88,26 @@
} }
#credStatus.ok { color: #4caf50; } #credStatus.ok { color: #4caf50; }
#credStatus.error { color: #e57373; } #credStatus.error { color: #e57373; }
#updateBtn {
display: block;
width: 100%;
margin-top: 10px;
padding: 6px;
background: #2a2a2a;
border: 1px solid #444;
border-radius: 4px;
color: #ccc;
font-size: 12px;
cursor: pointer;
}
#updateBtn:hover { background: #333; }
#updateStatus {
font-size: 11px;
color: #888;
text-align: center;
margin-top: 4px;
min-height: 14px;
}
</style> </style>
</head> </head>
<body> <body>
@@ -125,6 +145,8 @@
<p id="statusText"></p> <p id="statusText"></p>
<p id="versionText"></p> <p id="versionText"></p>
<button id="updateBtn">Check for Updates</button>
<p id="updateStatus"></p>
<script src="libs/constants.js"></script> <script src="libs/constants.js"></script>
<script src="libs/prototypes.js"></script> <script src="libs/prototypes.js"></script>
@@ -229,6 +251,10 @@
document.getElementById("projectSelect").addEventListener("change", save); document.getElementById("projectSelect").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("updateStatus").textContent = "";
$PI.sendToPlugin({ event: "checkForUpdates" });
});
}); });
$PI.onDidReceiveGlobalSettings(function(jsn) { $PI.onDidReceiveGlobalSettings(function(jsn) {
@@ -268,6 +294,9 @@
$PI.onSendToPropertyInspector(ACTION_UUID, function(jsn) { $PI.onSendToPropertyInspector(ACTION_UUID, function(jsn) {
var payload = jsn.payload; var payload = jsn.payload;
if (payload.event === "updateStatus") {
document.getElementById("updateStatus").textContent = payload.message;
}
if (payload.event === "projects") { if (payload.event === "projects") {
if (payload.version) { if (payload.version) {
document.getElementById("versionText").textContent = "v" + payload.version; document.getElementById("versionText").textContent = "v" + payload.version;

Binary file not shown.

View File

@@ -1,4 +1,4 @@
const CURRENT_VERSION = "1.0.15"; const CURRENT_VERSION = "1.0.16";
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=
@@ -19,19 +19,23 @@ 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(): Promise<void> { async function checkForUpdates(sendStatus?: (msg: string) => void): Promise<void> {
try { try {
const resp = await fetchWithTimeout(`${GITEA_BASE}/version.json`); const resp = await fetchWithTimeout(`${GITEA_BASE}/version.json`);
if (!resp.ok) return; if (!resp.ok) { 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)) return;
if (!isNewerVersion(version, CURRENT_VERSION)) return; if (!isNewerVersion(version, CURRENT_VERSION)) {
sendStatus?.(`Already up to date (v${CURRENT_VERSION})`);
return;
}
sendStatus?.(`Updating to v${version}`);
const [pluginResp, sigResp] = await Promise.all([ const [pluginResp, sigResp] = await Promise.all([
fetchWithTimeout(`${GITEA_BASE}/com.pdma.notion-timer.sdPlugin/bin/plugin.js`), fetchWithTimeout(`${GITEA_BASE}/com.pdma.notion-timer.sdPlugin/bin/plugin.js`),
fetchWithTimeout(`${GITEA_BASE}/com.pdma.notion-timer.sdPlugin/bin/plugin.js.sig`), fetchWithTimeout(`${GITEA_BASE}/com.pdma.notion-timer.sdPlugin/bin/plugin.js.sig`),
]); ]);
if (!pluginResp.ok || !sigResp.ok) return; if (!pluginResp.ok || !sigResp.ok) { sendStatus?.("Download failed"); return; }
const newCode = await pluginResp.text(); const newCode = await pluginResp.text();
const sigBytes = Buffer.from(await sigResp.arrayBuffer()); const sigBytes = Buffer.from(await sigResp.arrayBuffer());
@@ -40,6 +44,7 @@ async function checkForUpdates(): Promise<void> {
const valid = verify(null, Buffer.from(newCode), SIGNING_PUBLIC_KEY, sigBytes); const valid = verify(null, Buffer.from(newCode), SIGNING_PUBLIC_KEY, sigBytes);
if (!valid) { if (!valid) {
streamDeck.logger.error("Update rejected: signature verification failed"); streamDeck.logger.error("Update rejected: signature verification failed");
sendStatus?.("Update rejected: invalid signature");
return; return;
} }
@@ -48,7 +53,9 @@ async function checkForUpdates(): Promise<void> {
streamDeck.logger.info(`Updated to ${version}, restarting…`); streamDeck.logger.info(`Updated to ${version}, restarting…`);
process.exit(0); process.exit(0);
} catch (err) { } catch (err) {
streamDeck.logger.error(`Update check failed: ${err instanceof Error ? err.message : String(err)}`); const msg = err instanceof Error ? err.message : String(err);
streamDeck.logger.error(`Update check failed: ${msg}`);
sendStatus?.(`Error: ${msg}`);
} }
} }
@@ -235,6 +242,11 @@ 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 === "checkForUpdates") {
const send = (msg: string) => streamDeck.ui.sendToPropertyInspector({ event: "updateStatus", message: msg });
send("Checking…");
await checkForUpdates(send);
}
}); });
streamDeck.connect(); streamDeck.connect();

View File

@@ -1 +1 @@
{ "version": "1.0.15" } { "version": "1.0.16" }