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
44 changes: 44 additions & 0 deletions src/components/launch/LaunchWindow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,50 @@ describe("LaunchWindow record button", () => {
expect(recorderState.value.toggleRecording).not.toHaveBeenCalled();
});

it("clears record-after-selection intent when opening the source picker fails", async () => {
window.electronAPI.openSourceSelector = vi.fn(async () => {
throw new Error("source selector failed");
});

renderLaunchWindow();
await waitForSourceSelectionSubscription();

fireEvent.click(await screen.findByTestId("launch-record-button"));

await waitFor(() => {
expect(window.electronAPI.openSourceSelector).toHaveBeenCalledTimes(1);
});

await act(async () => {
await Promise.resolve();
});

emitSelectedSourceChanged(displayOneSource);

await waitFor(() => {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
expect(screen.getByTestId("launch-record-button")).toHaveAttribute("title", "Display 1");
});
expect(recorderState.value.toggleRecording).not.toHaveBeenCalled();
});

it("handles selected source polling failures", async () => {
const error = new Error("selected source unavailable");
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => undefined);
stubElectronAPI(
vi.fn(async () => {
throw error;
}),
);

renderLaunchWindow();

await waitFor(() => {
expect(warnSpy).toHaveBeenCalledWith("Failed to refresh selected source:", error);
});

warnSpy.mockRestore();
});

it("starts recording when a source is already selected", async () => {
stubElectronAPI(vi.fn(async () => displayOneSource));

Expand Down
20 changes: 15 additions & 5 deletions src/components/launch/LaunchWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,15 @@ export function LaunchWindow() {

useEffect(() => {
const checkSelectedSource = async () => {
if (window.electronAPI) {
if (!window.electronAPI) {
return;
}

try {
const source = await window.electronAPI.getSelectedSource();
applySelectedSource(source);
} catch (error) {
console.warn("Failed to refresh selected source:", error);
}
};

Expand Down Expand Up @@ -488,11 +494,15 @@ export function LaunchWindow() {
const handleRecordButtonClick = () => {
if (!hasSelectedSource && !recording) {
recordAfterSourceSelectionRef.current = true;
void openSourceSelector().then((result) => {
if (!result.opened) {
void openSourceSelector()
.then((result) => {
if (!result.opened) {
recordAfterSourceSelectionRef.current = false;
}
})
.catch(() => {
recordAfterSourceSelectionRef.current = false;
}
});
});
return;
}

Expand Down
Loading