From 4c1aeef220d3591f799769d7784f643fdb8865f3 Mon Sep 17 00:00:00 2001 From: smartfrigde <37928912+smartfrigde@users.noreply.github.com> Date: Sun, 28 Apr 2024 16:48:50 +0200 Subject: [PATCH] fix; wayland audio share --- assets/lang/en-US.json | 2 - package.json | 2 +- src/content/css/settingsEng.css | 3 -- src/content/js/patchAudio.js | 65 --------------------------------- src/menu.ts | 27 -------------- src/screenshare/main.ts | 14 ++----- src/settings/settings.html | 8 ---- src/setup/setup.html | 1 - src/utils.ts | 6 +-- 9 files changed, 7 insertions(+), 121 deletions(-) delete mode 100644 src/content/js/patchAudio.js diff --git a/assets/lang/en-US.json b/assets/lang/en-US.json index 468c1af..cf69bc1 100644 --- a/assets/lang/en-US.json +++ b/assets/lang/en-US.json @@ -45,8 +45,6 @@ "settings-channel-desc4": "public test build. Receives features earlier than stable but is a bit older than Canary.", "settings-invitewebsocket": "Rich Presence (Experimental)", "settings-invitewebsocket-desc": "Uses arRPC to support Discord RPC (Rich Presence) with local programs on your machine. Work in progress.", - "settings-altPaste": "Alternative Paste", - "settings-altPaste-desc": "If you're on Gnome on Linux or just simply can't paste images copied from other messages, then this is\n for you. This enables alternative module for pasting images. Only enable this when you're experiencing\n issues.", "settings-mod": "Client mod", "settings-mod-desc1": "Client mods are programs that allow you customize your Discord experience. They can change appearance of\n the client, modify behaviours or add new features!", "settings-mod-vencord": "lightweight, and easy to use client mod. Features a built-in store for plugins.", diff --git a/package.json b/package.json index b4d6b84..00b57c9 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "start": "npm run build && electron ./ts-out/main.js", "startThemeManager": "npm run build && electron ./ts-out/main.js themes", "startKeybindManager": "npm run build && electron ./ts-out/main.js keybinds", - "startWayland": "npm run build && electron ./ts-out/main.js --ozone-platform-hint=auto --enable-features=WebRTCPipeWireCapturer,WaylandWindowDecorations", + "startWayland": "npm run build && electron ./ts-out/main.js --ozone-platform-hint=auto --enable-features=WebRTCPipeWireCapturer,WaylandWindowDecorations --disable-gpu", "package": "npm run build && electron-builder", "packageQuick": "npm run build && electron-builder --dir", "format": "prettier --write src *.json", diff --git a/src/content/css/settingsEng.css b/src/content/css/settingsEng.css index 4d2acac..b487cb3 100644 --- a/src/content/css/settingsEng.css +++ b/src/content/css/settingsEng.css @@ -13,9 +13,6 @@ .acMobileMode { height: 11em !important; } -.acAltPaste { - height: 11em !important; -} .acChannel { height: 21em !important; } diff --git a/src/content/js/patchAudio.js b/src/content/js/patchAudio.js deleted file mode 100644 index 8bbdca4..0000000 --- a/src/content/js/patchAudio.js +++ /dev/null @@ -1,65 +0,0 @@ -navigator.mediaDevices.getDisplayMedia = getDisplayMedia; -// ==UserScript== -// @name Screenshare with Audio -// @namespace https://github.com/edisionnano -// @version 0.4 -// @updateURL https://openuserjs.org/meta/samantas5855/Screenshare_with_Audio.meta.js -// @description Screenshare with Audio on Discord -// @author Guest271314 and Samantas5855 -// @match https://*.discord.com/* -// @icon https://www.google.com/s2/favicons?domain=discord.com -// @grant none -// @license MIT -// ==/UserScript== - -/* jshint esversion: 8 */ - -navigator.mediaDevices.chromiumGetDisplayMedia = navigator.mediaDevices.getDisplayMedia; - -const getAudioDevice = async (nameOfAudioDevice) => { - await navigator.mediaDevices.getUserMedia({ - audio: true - }); - await new Promise((r) => setTimeout(r, 1000)); - let devices = await navigator.mediaDevices.enumerateDevices(); - let audioDevice = devices.find(({label}) => label === nameOfAudioDevice); - return audioDevice; -}; - -const getDisplayMedia = async () => { - var id; - try { - let myDiscordAudioSink = await getAudioDevice("screenshareAudio"); - id = myDiscordAudioSink.deviceId; - } catch (error) { - id = "default"; - } - let captureSystemAudioStream = await navigator.mediaDevices.getUserMedia({ - audio: { - // We add our audio constraints here, to get a list of supported constraints use navigator.mediaDevices.getSupportedConstraints(); - // We must capture a microphone, we use default since its the only deviceId that is the same for every Chromium user - deviceId: { - exact: id - }, - // We want auto gain control, noise cancellation and noise suppression disabled so that our stream won't sound bad - autoGainControl: false, - echoCancellation: false, - noiseSuppression: false - // By default Chromium sets channel count for audio devices to 1, we want it to be stereo in case we find a way for Discord to accept stereo screenshare too - //channelCount: 2, - // You can set more audio constraints here, bellow are some examples - //latency: 0, - //sampleRate: 48000, - //sampleSize: 16, - //volume: 1.0 - } - }); - let [track] = captureSystemAudioStream.getAudioTracks(); - const gdm = await navigator.mediaDevices.chromiumGetDisplayMedia({ - video: true, - audio: true - }); - gdm.addTrack(track); - return gdm; -}; -navigator.mediaDevices.getDisplayMedia = getDisplayMedia; diff --git a/src/menu.ts b/src/menu.ts index 1fd1654..fb078d6 100644 --- a/src/menu.ts +++ b/src/menu.ts @@ -12,33 +12,6 @@ function paste(contents: any): void { contents.paste(); } export async function setMenu(): Promise { - if ((await getConfig("alternativePaste")) == true) { - mainWindow.on("focus", function () { - console.log("[Window state manager] Focus"); - globalShortcut.register("CmdOrCtrl+V", function () { - if (mainWindow.isFocused()) { - paste(mainWindow.webContents); - } - }); - }); - mainWindow.on("show", function () { - console.log("[Window state manager] Show"); - mainWindow.focus(); - globalShortcut.register("CmdOrCtrl+V", function () { - if (mainWindow.isFocused()) { - paste(mainWindow.webContents); - } - }); - }); - mainWindow.on("blur", function () { - console.log("[Window state manager] Defocus"); - globalShortcut.unregister("CmdOrCtrl+V"); - }); - mainWindow.on("hide", function () { - console.log("[Window state manager] Hide"); - globalShortcut.unregister("CmdOrCtrl+V"); - }); - } let template: Electron.MenuItemConstructorOptions[] = [ { label: "ArmCord", diff --git a/src/screenshare/main.ts b/src/screenshare/main.ts index c9227b1..29f1393 100644 --- a/src/screenshare/main.ts +++ b/src/screenshare/main.ts @@ -6,13 +6,6 @@ let capturerWindow: BrowserWindow; 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(); - // } - // } const sources = await desktopCapturer.getSources({ types: ["screen", "window"] }); @@ -20,7 +13,7 @@ function registerCustomHandler(): void { 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}}); + callback({video: sources[0], audio: "loopbackWithMute"}); } else { capturerWindow = new BrowserWindow({ width: 800, @@ -40,8 +33,9 @@ function registerCustomHandler(): void { //console.log(sources[id]); //console.log(id); capturerWindow.close(); - let result = {id, name, width: 9999, height: 9999}; - if (process.platform === "linux") { + let result = {id, name}; + if (process.platform === "linux" || process.platform === "win32") { + console.log("audio screenshare"); callback({video: result, audio: "loopbackWithMute"}); } else { callback({video: result}); diff --git a/src/settings/settings.html b/src/settings/settings.html index c472228..d62456c 100644 --- a/src/settings/settings.html +++ b/src/settings/settings.html @@ -100,14 +100,6 @@
-
- - - -

