fix(desktop): preserve external-open IPC result
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
8fd276f69e
commit
761be9497d
3 files changed
+50
-1
No files matched your search
@@ -0,0 +1,34 @@
|
||||
import { assert, describe, it } from "@effect/vitest";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Logger from "effect/Logger";
|
||||
|
||||
import { openExternal } from "./window.ts";
|
||||
import * as ElectronShell from "../../electron/ElectronShell.ts";
|
||||
|
||||
describe("window IPC", () => {
|
||||
it.effect("returns false when Electron rejects an external URL", () => {
|
||||
const url = "https://example.com/path";
|
||||
const error = new ElectronShell.ElectronShellOpenExternalError({
|
||||
urlHostname: "example.com",
|
||||
urlLength: url.length,
|
||||
urlProtocol: "https:",
|
||||
cause: new Error("open failed"),
|
||||
});
|
||||
const layer = Layer.mergeAll(
|
||||
Layer.succeed(
|
||||
ElectronShell.ElectronShell,
|
||||
ElectronShell.ElectronShell.of({
|
||||
openExternal: () => Effect.fail(error),
|
||||
copyText: () => Effect.void,
|
||||
}),
|
||||
),
|
||||
Logger.layer([], { mergeWithExisting: false }),
|
||||
);
|
||||
|
||||
return Effect.gen(function* () {
|
||||
const opened = yield* openExternal.handler(url);
|
||||
assert.equal(opened, false);
|
||||
}).pipe(Effect.provide(layer));
|
||||
});
|
||||
});
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
} from "@t3tools/contracts";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Redacted from "effect/Redacted";
|
||||
import * as Schema from "effect/Schema";
|
||||
|
||||
import * as DesktopBackendManager from "../../backend/DesktopBackendManager.ts";
|
||||
@@ -141,6 +142,19 @@ export const openExternal = DesktopIpc.makeIpcMethod({
|
||||
result: Schema.Boolean,
|
||||
handler: Effect.fn("desktop.ipc.window.openExternal")(function* (url) {
|
||||
const shell = yield* ElectronShell.ElectronShell;
|
||||
return yield* shell.openExternal(url);
|
||||
return yield* shell.openExternal(url).pipe(
|
||||
Effect.catchTag("ElectronShellOpenExternalError", (error) =>
|
||||
Effect.logWarning(error.message).pipe(
|
||||
Effect.annotateLogs({
|
||||
error: Redacted.make(error, { label: error._tag }),
|
||||
"error.type": error._tag,
|
||||
"desktop.external_url.hostname": error.urlHostname,
|
||||
"desktop.external_url.input_length": error.urlLength,
|
||||
"desktop.external_url.protocol": error.urlProtocol,
|
||||
}),
|
||||
Effect.as(false),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
});
|
||||
@@ -942,6 +942,7 @@ export interface DesktopBridge {
|
||||
items: readonly ContextMenuItem<T>[],
|
||||
position?: { x: number; y: number },
|
||||
) => Promise<T | null>;
|
||||
/** Resolves false when the URL is unsafe or the desktop shell cannot open it. */
|
||||
openExternal: (url: string) => Promise<boolean>;
|
||||
onMenuAction: (listener: (action: string) => void) => () => void;
|
||||
getUpdateState: () => Promise<DesktopUpdateState>;
|
||||
|
||||
Reference in new issue
Block a user