Skip to content
Open
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
21 changes: 18 additions & 3 deletions apps/desktop/src/preview/Manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3167,7 +3167,10 @@ describe("PreviewManager", () => {
listeners.set(event, listener);
}),
once: vi.fn((event: string, listener: (...args: unknown[]) => void) => {
listeners.set(event, listener);
listeners.set(event, (...args) => {
listeners.delete(event);
listener(...args);
});
}),
off: vi.fn(),
ipc: { on: vi.fn(), off: vi.fn(), removeListener: vi.fn() },
Expand All @@ -3188,11 +3191,23 @@ describe("PreviewManager", () => {
const pick = yield* manager.pickElement("tab_1").pipe(Effect.forkChild);
yield* Effect.yieldNow;

listeners.get("did-start-navigation")?.({}, "about:blank", false, false);
listeners.get("did-start-navigation")?.({
url: "about:blank",
isSameDocument: false,
isMainFrame: false,
frame: null,
});
yield* Effect.yieldNow;
expect(pick.pollUnsafe()).toBeUndefined();

listeners.get("did-start-navigation")?.({}, "https://example.com/next", false, true);
listeners.get("did-start-navigation")?.({
url: "https://example.com/next",
isSameDocument: false,
isMainFrame: true,
frame: null,
});
yield* Effect.yieldNow;
expect(pick.pollUnsafe()).toBeDefined();
expect(yield* Fiber.join(pick)).toBeNull();
}),
),
Expand Down
9 changes: 3 additions & 6 deletions apps/desktop/src/preview/Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2503,12 +2503,9 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
};
const onDestroyed = () => settle(null);
const onNavigated = (
_event: Electron.Event,
_url: string,
_isInPlace: boolean,
isMainFrame: boolean,
event: Electron.Event<Electron.WebContentsDidStartNavigationEventParams>,
) => {
if (isMainFrame) settle(null);
if (event.isMainFrame) settle(null);
};
const registerPickElement = Effect.fn("PreviewManager.registerPickElement")(function* () {
// Two picks on one tab can overlap. Swap this session in and cancel
Expand All @@ -2529,7 +2526,7 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
yield* attempt({ operation: "pickElement.register", tabId, webContentsId: wc.id }, () => {
wc.ipc.on(ELEMENT_PICKED_CHANNEL, onMessage);
wc.once("destroyed", onDestroyed);
wc.once("did-start-navigation", onNavigated);
wc.on("did-start-navigation", onNavigated);
Comment thread
cursor[bot] marked this conversation as resolved.
if (!wc.isFocused()) wc.focus();
wc.send(START_PICK_CHANNEL, annotationTheme);
});
Expand Down
Loading