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" 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…", - ); - }); -});