From 0b351d6184fa955ffa07108da5120c30b00a576b Mon Sep 17 00:00:00 2001 From: CrystalSplitter Date: Fri, 26 Jun 2026 12:11:52 -0700 Subject: [PATCH 1/2] Update github workflows to node 24 Related to Issue #176. --- .github/workflows/release-linux.yml | 4 ++-- .github/workflows/release-macos.yml | 4 ++-- .github/workflows/release-windows.yml | 4 ++-- .github/workflows/test-linux.yml | 8 ++++---- .github/workflows/test-macos.yml | 4 ++-- .github/workflows/test-windows.yml | 4 ++-- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/workflows/release-linux.yml b/.github/workflows/release-linux.yml index 488b1b7f..73dc5dec 100644 --- a/.github/workflows/release-linux.yml +++ b/.github/workflows/release-linux.yml @@ -13,9 +13,9 @@ jobs: steps: - uses: "actions/checkout@v5" - name: "Set Up Node" - uses: "actions/setup-node@v4" + uses: "actions/setup-node@v6" with: - node-version: "22.x" + node-version: "24.x" cache: "npm" - run: "npm ci" - run: "npm run build" diff --git a/.github/workflows/release-macos.yml b/.github/workflows/release-macos.yml index db84e53c..ff5df00e 100644 --- a/.github/workflows/release-macos.yml +++ b/.github/workflows/release-macos.yml @@ -13,9 +13,9 @@ jobs: steps: - uses: "actions/checkout@v5" - name: "Set Up Node" - uses: "actions/setup-node@v4" + uses: "actions/setup-node@v6" with: - node-version: "22.x" + node-version: "24.x" cache: "npm" - run: "npm ci" - run: "npm run build" diff --git a/.github/workflows/release-windows.yml b/.github/workflows/release-windows.yml index 772654e0..e2997f7b 100644 --- a/.github/workflows/release-windows.yml +++ b/.github/workflows/release-windows.yml @@ -13,9 +13,9 @@ jobs: steps: - uses: "actions/checkout@v5" - name: "Set Up Node" - uses: "actions/setup-node@v4" + uses: "actions/setup-node@v6" with: - node-version: "22.x" + node-version: "24.x" cache: "npm" - run: "npm ci" - run: "npm run build" diff --git a/.github/workflows/test-linux.yml b/.github/workflows/test-linux.yml index b6b5761b..f8420340 100644 --- a/.github/workflows/test-linux.yml +++ b/.github/workflows/test-linux.yml @@ -11,9 +11,9 @@ jobs: steps: - uses: "actions/checkout@v5" - name: "Set Up Node" - uses: "actions/setup-node@v4" + uses: "actions/setup-node@v6" with: - node-version: "22.x" + node-version: "24.x" cache: "npm" - run: "npm ci" - run: "npm run build" @@ -24,9 +24,9 @@ jobs: steps: - uses: "actions/checkout@v5" - name: "Build Debian Package" - uses: "actions/setup-node@v4" + uses: "actions/setup-node@v6" with: - node-version: "22.x" + node-version: "24.x" cache: "npm" - run: "npm ci" - run: "npm run build" diff --git a/.github/workflows/test-macos.yml b/.github/workflows/test-macos.yml index 1fc86876..d9e6d6ce 100644 --- a/.github/workflows/test-macos.yml +++ b/.github/workflows/test-macos.yml @@ -11,9 +11,9 @@ jobs: steps: - uses: "actions/checkout@v5" - name: "Set Up Node" - uses: "actions/setup-node@v4" + uses: "actions/setup-node@v6" with: - node-version: "22.x" + node-version: "24.x" cache: "npm" - run: "npm ci" - run: "npm run build" diff --git a/.github/workflows/test-windows.yml b/.github/workflows/test-windows.yml index 47163c29..8cf925d0 100644 --- a/.github/workflows/test-windows.yml +++ b/.github/workflows/test-windows.yml @@ -11,9 +11,9 @@ jobs: steps: - uses: "actions/checkout@v5" - name: "Set Up Node" - uses: "actions/setup-node@v4" + uses: "actions/setup-node@v6" with: - node-version: "22.x" + node-version: "24.x" - run: "npm ci" - run: "npm run build" - run: "npm run test" From cdbf6c55066b8860da516d05b05164dc4fb3ad7e Mon Sep 17 00:00:00 2001 From: CrystalSplitter Date: Fri, 26 Jun 2026 17:43:56 -0700 Subject: [PATCH 2/2] Move non-electron main utils out of utils.ts utils.ts is a very poorly named library, as it primarily exists for various bridge calls between the renderer and the main process. Whereas, we actually would like some utility functions that have relatively few (if any) dependencies, so that we may test them better with a node runtime. This is necessary for us to use mocha for newer NPMs, as build dependencies are not shaken consistently across newer NPMs. --- src/main/pure-utils.ts | 25 +++++++++++++++++++++++ src/main/utils.ts | 37 +++-------------------------------- tests/main/test_pure-utils.ts | 13 ++++++++++++ tests/main/test_utils.ts | 15 -------------- 4 files changed, 41 insertions(+), 49 deletions(-) create mode 100644 src/main/pure-utils.ts create mode 100644 tests/main/test_pure-utils.ts delete mode 100644 tests/main/test_utils.ts diff --git a/src/main/pure-utils.ts b/src/main/pure-utils.ts new file mode 100644 index 00000000..4cd81a71 --- /dev/null +++ b/src/main/pure-utils.ts @@ -0,0 +1,25 @@ +/** Ensure we don't have too long of a message. */ +export function trimContent( + s: string, + charLen: number = 512, + lineLen: number = 5, +): string { + return limitLines(trimString(s, charLen), lineLen); +} + +function limitLines(s: string, maxLength: number): string { + const splitLines = s.split("\n"); + if (splitLines.length <= maxLength) { + return s; + } + const newLines = splitLines.slice(0, maxLength - 1); + newLines.push("…more lines…"); + return newLines.join("\n"); +} + +export function trimString(s: string, maxLength: number): string { + if (s.length <= maxLength) { + return s; + } + return s.substring(0, maxLength - 1) + "…"; +} diff --git a/src/main/utils.ts b/src/main/utils.ts index dfef8ce9..f0878b1b 100644 --- a/src/main/utils.ts +++ b/src/main/utils.ts @@ -7,8 +7,9 @@ import { clipboard, systemPreferences, } from "electron"; -import { version } from "../../package.json"; +import pkg from "../../package.json"; import { WindowManager } from "./window"; +import { trimContent, trimString } from "./pure-utils"; import { promises, writeFile } from "fs"; import { ImageCallbackTypes, TouchBarTexts } from "../schema-types"; import { initMainTouchBar } from "./touchbar"; @@ -50,7 +51,7 @@ export function setUtilsListeners(manager: WindowManager) { }); ipcMain.on("get-version", (event) => { - event.returnValue = version; + event.returnValue = pkg.version; }); ipcMain.handle("open-external", (_, url: string, background: boolean) => { @@ -336,35 +337,3 @@ export function setUtilsListeners(manager: WindowManager) { event.returnValue = manager.args; }); } - -/** Ensure we don't have too long of a message. */ -function trimContent( - s: string, - charLen: number = 512, - lineLen: number = 5, -): string { - return limitLines(trimString(s, charLen), lineLen); -} - -function limitLines(s: string, maxLength: number): string { - const splitLines = s.split("\n"); - if (splitLines.length <= maxLength) { - return s; - } - const newLines = splitLines.slice(0, maxLength - 1); - newLines.push("…more lines…"); - return newLines.join("\n"); -} - -function trimString(s: string, maxLength: number): string { - if (s.length <= maxLength) { - return s; - } - return s.substring(0, maxLength - 1) + "…"; -} - -export const exportedForTesting = { - trimContent: trimContent, - limitLines: limitLines, - trimString: trimString, -}; diff --git a/tests/main/test_pure-utils.ts b/tests/main/test_pure-utils.ts new file mode 100644 index 00000000..b4117cf3 --- /dev/null +++ b/tests/main/test_pure-utils.ts @@ -0,0 +1,13 @@ +import { expect } from "chai"; +import { trimContent } from "../../src/main/pure-utils"; + +describe("dialog trimming", () => { + it("trims long words", () => { + expect(trimContent("M".repeat(1000))).to.equal("M".repeat(511) + "…"); + }); + it("trims too many lines", () => { + expect(trimContent("M\n".repeat(10))).to.equal( + "M\n".repeat(4) + "…more lines…", + ); + }); +}); diff --git a/tests/main/test_utils.ts b/tests/main/test_utils.ts deleted file mode 100644 index ac826e9b..00000000 --- a/tests/main/test_utils.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { expect } from "chai"; -import { exportedForTesting } from "../../src/main/utils"; - -describe("dialog trimming", () => { - it("trims long words", () => { - expect(exportedForTesting.trimContent("M".repeat(1000))).to.equal( - "M".repeat(511) + "…", - ); - }); - it("trims too many lines", () => { - expect(exportedForTesting.trimContent("M\n".repeat(10))).to.equal( - "M\n".repeat(4) + "…more lines…", - ); - }); -});