wip: wayland screensharing

This commit is contained in:
smartfrigde 2023-07-13 22:59:08 +02:00
parent ba27104be6
commit 4074a8ccd5
3 changed files with 91 additions and 36 deletions

View file

@ -11,7 +11,7 @@
"watch": "tsc -w",
"start": "npm run build && electron ./ts-out/main.js",
"startThemeManager": "npm run build && electron ./ts-out/main.js themes",
"startWayland": "npm run build && electron ./ts-out/main.js --ozone-platform-hint=auto --enable-features=WebRTCPipeWireCapturer",
"startWayland": "npm run build && electron ./ts-out/main.js --ozone-platform-hint=auto --enable-features=WebRTCPipeWireCapturer,WaylandWindowDecorations",
"package": "npm run build && electron-builder",
"packageQuick": "npm run build && electron-builder --dir",
"format": "prettier --write src *.json",
@ -36,8 +36,9 @@
"@typescript-eslint/parser": "^5.59.2",
"chalk-cli": "^5.0.0",
"copyfiles": "^2.4.1",
"electron": "^25.1.0",
"electron": "^25.3.0",
"electron-builder": "^23.6.0",
"electron-nightly": "27.0.0-nightly.20230711",
"eslint": "^8.40.0",
"eslint-config-dmitmel": "github:dmitmel/eslint-config-dmitmel",
"eslint-plugin-node": "^11.1.0",

View file

@ -1,9 +1,13 @@
lockfileVersion: '6.0'
settings:
autoInstallPeers: true
excludeLinksFromLockfile: false
dependencies:
'@pyke/vibe':
specifier: github:pykeio/vibe#3c61074414cbed96ad51870e4dde379b16d9da6d
version: github.com/pykeio/vibe/3c61074414cbed96ad51870e4dde379b16d9da6d(electron@25.1.0)
version: github.com/pykeio/vibe/3c61074414cbed96ad51870e4dde379b16d9da6d(electron@25.3.0)
arrpc:
specifier: file:src/arrpc
version: file:src/arrpc
@ -43,11 +47,14 @@ devDependencies:
specifier: ^2.4.1
version: 2.4.1
electron:
specifier: ^25.1.0
version: 25.1.0
specifier: ^25.3.0
version: 25.3.0
electron-builder:
specifier: ^23.6.0
version: 23.6.0
electron-nightly:
specifier: 27.0.0-nightly.20230711
version: 27.0.0-nightly.20230711
eslint:
specifier: ^8.40.0
version: 8.40.0
@ -1154,6 +1161,19 @@ packages:
resolution: {integrity: sha512-3X99K852Yoqu9AcW50qz3ibYBWY79/pBhlMCab8ToEWS48R0T9tyxRiQhwylE7zQdXrMnx2JKqUJyMPmt5FBqA==}
dev: false
/electron-nightly@27.0.0-nightly.20230711:
resolution: {integrity: sha512-JBTc1lIJH0vofa1kdEfBrAlHpRWy3SW9gdNy0ga8R6FB4ZxaOyhe6dr0j/UYyKDE3OfesazJ0qALHK8634aCEA==}
engines: {node: '>= 12.20.55'}
hasBin: true
requiresBuild: true
dependencies:
'@electron/get': 2.0.2
'@types/node': 18.15.11
extract-zip: 2.0.1
transitivePeerDependencies:
- supports-color
dev: true
/electron-osx-sign@0.6.0:
resolution: {integrity: sha512-+hiIEb2Xxk6eDKJ2FFlpofCnemCbjbT5jz+BKGpVBrRNT3kWTGs4DfNX6IzGwgi33hUcXF+kFs9JW+r6Wc1LRg==}
engines: {node: '>=4.0.0'}
@ -1184,8 +1204,8 @@ packages:
- supports-color
dev: true
/electron@25.1.0:
resolution: {integrity: sha512-VKk4G/0euO7ysMKQKHXmI4d3/qR4uHsAtVFXK2WfQUVxBmc160OAm2R6PN9/EXmgXEioKQBtbc2/lvWyYpDbuA==}
/electron@25.3.0:
resolution: {integrity: sha512-cyqotxN+AroP5h2IxUsJsmehYwP5LrFAOO7O7k9tILME3Sa1/POAg3shrhx4XEnaAMyMqMLxzGvkzCVxzEErnA==}
engines: {node: '>= 12.20.55'}
hasBin: true
requiresBuild: true
@ -2947,7 +2967,6 @@ packages:
file:src/arrpc:
resolution: {directory: src/arrpc, type: directory}
name: arrpc
version: 3.0.0
dependencies:
ws: 8.11.0
transitivePeerDependencies:
@ -2977,7 +2996,7 @@ packages:
eslint: 8.40.0
dev: true
github.com/pykeio/vibe/3c61074414cbed96ad51870e4dde379b16d9da6d(electron@25.1.0):
github.com/pykeio/vibe/3c61074414cbed96ad51870e4dde379b16d9da6d(electron@25.3.0):
resolution: {tarball: https://codeload.github.com/pykeio/vibe/tar.gz/3c61074414cbed96ad51870e4dde379b16d9da6d}
id: github.com/pykeio/vibe/3c61074414cbed96ad51870e4dde379b16d9da6d
name: '@pyke/vibe'
@ -2987,5 +3006,5 @@ packages:
electron: '>=11.0'
dependencies:
cargo-cp-artifact: 0.1.7
electron: 25.1.0
electron: 25.3.0
dev: false

View file

@ -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();