fix wayland screenshare

This commit is contained in:
smartfrigde 2023-08-05 14:07:42 +02:00
parent ce1170178e
commit 8e43e5abcc
4 changed files with 44 additions and 88 deletions

View file

@ -36,7 +36,7 @@
"@typescript-eslint/eslint-plugin": "^5.59.2",
"@typescript-eslint/parser": "^5.59.2",
"copyfiles": "^2.4.1",
"electron": "^25.3.2",
"electron": "26.0.0-beta.11",
"electron-builder": "^24.6.3",
"eslint": "^8.40.0",
"eslint-config-dmitmel": "github:dmitmel/eslint-config-dmitmel",

View file

@ -41,8 +41,8 @@ devDependencies:
specifier: ^2.4.1
version: 2.4.1
electron:
specifier: ^25.3.2
version: 25.3.2
specifier: 26.0.0-beta.11
version: 26.0.0-beta.11
electron-builder:
specifier: ^24.6.3
version: 24.6.3
@ -1024,8 +1024,8 @@ packages:
- supports-color
dev: true
/electron@25.3.2:
resolution: {integrity: sha512-xiktJvXraaE/ARf2OVHFyTze1TksSbsbJgOaBtdIiBvUduez6ipATEPIec8Msz1n6eQ+xqYb6YF8tDuIZtJSPw==}
/electron@26.0.0-beta.11:
resolution: {integrity: sha512-QejgSimxMxl4C3oOVGqKPn9T50PHt//i9JZPN3mOKviyawpfA3yI8SbtDhXW0d+6f+GGHIg0Eo7deppki3be/Q==}
engines: {node: '>= 12.20.55'}
hasBin: true
requiresBuild: true
@ -1453,7 +1453,7 @@ packages:
es6-error: 4.1.1
matcher: 3.0.0
roarr: 2.15.4
semver: 7.3.8
semver: 7.5.4
serialize-error: 7.0.1
dev: true
optional: true

View file

@ -60,26 +60,11 @@ if (!app.requestSingleInstanceLock()) {
} else {
// Your data now belongs to CCP
crashReporter.start({uploadToServer: false});
/* Using appendSwitch properly causes ArmCord to segfault,
So we will leave the responsibility of enabling Wayland
And PipeWire video capture to packagers.
// We use toLowerCase to account for desktops where XDG_SESSION_TYPE might be Wayland and not wayland.
// enable webrtc capturer for wayland
if (process.platform === "linux" && process.env.XDG_SESSION_TYPE?.toLowerCase() === "wayland") {
// Just using the native Wayland backend doesn't enable PipeWire capture, we need to enable it explicitly.
app.commandLine.appendSwitch("enable-features=WebRTCPipeWireCapturer");
console.log("Wayland detected, using PipeWire for video capture.");
// Some people might want to disable the Wayland backend for one reason or another, such as for Wayland-specific bugs.
if (process.env.USE_WAYLAND === "0") {
console.log("Wayland backend disabled.");
} else {
console.log("Using native Wayland, not Xwayland. Disable with USE_WAYLAND=0 if you find issues.");
app.commandLine.appendSwitch("ozone-platform=auto");
// The Wayland spec doesn't require SSDs, so lets enable self-drawn window decorations.
// If SSDs are supported on the compositor, Electron will let the compositor handle the decorations.
app.commandLine.appendSwitch("enable-features=UseOzonePlatform,WaylandWindowDecorations");
}
}
*/
app.commandLine.appendSwitch("enable-features=WebRTCPipeWireCapturer");
console.log("Wayland detected, using PipeWire for video capture.");
}
// work around chrome 66 disabling autoplay by default
app.commandLine.appendSwitch("autoplay-policy", "no-user-gesture-required");

View file

@ -1,36 +1,8 @@
import {BrowserWindow, MessageBoxOptions, desktopCapturer, ipcMain, session, dialog} from "electron";
import {BrowserWindow, desktopCapturer, ipcMain, session} from "electron";
import path from "path";
import {iconPath} from "../main";
import {getSinks, isAudioSupported} from "./audio";
let capturerWindow: BrowserWindow;
var sources: Electron.DesktopCapturerSource[];
function openPickerWindow() {
capturerWindow = new BrowserWindow({
width: 800,
height: 600,
title: "ArmCord Screenshare",
darkTheme: true,
icon: iconPath,
frame: true,
autoHideMenuBar: true,
webPreferences: {
sandbox: false,
spellcheck: false,
preload: path.join(__dirname, "preload.js")
}
});
function waitForElement() {
if (sources == undefined) {
setTimeout(waitForElement, 250);
console.log(sources);
} else {
capturerWindow.loadURL(`file://${__dirname}/picker.html`);
capturerWindow.webContents.send("getSources", sources);
}
}
waitForElement();
}
let capturerWindow: BrowserWindow;
function registerCustomHandler(): void {
session.defaultSession.setDisplayMediaRequestHandler(async (request, callback) => {
console.log(request);
@ -41,44 +13,43 @@ function registerCustomHandler(): void {
// getSinks();
// }
// }
if (process.platform == "linux") {
const options: MessageBoxOptions = {
type: "question",
buttons: ["My screen", "An app"],
defaultId: 1,
const sources = await desktopCapturer.getSources({
types: ["screen", "window"]
});
console.log(sources);
if (process.platform === "linux" && process.env.XDG_SESSION_TYPE?.toLowerCase() === "wayland") {
console.log("WebRTC Capturer detected, skipping window creation."); //assume webrtc capturer is used
console.log({video: {id: sources[0].id, name: sources[0].name}});
callback({video: {id: sources[0].id, name: sources[0].name}});
} else {
capturerWindow = new BrowserWindow({
width: 800,
height: 600,
title: "ArmCord Screenshare",
message: `What would you like to screenshare?`
};
dialog.showMessageBox(options).then(async ({response}) => {
if (response == 0) {
sources = await desktopCapturer.getSources({
types: ["screen"]
});
} else {
sources = await desktopCapturer.getSources({
types: ["window"]
});
darkTheme: true,
icon: iconPath,
frame: true,
autoHideMenuBar: true,
webPreferences: {
sandbox: false,
spellcheck: false,
preload: path.join(__dirname, "preload.js")
}
});
} else {
sources = await desktopCapturer.getSources({
types: ["screen", "window"]
ipcMain.once("selectScreenshareSource", (_event, id, name) => {
//console.log(sources[id]);
//console.log(id);
capturerWindow.close();
let result = {id, name, width: 9999, height: 9999};
if (process.platform === "win32") {
callback({video: result, audio: "loopback"});
} else {
callback({video: result});
}
});
capturerWindow.loadURL(`file://${__dirname}/picker.html`);
capturerWindow.webContents.send("getSources", sources);
}
ipcMain.once("selectScreenshareSource", (_event, id, name) => {
//console.log(sources[id]);
//console.log(id);
capturerWindow.close();
let result = {id, name, width: 9999, height: 9999};
if (process.platform === "win32") {
callback({video: result, audio: "loopback"});
} else {
callback({video: result});
}
});
openPickerWindow();
});
}
registerCustomHandler();