mirror of
https://github.com/smartfrigde/armcord.git
synced 2024-08-14 23:56:58 +00:00
wip: wayland screensharing
This commit is contained in:
parent
ba27104be6
commit
4074a8ccd5
3 changed files with 91 additions and 36 deletions
|
@ -1,36 +1,72 @@
|
|||
import {BrowserWindow, desktopCapturer, ipcMain, session} from "electron";
|
||||
import {BrowserWindow, MessageBoxOptions, desktopCapturer, ipcMain, session, dialog} 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();
|
||||
}
|
||||
function registerCustomHandler(): void {
|
||||
session.defaultSession.setDisplayMediaRequestHandler(async (request, callback) => {
|
||||
console.log(request);
|
||||
// if (process.platform == "linux") {
|
||||
// let isAudio = isAudioSupported();
|
||||
// if (isAudio) {
|
||||
// console.log("audio supported");
|
||||
// getSinks();
|
||||
// }
|
||||
// }
|
||||
if (process.platform == "linux") {
|
||||
let isAudio = isAudioSupported();
|
||||
if (isAudio) {
|
||||
console.log("audio supported");
|
||||
getSinks();
|
||||
}
|
||||
const options: MessageBoxOptions = {
|
||||
type: "question",
|
||||
buttons: ["My screen", "An app"],
|
||||
defaultId: 1,
|
||||
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"]
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
sources = await desktopCapturer.getSources({
|
||||
types: ["screen", "window"]
|
||||
});
|
||||
}
|
||||
const sources = await desktopCapturer.getSources({
|
||||
types: ["screen", "window"]
|
||||
});
|
||||
console.log(sources);
|
||||
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")
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.once("selectScreenshareSource", (_event, id, name) => {
|
||||
//console.log(sources[id]);
|
||||
//console.log(id);
|
||||
|
@ -42,8 +78,7 @@ function registerCustomHandler(): void {
|
|||
callback({video: result});
|
||||
}
|
||||
});
|
||||
capturerWindow.loadURL(`file://${__dirname}/picker.html`);
|
||||
capturerWindow.webContents.send("getSources", sources);
|
||||
openPickerWindow();
|
||||
});
|
||||
}
|
||||
registerCustomHandler();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue