v1.0.16: manual update button in property inspector
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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 SIGNING_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
|
||||
MCowBQYDK2VwAyEAN7ko8TUpuPzPAJuKAZCRjV0c4ZSlou5d9pUAF6o12b4=
|
||||
@@ -19,19 +19,23 @@ function fetchWithTimeout(url: string): Promise<Response> {
|
||||
return fetch(url, { signal: controller.signal }).finally(() => clearTimeout(timer));
|
||||
}
|
||||
|
||||
async function checkForUpdates(): Promise<void> {
|
||||
async function checkForUpdates(sendStatus?: (msg: string) => void): Promise<void> {
|
||||
try {
|
||||
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 };
|
||||
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([
|
||||
fetchWithTimeout(`${GITEA_BASE}/com.pdma.notion-timer.sdPlugin/bin/plugin.js`),
|
||||
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 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);
|
||||
if (!valid) {
|
||||
streamDeck.logger.error("Update rejected: signature verification failed");
|
||||
sendStatus?.("Update rejected: invalid signature");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -48,7 +53,9 @@ async function checkForUpdates(): Promise<void> {
|
||||
streamDeck.logger.info(`Updated to ${version}, restarting…`);
|
||||
process.exit(0);
|
||||
} 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 || "");
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user