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/eslint-plugin": "^5.59.2",
"@typescript-eslint/parser": "^5.59.2", "@typescript-eslint/parser": "^5.59.2",
"copyfiles": "^2.4.1", "copyfiles": "^2.4.1",
"electron": "^25.3.2", "electron": "26.0.0-beta.11",
"electron-builder": "^24.6.3", "electron-builder": "^24.6.3",
"eslint": "^8.40.0", "eslint": "^8.40.0",
"eslint-config-dmitmel": "github:dmitmel/eslint-config-dmitmel", "eslint-config-dmitmel": "github:dmitmel/eslint-config-dmitmel",

View file

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

View file

@ -60,26 +60,11 @@ if (!app.requestSingleInstanceLock()) {
} else { } else {
// Your data now belongs to CCP // Your data now belongs to CCP
crashReporter.start({uploadToServer: false}); crashReporter.start({uploadToServer: false});
/* Using appendSwitch properly causes ArmCord to segfault, // enable webrtc capturer for wayland
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.
if (process.platform === "linux" && process.env.XDG_SESSION_TYPE?.toLowerCase() === "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");
app.commandLine.appendSwitch("enable-features=WebRTCPipeWireCapturer"); console.log("Wayland detected, using PipeWire for video capture.");
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");
}
}
*/
// work around chrome 66 disabling autoplay by default // work around chrome 66 disabling autoplay by default
app.commandLine.appendSwitch("autoplay-policy", "no-user-gesture-required"); 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 path from "path";
import {iconPath} from "../main"; 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 { function registerCustomHandler(): void {
session.defaultSession.setDisplayMediaRequestHandler(async (request, callback) => { session.defaultSession.setDisplayMediaRequestHandler(async (request, callback) => {
console.log(request); console.log(request);
@ -41,44 +13,43 @@ function registerCustomHandler(): void {
// getSinks(); // getSinks();
// } // }
// } // }
if (process.platform == "linux") { const sources = await desktopCapturer.getSources({
const options: MessageBoxOptions = { types: ["screen", "window"]
type: "question", });
buttons: ["My screen", "An app"], console.log(sources);
defaultId: 1, 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", title: "ArmCord Screenshare",
message: `What would you like to screenshare?` darkTheme: true,
}; icon: iconPath,
frame: true,
dialog.showMessageBox(options).then(async ({response}) => { autoHideMenuBar: true,
if (response == 0) { webPreferences: {
sources = await desktopCapturer.getSources({ sandbox: false,
types: ["screen"] spellcheck: false,
}); preload: path.join(__dirname, "preload.js")
} else {
sources = await desktopCapturer.getSources({
types: ["window"]
});
} }
}); });
} else { ipcMain.once("selectScreenshareSource", (_event, id, name) => {
sources = await desktopCapturer.getSources({ //console.log(sources[id]);
types: ["screen", "window"] //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(); registerCustomHandler();