Skip to content

Commit 2ab6db0

Browse files
author
byquanton
committed
Add explaining comment and error handeling
1 parent e682d9f commit 2ab6db0

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/electron-main.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,14 @@ app.on("ready", async () => {
556556

557557
session.defaultSession.setDisplayMediaRequestHandler((_, callback) => {
558558
if (process.env.XDG_SESSION_TYPE === "wayland") {
559+
// On Wayland, calling getSources() opens the xdg-desktop-portal picker.
560+
// The user can only select a single source there, so Electron will return an array with exactly one entry.
559561
desktopCapturer.getSources({ types: ['screen', 'window'] }).then((sources) => {
560-
callback({ video: sources[0] })
562+
callback({ video: sources[0] });
563+
}).catch((err) => {
564+
// If the user cancels the dialog an error occurs "Failed to get sources"
565+
console.error("Wayland: failed to get user-selected source:", err);
566+
callback({ video: { id: "", name: ""} }); // The promise does not return if no dummy is passed here as source
561567
});
562568
} else {
563569
global.mainWindow?.webContents.send("openDesktopCapturerSourcePicker");

0 commit comments

Comments
 (0)