-
-
-
diff --git a/src/setup/setup.html b/src/setup/setup.html index 5578f1c..df56081 100644 --- a/src/setup/setup.html +++ b/src/setup/setup.html @@ -143,7 +143,6 @@ useLegacyCapturer: false, tray: /true/i.test(document.getElementById("tray").value), startMinimized: false, - alternativePaste: false, performanceMode: "none", trayIcon: "default", inviteWebsocket: true, diff --git a/src/utils.ts b/src/utils.ts index 7163566..97f4fbb 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -58,7 +58,6 @@ export function setup(): void { armcordCSP: true, minimizeToTray: true, keybinds: [], - alternativePaste: false, multiInstance: false, mods: "none", spellcheck: true, @@ -139,11 +138,11 @@ export async function injectElectronFlags(): Promise { switch (await getConfig("performanceMode")) { case "performance": console.log("Performance mode enabled"); - app.commandLine.appendSwitch(presets.performance); + app.commandLine.appendArgument(presets.performance); break; case "battery": console.log("Battery mode enabled"); - app.commandLine.appendSwitch(presets.battery); + app.commandLine.appendArgument(presets.battery); break; default: console.log("No performance modes set"); @@ -270,7 +269,6 @@ export interface Settings { channel: string; armcordCSP: boolean; minimizeToTray: boolean; - alternativePaste: boolean; multiInstance: boolean; spellcheck: boolean; mods: string;