Skip to content

Commit 7883dac

Browse files
SpacingBat3fyiel
andcommitted
Fix screen capturing issues.
This might also fix Wayland capturing, Resolves: #581 Co-Authored-By: Yops <zorbofs@gmail.com>
1 parent 28bf26b commit 7883dac

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

sources/code/main/windows/main.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ export default function createMainWindow(...flags:MainWindowFlags): BrowserWindo
409409
const media = navigator.mediaDevices.getUserMedia.bind(navigator.mediaDevices);
410410
navigator.mediaDevices.getUserMedia = Function.prototype.call.apply(Function.prototype.bind, [(constrains) => {
411411
if(constrains?.audio?.mandatory || constrains?.video?.mandatory)
412-
return Promise.rejected(new DOMException("Invalid state.", "NotAllowedError"));
412+
return Promise.reject(new DOMException("Invalid state.", "NotAllowedError"));
413413
return media(constrains);
414414
}]);
415415
Object.defineProperty(navigator.mediaDevices.getUserMedia, "name", {value: "getUserMedia"});
@@ -458,7 +458,7 @@ export default function createMainWindow(...flags:MainWindowFlags): BrowserWindo
458458
* Limitations for APIs to allow running WebCord properly with different
459459
* Electron releases.
460460
*/
461-
const apiSafe = Object.freeze({
461+
const apiGuard = Object.freeze({
462462
capturer: rSatisfies(process.versions.electron,"<22.0.0 || >=26.0.0"),
463463
unixAudioSharing: Number(process.versions.electron.split(".")[0])>=29
464464
});
@@ -492,7 +492,7 @@ export default function createMainWindow(...flags:MainWindowFlags): BrowserWindo
492492
process.env["XDG_SESSION_TYPE"] !== "wayland" ||
493493
process.platform === "win32";
494494

495-
const sources = lock || apiSafe.capturer ?
495+
const sources = lock || apiGuard.capturer ?
496496
// Use desktop capturer where it doesn't crash.
497497
desktopCapturer.getSources({
498498
types: ["screen", "window"],
@@ -549,7 +549,15 @@ export default function createMainWindow(...flags:MainWindowFlags): BrowserWindo
549549
});
550550
} else void sources.then(sources => sources[0] ? callback({
551551
video: sources[0],
552-
...(apiSafe.unixAudioSharing ? {audio:"loopbackWithMute"} : {})
552+
// FIXME: Look if there's audio on Wayland.
553+
// Also test this code:
554+
//
555+
//...(apiGuard.unixAudioSharing ? {audio:"loopback"} : {})
556+
//
557+
// In general, I know there's bug where Electron seem to
558+
// trigger Wayland capture, but somewhat cancels it or
559+
// stops taking care of its input (crashes?). Need to check
560+
// it out further.
553561
}) : callback(null as unknown as Electron.Streams));
554562
},{ useSystemPicker: true });
555563

0 commit comments

Comments
 (0)