Skip to content

Commit 82bc5b6

Browse files
chore(deps): bump Electron to 44.1.0
Electron 44 turns clipboard.writeText into a Promise and removes clipboard.writeImage in favour of clipboard.write with ClipboardItem, so the shell and preview manager follow. node-abi is pinned to a release that knows the new Electron ABI so prebuilt native modules resolve during packaging, and the release-age policy excludes this exact version. Co-Authored-By: Claude Fable 5.1 <[email protected]>
1 parent 0d34579 commit 82bc5b6

7 files changed

Lines changed: 93 additions & 27 deletions

File tree

‎apps/desktop/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"@t3tools/ssh": "workspace:*",
2323
"@t3tools/tailscale": "workspace:*",
2424
"effect": "catalog:",
25-
"electron": "43.4.1",
25+
"electron": "44.1.0",
2626
"electron-store": "^8.2.0",
2727
"electron-updater": "^6.6.2",
2828
"playwright-core": "1.60.0",

‎apps/desktop/src/electron/ElectronShell.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,28 @@ describe("ElectronShell", () => {
3636
}).pipe(Effect.provide(ElectronShell.layer)),
3737
);
3838

39+
it.effect("copies text to the system clipboard", () =>
40+
Effect.gen(function* () {
41+
writeTextMock.mockResolvedValue(undefined);
42+
43+
const electronShell = yield* ElectronShell.ElectronShell;
44+
yield* electronShell.copyText("https://example.com/path");
45+
46+
assert.deepEqual(writeTextMock.mock.calls, [["https://example.com/path"]]);
47+
}).pipe(Effect.provide(ElectronShell.layer)),
48+
);
49+
50+
it.effect("does not fail when the clipboard write rejects", () =>
51+
Effect.gen(function* () {
52+
writeTextMock.mockRejectedValue(new Error("write failed"));
53+
54+
const electronShell = yield* ElectronShell.ElectronShell;
55+
yield* electronShell.copyText("https://example.com/path");
56+
57+
assert.deepEqual(writeTextMock.mock.calls, [["https://example.com/path"]]);
58+
}).pipe(Effect.provide(ElectronShell.layer)),
59+
);
60+
3961
it.effect("opens the Full Disk Access settings anchor", () =>
4062
Effect.gen(function* () {
4163
openExternalMock.mockResolvedValue(undefined);

‎apps/desktop/src/electron/ElectronShell.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ export const make = ElectronShell.of({
8787
),
8888
),
8989
copyText: (text) =>
90-
Effect.sync(() => {
91-
Electron.clipboard.writeText(text);
92-
}),
90+
Effect.promise(() => Electron.clipboard.writeText(text).catch(() => undefined)),
9391
});
9492

9593
export const layer = Layer.succeed(ElectronShell, make);

‎apps/desktop/src/preview/Manager.test.ts‎

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,30 +113,40 @@ describe("previewWindowOpenAction", () => {
113113

114114
const {
115115
browserWindowConstructor,
116+
clipboardItemConstructor,
116117
createFromPath,
117118
fromId,
118119
getFocusedWebContents,
119120
mkdir,
120121
showItemInFolder,
121122
webviewSend,
122123
writeFile,
123-
writeImage,
124+
writeClipboard,
124125
} = vi.hoisted(() => ({
125126
browserWindowConstructor: vi.fn(),
126-
createFromPath: vi.fn((): { readonly isEmpty: () => boolean } => ({ isEmpty: () => false })),
127+
clipboardItemConstructor: vi.fn(),
128+
createFromPath: vi.fn((): { readonly isEmpty: () => boolean; readonly toPNG: () => Buffer } => ({
129+
isEmpty: () => false,
130+
toPNG: () => Buffer.from("png"),
131+
})),
127132
fromId: vi.fn<(_id?: number) => Electron.WebContents | null>((_id?: number) => null),
128133
getFocusedWebContents: vi.fn(() => null),
129134
mkdir: vi.fn((_path: string) => undefined),
130135
showItemInFolder: vi.fn(),
131136
webviewSend: vi.fn(),
132137
writeFile: vi.fn((_path: string, _data: Uint8Array) => undefined),
133-
writeImage: vi.fn(),
138+
writeClipboard: vi.fn(async () => undefined),
134139
}));
135140

136141
vi.mock("electron", () => ({
137142
BrowserWindow: browserWindowConstructor,
143+
ClipboardItem: class {
144+
constructor(data: Record<string, unknown>) {
145+
clipboardItemConstructor(data);
146+
}
147+
},
138148
clipboard: {
139-
writeImage,
149+
write: writeClipboard,
140150
},
141151
nativeImage: {
142152
createFromPath,
@@ -471,7 +481,8 @@ describe("PreviewManager", () => {
471481
mkdir.mockClear();
472482
writeFile.mockClear();
473483
showItemInFolder.mockClear();
474-
writeImage.mockClear();
484+
clipboardItemConstructor.mockClear();
485+
writeClipboard.mockClear();
475486
createFromPath.mockClear();
476487
webviewSend.mockClear();
477488
});
@@ -3671,7 +3682,10 @@ describe("PreviewManager", () => {
36713682
yield* manager.copyArtifactToClipboard(artifactPath);
36723683

36733684
expect(createFromPath).toHaveBeenCalledWith(artifactPath);
3674-
expect(writeImage).toHaveBeenCalledOnce();
3685+
expect(clipboardItemConstructor).toHaveBeenCalledWith({
3686+
"image/png": expect.any(Blob),
3687+
});
3688+
expect(writeClipboard).toHaveBeenCalledOnce();
36753689
const exit = yield* Effect.exit(
36763690
manager.copyArtifactToClipboard("/tmp/t3/dev/settings.json"),
36773691
);
@@ -3685,14 +3699,29 @@ describe("PreviewManager", () => {
36853699
});
36863700
expect("cause" in error).toBe(false);
36873701

3688-
createFromPath.mockReturnValueOnce({ isEmpty: () => true });
3702+
createFromPath.mockReturnValueOnce({
3703+
isEmpty: () => true,
3704+
toPNG: () => Buffer.from("invalid"),
3705+
});
36893706
const invalidImageExit = yield* Effect.exit(manager.copyArtifactToClipboard(artifactPath));
36903707
expect(Exit.isFailure(invalidImageExit)).toBe(true);
36913708
if (Exit.isSuccess(invalidImageExit)) return;
36923709
expect(Option.getOrThrow(Cause.findErrorOption(invalidImageExit.cause))).toMatchObject({
36933710
_tag: "PreviewArtifactImageLoadError",
36943711
artifactPath,
36953712
});
3713+
3714+
const writeCause = new Error("clipboard write failed");
3715+
writeClipboard.mockRejectedValueOnce(writeCause);
3716+
const writeExit = yield* Effect.exit(manager.copyArtifactToClipboard(artifactPath));
3717+
expect(Exit.isFailure(writeExit)).toBe(true);
3718+
if (Exit.isSuccess(writeExit)) return;
3719+
expect(Option.getOrThrow(Cause.findErrorOption(writeExit.cause))).toMatchObject({
3720+
_tag: "PreviewOperationError",
3721+
operation: "copyArtifactToClipboard.write",
3722+
artifactPath,
3723+
cause: writeCause,
3724+
});
36963725
}),
36973726
),
36983727
);

‎apps/desktop/src/preview/Manager.ts‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,15 @@ import type {
3232
} from "@t3tools/contracts";
3333
import { HostProcessPlatform } from "@t3tools/shared/hostProcess";
3434
import { normalizePreviewUrl } from "@t3tools/shared/preview";
35-
import { BrowserWindow, type Session, clipboard, nativeImage, shell, webContents } from "electron";
35+
import {
36+
BrowserWindow,
37+
ClipboardItem,
38+
type Session,
39+
clipboard,
40+
nativeImage,
41+
shell,
42+
webContents,
43+
} from "electron";
3644
import * as Cause from "effect/Cause";
3745
import * as Clock from "effect/Clock";
3846
import * as Context from "effect/Context";
@@ -4107,8 +4115,14 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
41074115
if (image.isEmpty()) {
41084116
return yield* new PreviewArtifactImageLoadError({ artifactPath: resolvedPath });
41094117
}
4110-
yield* attempt({ operation: "copyArtifactToClipboard.write", artifactPath: resolvedPath }, () =>
4111-
clipboard.writeImage(image),
4118+
yield* attemptPromise(
4119+
{ operation: "copyArtifactToClipboard.write", artifactPath: resolvedPath },
4120+
() =>
4121+
clipboard.write([
4122+
new ClipboardItem({
4123+
"image/png": new Blob([Uint8Array.from(image.toPNG())], { type: "image/png" }),
4124+
}),
4125+
]),
41124126
);
41134127
});
41144128

‎pnpm-lock.yaml‎

Lines changed: 14 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pnpm-workspace.yaml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ minimumReleaseAgeExclude:
9090
9191
9292
93+
9394
- "@anthropic-ai/[email protected]"
9495

9596
overrides:
@@ -137,6 +138,7 @@ overrides:
137138
expo-router: 57.0.17
138139
"expo-sharing>@expo/config-plugins": 57.0.9
139140
"expo-sharing>@expo/config-types": 57.0.2
141+
node-abi: 4.33.0
140142
lightningcss: "catalog:"
141143
tailwindcss: "catalog:"
142144
vite: "catalog:"

0 commit comments

Comments
 (0)