Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

fix: walk GitHub release pages for prefix tags (#2147)

Po-Han (Stan) Shih · 施博瀚f770e9211719
diff --git a/.github/workflows/build-and-notarize.yml b/.github/workflows/build-and-notarize.yml
index 64034eddc..9f669a4d9 100644
--- a/.github/workflows/build-and-notarize.yml
+++ b/.github/workflows/build-and-notarize.yml
@@ -229,11 +229,6 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
- - name: Download windows-key-listener.exe
- run: node scripts/download-windows-key-listener.js
- env:
- GITHUB_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
-
- name: Compile windows-mic-listener.exe
shell: cmd
run: |
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index f526445a8..2463e9dba 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -214,11 +214,6 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
- - name: Download windows-key-listener.exe
- run: node scripts/download-windows-key-listener.js
- env:
- GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
-
- name: Compile windows-mic-listener.exe
shell: cmd
run: |
diff --git a/CLAUDE.md b/CLAUDE.md
index 83853d47f..082583da6 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -891,7 +891,7 @@ UI icons come from `src/components/icons/` (vendored Nucleo core outline compone
5. **Windows Push-to-Talk Binary**:
- Prebuilt binary downloaded automatically on Windows during build
- - If download fails, push-to-talk falls back to tap mode
+ - If neither compiling nor the download produces it, `afterPack.js` fails the Windows build
- To compile locally: install Visual Studio Build Tools or MinGW-w64
- CI workflow (`.github/workflows/build-windows-key-listener.yml`) auto-builds on push to main
diff --git a/scripts/afterPack.js b/scripts/afterPack.js
index f5aace49d..d9c6536b3 100644
--- a/scripts/afterPack.js
+++ b/scripts/afterPack.js
@@ -254,6 +254,18 @@ function verifyWindowsOnnxRuntimePrivatized(binDir) {
}
}
+// compile:winkeys and download:windows-key-listener only warn when they can't
+// produce the key listener, so without this check a build ships where Hold and
+// modifier-only hotkeys (the default Control+Super) never fire (#2005).
+function verifyWindowsKeyListener(binDir) {
+ const listenerPath = path.join(binDir, "windows-key-listener.exe");
+ if (!fs.existsSync(listenerPath)) {
+ throw new Error(
+ `afterPack: missing ${listenerPath} — run npm run compile:winkeys on Windows (compiles with MSVC, MinGW or Clang, or downloads the prebuilt binary); Push-to-Talk and modifier-only hotkeys would never fire on Windows`
+ );
+ }
+}
+
function verifyUnpackedBinaries(context) {
const unpackedDir = path.join(resolveResourcesDir(context), "app.asar.unpacked");
const unpackedModulesDir = path.join(unpackedDir, "node_modules");
@@ -290,7 +302,9 @@ function verifyUnpackedBinaries(context) {
`afterPack: no fastlist-*.exe in ${psListVendorDir} — ps-list vendor executable was not unpacked from app.asar (asarUnpack/packaging failure); Windows process detection would break`
);
}
- verifyWindowsOnnxRuntimePrivatized(path.join(resolveResourcesDir(context), "bin"));
+ const binDir = path.join(resolveResourcesDir(context), "bin");
+ verifyWindowsOnnxRuntimePrivatized(binDir);
+ verifyWindowsKeyListener(binDir);
}
console.log(" afterPack: verified unpacked bundled binaries");
@@ -309,3 +323,4 @@ exports.default = async function (context) {
};
exports.verifyWindowsOnnxRuntimePrivatized = verifyWindowsOnnxRuntimePrivatized;
+exports.verifyWindowsKeyListener = verifyWindowsKeyListener;
diff --git a/scripts/download-windows-key-listener.js b/scripts/download-windows-key-listener.js
index 2b60eca07..745fb94ca 100644
--- a/scripts/download-windows-key-listener.js
+++ b/scripts/download-windows-key-listener.js
@@ -120,7 +120,7 @@ async function main() {
fs.unlinkSync(zipPath);
}
- // Don't fail the build - Push-to-Talk can fall back to tap mode
+ // Don't fail here: afterPack stops a Windows build that lacks the listener
console.log(
"[windows-key-listener] Push-to-Talk will use fallback mode (compile locally or tap mode)"
);
diff --git a/scripts/lib/download-utils.js b/scripts/lib/download-utils.js
index 7e197b316..3060e6f96 100644
--- a/scripts/lib/download-utils.js
+++ b/scripts/lib/download-utils.js
@@ -7,6 +7,8 @@ const REQUEST_TIMEOUT = 30000;
const MAX_RETRIES = 3;
const RETRY_DELAY = 2000;
const MAX_REDIRECTS = 5;
+const RELEASE_PAGE_SIZE = 100;
+const MAX_RELEASE_PAGES = 20;
// Node's global agent keeps sockets alive, and a socket only returns to the pool (where it
// stops holding the event loop open) once its response has been read to the end. A redirect
@@ -16,12 +18,12 @@ function discardBody(response) {
}
/**
- * Fetch JSON from a URL with proper error handling.
+ * Fetch JSON and response headers from a URL.
* @param {string} url - URL to fetch
* @param {number} [redirectCount=0] - Current redirect count (internal use)
- * @returns {Promise<object>} - Parsed JSON response
+ * @returns {Promise<{json: object, headers: object}>}
*/
-function fetchJson(url, redirectCount = 0) {
+function fetchJsonResponse(url, redirectCount = 0) {
return new Promise((resolve, reject) => {
if (redirectCount > MAX_REDIRECTS) {
reject(new Error("Too many redirects"));
@@ -54,7 +56,7 @@ function fetchJson(url, redirectCount = 0) {
return;
}
const redirectUrl = location.startsWith("/") ? new URL(location, url).href : location;
- fetchJson(redirectUrl, redirectCount + 1)
+ fetchJsonResponse(redirectUrl, redirectCount + 1)
.then(resolve)
.catch(reject);
return;
@@ -70,7 +72,7 @@ function fetchJson(url, redirectCount = 0) {
res.on("data", (chunk) => (data += chunk));
res.on("end", () => {
try {
- resolve(JSON.parse(data));
+ resolve({ json: JSON.parse(data), headers: res.headers });
} catch (e) {
reject(new Error(`Failed to parse JSON: ${e.message}`));
}
@@ -85,12 +87,63 @@ function fetchJson(url, redirectCount = 0) {
});
}
+function fetchJson(url) {
+ return fetchJsonResponse(url).then((response) => response.json);
+}
+
+/**
+ * Return the next URL from a GitHub `Link` header, or null when this is the last page.
+ * @param {string | undefined} linkHeader
+ * @returns {string | null}
+ */
+function parseGithubNextLink(linkHeader) {
+ if (!linkHeader) {
+ return null;
+ }
+
+ for (const part of linkHeader.split(",")) {
+ if (!/rel=["']?next["']?/i.test(part)) {
+ continue;
+ }
+ const match = part.match(/<([^>]+)>/);
+ if (match) {
+ return match[1];
+ }
+ }
+
+ return null;
+}
+
+/**
+ * First non-draft release whose tag starts with `tagPrefix`.
+ * GitHub lists releases newest-first, so the first hit is the latest match.
+ * @param {unknown} releases
+ * @param {string} tagPrefix
+ * @param {boolean} includePrerelease
+ * @returns {object | null}
+ */
+function matchReleaseByPrefix(releases, tagPrefix, includePrerelease) {
+ if (!Array.isArray(releases)) {
+ return null;
+ }
+
+ for (const release of releases) {
+ if (release.draft) continue;
+ if (!includePrerelease && release.prerelease) continue;
+ if (release.tag_name && release.tag_name.startsWith(tagPrefix)) {
+ return release;
+ }
+ }
+
+ return null;
+}
+
/**
* Fetch a release from a GitHub repository.
* @param {string} repo - Repository in "owner/repo" format
* @param {object} options - Options
* @param {string} [options.tag] - Exact tag to fetch (works for any release age, no pagination)
- * @param {string} [options.tagPrefix] - Latest release whose tag starts with this prefix (searches the 50 most recent only)
+ * @param {string} [options.tagPrefix] - Latest release whose tag starts with this prefix (walks GitHub release pages)
* @param {boolean} [options.includePrerelease=false] - Include prereleases (tagPrefix only)
* @returns {Promise<{tag: string, assets: Array<{name: string, url: string}>, url: string} | null>}
*/
@@ -110,20 +163,15 @@ async function fetchLatestRelease(repo, options = {}) {
return formatRelease(release);
}
- const url = `https://api.github.com/repos/${repo}/releases?per_page=50`;
- const releases = await fetchJson(url);
-
- if (!Array.isArray(releases)) {
- return null;
- }
+ let pageUrl = `https://api.github.com/repos/${repo}/releases?per_page=${RELEASE_PAGE_SIZE}`;
- // Find the latest release matching the prefix
- for (const release of releases) {
- if (release.draft) continue;
- if (!includePrerelease && release.prerelease) continue;
- if (release.tag_name && release.tag_name.startsWith(tagPrefix)) {
- return formatRelease(release);
+ for (let page = 0; page < MAX_RELEASE_PAGES && pageUrl; page++) {
+ const { json, headers } = await fetchJsonResponse(pageUrl);
+ const match = matchReleaseByPrefix(json, tagPrefix, includePrerelease);
+ if (match) {
+ return formatRelease(match);
}
+ pageUrl = parseGithubNextLink(headers.link);
}
return null;
diff --git a/test/scripts/afterPackWindowsKeyListener.test.js b/test/scripts/afterPackWindowsKeyListener.test.js
new file mode 100644
index 000000000..9554eead8
--- /dev/null
+++ b/test/scripts/afterPackWindowsKeyListener.test.js
@@ -0,0 +1,24 @@
+const test = require("node:test");
+const assert = require("node:assert/strict");
+const fs = require("fs");
+const os = require("os");
+const path = require("path");
+
+const { verifyWindowsKeyListener } = require("../../scripts/afterPack");
+
+function makeBinDir(t) {
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "afterpack-bin-"));
+ t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
+ return dir;
+}
+
+test("passes when the Windows key listener is bundled", (t) => {
+ const dir = makeBinDir(t);
+ fs.writeFileSync(path.join(dir, "windows-key-listener.exe"), "");
+ assert.doesNotThrow(() => verifyWindowsKeyListener(dir));
+});
+
+test("fails when the Windows key listener is missing", (t) => {
+ const dir = makeBinDir(t);
+ assert.throws(() => verifyWindowsKeyListener(dir), /missing .*windows-key-listener\.exe/);
+});
diff --git a/test/scripts/fetchLatestRelease.test.js b/test/scripts/fetchLatestRelease.test.js
new file mode 100644
index 000000000..ea8b79ea3
--- /dev/null
+++ b/test/scripts/fetchLatestRelease.test.js
@@ -0,0 +1,89 @@
+const test = require("node:test");
+const assert = require("node:assert/strict");
+const https = require("https");
+const { EventEmitter } = require("events");
+const { Readable } = require("stream");
+
+const { fetchLatestRelease } = require("../../scripts/lib/download-utils");
+
+const REPO = "OpenWhispr/openwhispr";
+const FIRST_PAGE = `https://api.github.com/repos/${REPO}/releases?per_page=100`;
+const SECOND_PAGE = `${FIRST_PAGE}&page=2`;
+const LAST_PAGE = `${FIRST_PAGE}&page=3`;
+
+// Answer https.get the way the GitHub API does: a JSON page and, when more
+// pages follow, a `link` header (Node lower-cases header names).
+function serveReleasePages(t, pages) {
+ const requested = [];
+ t.mock.method(https, "get", (url, _options, onResponse) => {
+ requested.push(url);
+ const { releases, link } = pages[url];
+ const response = Readable.from([Buffer.from(JSON.stringify(releases))]);
+ response.statusCode = 200;
+ response.headers = link ? { link } : {};
+ setImmediate(() => onResponse(response));
+ return new EventEmitter();
+ });
+ return requested;
+}
+
+test("follows rel=next past a first page without the prefix", async (t) => {
+ const requested = serveReleasePages(t, {
+ [FIRST_PAGE]: {
+ releases: Array.from({ length: 100 }, (_, i) => ({ tag_name: `v1.${i}.0` })),
+ link: `<${LAST_PAGE}>; rel="last", <${SECOND_PAGE}>; rel="next"`,
+ },
+ [SECOND_PAGE]: {
+ releases: [
+ { tag_name: "v0.9.0" },
+ {
+ tag_name: "windows-key-listener-v1.0.0",
+ html_url: `https://github.com/${REPO}/releases/tag/windows-key-listener-v1.0.0`,
+ assets: [
+ {
+ name: "windows-key-listener-win32-x64.zip",
+ browser_download_url: "https://example.test/key.zip",
+ },
+ ],
+ },
+ ],
+ },
+ });
+
+ const release = await fetchLatestRelease(REPO, { tagPrefix: "windows-key-listener-v" });
+
+ assert.deepEqual(release, {
+ tag: "windows-key-listener-v1.0.0",
+ url: `https://github.com/${REPO}/releases/tag/windows-key-listener-v1.0.0`,
+ assets: [{ name: "windows-key-listener-win32-x64.zip", url: "https://example.test/key.zip" }],
+ });
+ assert.deepEqual(requested, [FIRST_PAGE, SECOND_PAGE]);
+});
+
+test("skips drafts, and prereleases unless asked for", async (t) => {
+ serveReleasePages(t, {
+ [FIRST_PAGE]: {
+ releases: [
+ { tag_name: "windows-key-listener-v1.2.0", draft: true },
+ { tag_name: "windows-key-listener-v1.1.0-rc", prerelease: true },
+ { tag_name: "windows-key-listener-v1.0.0" },
+ ],
+ },
+ });
+ const options = { tagPrefix: "windows-key-listener-v" };
+
+ assert.equal((await fetchLatestRelease(REPO, options)).tag, "windows-key-listener-v1.0.0");
+ assert.equal(
+ (await fetchLatestRelease(REPO, { ...options, includePrerelease: true })).tag,
+ "windows-key-listener-v1.1.0-rc"
+ );
+});
+
+test("returns null once the last page has no match", async (t) => {
+ const requested = serveReleasePages(t, {
+ [FIRST_PAGE]: { releases: [{ tag_name: "v1.9.3" }] },
+ });
+
+ assert.equal(await fetchLatestRelease(REPO, { tagPrefix: "windows-key-listener-v" }), null);
+ assert.deepEqual(requested, [FIRST_PAGE]);
+});