Skip to content

Commit

Permalink
Wayland: Disable audio sharing for Electron <29.
Browse files Browse the repository at this point in the history
This might help with #513 or at least will not set any useless options
to enable audio share on Electron builds that don't really support it.
  • Loading branch information
SpacingBat3 committed Feb 20, 2024
1 parent 294987d commit 7c1bef6
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions sources/code/main/windows/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,13 +442,13 @@ export default function createMainWindow(...flags:MainWindowFlags): BrowserWindo
void loadChromiumExtensions(win.webContents.session);

/**
* Whenever `desktopCapturer.getSources()` API is expected to crash
* with current Electron version the application is running on.
* Limitations for APIs to allow running WebCord properly with different
* Electron releases.
*/
const capturerApiSafe = rSatisfies(
process.versions.electron,
"<22.0.0 || >=26.0.0"
);
const apiSafe = Object.freeze({
capturer: rSatisfies(process.versions.electron,"<22.0.0 || >=26.0.0"),
unixAudioSharing: Number(process.versions.electron.split(".")[0])>=29
});

/** Determines whenever another request to desktopCapturer is processed. */
let lock = false;
Expand Down Expand Up @@ -479,7 +479,7 @@ export default function createMainWindow(...flags:MainWindowFlags): BrowserWindo
process.env["XDG_SESSION_TYPE"] !== "wayland" ||
process.platform === "win32";

const sources = lock || capturerApiSafe ?
const sources = lock || apiSafe.capturer ?
// Use desktop capturer where it doesn't crash.
desktopCapturer.getSources({
types: ["screen", "window"],
Expand Down Expand Up @@ -533,13 +533,10 @@ export default function createMainWindow(...flags:MainWindowFlags): BrowserWindo
autoResize();
win.on("resize", autoResize);
});
} else void sources.then(sources => {
const { id, name } = sources[0] ?? {};
if(id === undefined || name === undefined)
callback(null as unknown as Electron.Streams);
else
callback({video: { id, name }, audio: "loopbackWithMute"});
});
} else void sources.then(sources => sources[0] ? callback({
video: sources[0],
...(apiSafe.unixAudioSharing ? {audio:"loopbackWithMute"} : {})
}) : callback(null as unknown as Electron.Streams));
});

// IPC events validated by secret "API" key and sender frame.
Expand Down

0 comments on commit 7c1bef6

Please sign in to comment.