Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/release-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
25 changes: 25 additions & 0 deletions src/main/pure-utils.ts
Original file line number Diff line number Diff line change
@@ -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) + "…";
}
37 changes: 3 additions & 34 deletions src/main/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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,
};
13 changes: 13 additions & 0 deletions tests/main/test_pure-utils.ts
Original file line number Diff line number Diff line change
@@ -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…",
);
});
});
15 changes: 0 additions & 15 deletions tests/main/test_utils.ts

This file was deleted.

Loading