v1.0.49: fix version auto-refresh by polling from the property inspector

The v1.0.47/48 attempt pushed sendProjectsToPI() from the plugin right
after streamDeck.connect() on startup, assuming that would reach an
already-open panel post-update-restart. It doesn't: per the SDK,
sendToPropertyInspector only delivers 'when the property inspector is
visible for an action provided by this plugin', and that visibility
state is tracked per-process via live didAppear/onSendToPlugin events
-- a freshly restarted process has never received one, so the push was
silently dropped. Confirmed in testing: the panel stayed frozen on
'Updating to vX...' indefinitely.

Removed the ineffective push. Instead, the property inspector's
'Check for Updates' handler now schedules a few refreshProjects
requests (1.5s/3.5s/6s/9s after the click) -- the same proven
PI-initiated round trip already used when entering an API token, which
reliably re-populates the panel including the version text once the
new process comes back up.

Also hardened checkForUpdates(): the final 'Updated to vX --
restarting...' status is now awaited with a short delay before
process.exit(0), best-effort only, since the panel no longer depends
on it arriving.
This commit is contained in:
pdmarf
2026-09-02 11:32:06 +01:00
parent ae230e45ed
commit acf4f98d6b
6 changed files with 28 additions and 14 deletions
+3 -3
View File
@@ -6438,7 +6438,7 @@ async function stopTimer(token, entryId) {
} }
// src/plugin.ts // src/plugin.ts
var CURRENT_VERSION = "1.0.48"; var CURRENT_VERSION = "1.0.49";
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=
@@ -6512,7 +6512,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`);
sendStatus?.(`Updated to v${version} \u2014 restarting\u2026`); await sendStatus?.(`Updated to v${version} \u2014 restarting\u2026`);
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);
@@ -6735,7 +6736,6 @@ plugin_default.ui.onSendToPlugin(async (ev) => {
} }
}); });
plugin_default.connect(); plugin_default.connect();
sendProjectsToPI();
setTimeout(() => checkForUpdates(), 1e4); setTimeout(() => checkForUpdates(), 1e4);
/*! Bundled license information: /*! Bundled license information:
@@ -1 +1 @@
Ïìp ¤i§%C‰ÍY9!qTVa¤'R?@·‰~o‰Ÿ.a' ç_‰CXÜfÉ‚&º”V‡+×} ½Ò␍ sѕЈвтЫв��ЭSЋгњЬuс�ЏIs5nВ�6фљбJхыИZЯХh?Ў�ВЊЙШ��ЉLJVН?1
@@ -176,6 +176,21 @@
el.className = cls || ""; el.className = cls || "";
} }
// The plugin process restarts after an update, and a freshly-restarted
// process has no way to push to an already-open panel (Stream Deck only
// tells a plugin a panel is visible via a live didAppear/onSendToPlugin
// round trip, which a cold-started process hasn't received yet). So the
// panel re-requests the version itself a few times after the restart
// window, instead of waiting on the plugin to notify it.
function pollForVersionRefresh() {
var token = document.getElementById("notionToken").value.trim();
[1500, 3500, 6000, 9000].forEach(function(delay) {
setTimeout(function() {
$PI.sendToPlugin({ event: "refreshProjects", token: token });
}, delay);
});
}
// Collapsible credentials section // Collapsible credentials section
document.getElementById("credToggle").addEventListener("click", function() { document.getElementById("credToggle").addEventListener("click", function() {
var section = document.getElementById("credSection"); var section = document.getElementById("credSection");
@@ -264,6 +279,7 @@
document.getElementById("updateBtn").addEventListener("click", function() { document.getElementById("updateBtn").addEventListener("click", function() {
document.getElementById("updateStatus").textContent = ""; document.getElementById("updateStatus").textContent = "";
$PI.sendToPlugin({ event: "checkForUpdates" }); $PI.sendToPlugin({ event: "checkForUpdates" });
pollForVersionRefresh();
}); });
}); });
Binary file not shown.
+7 -9
View File
@@ -1,4 +1,4 @@
const CURRENT_VERSION = "1.0.48"; const CURRENT_VERSION = "1.0.49";
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,7 +19,7 @@ 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) { sendStatus?.("Update check failed"); return; }
@@ -73,7 +73,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…`);
sendStatus?.(`Updated to v${version} — restarting…`); // Await + a short delay so the message actually reaches the socket before
// the process dies — best-effort only, the property inspector doesn't
// depend on this arriving (it polls for the new version itself).
await sendStatus?.(`Updated to v${version} — restarting…`);
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);
@@ -350,10 +354,4 @@ streamDeck.ui.onSendToPlugin<{ event: string; settings?: TimerSettings; token?:
streamDeck.connect(); streamDeck.connect();
// If a Property Inspector is already open (e.g. it survived the restart
// that just happened after an auto-update), push it the now-current
// version immediately — otherwise it keeps showing the pre-update number
// until the user happens to click a different button and reopens it.
sendProjectsToPI();
setTimeout(() => checkForUpdates(), 10_000); setTimeout(() => checkForUpdates(), 10_000);
+1 -1
View File
@@ -1 +1 @@
{ "version": "1.0.48" } { "version": "1.0.49" }