mirror of
https://github.com/smartfrigde/armcord.git
synced 2024-08-14 23:56:58 +00:00
fix wayland screenshare
This commit is contained in:
parent
ce1170178e
commit
8e43e5abcc
4 changed files with 44 additions and 88 deletions
23
src/main.ts
23
src/main.ts
|
@ -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");
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue