From 7447fe3b703669a53dd910dacadeb1ebc397643f Mon Sep 17 00:00:00 2001 From: Vendicated Date: Thu, 28 Sep 2023 01:55:31 +0200 Subject: [PATCH] add linux audio picker --- src/main/screenShare.ts | 5 +- src/renderer/components/ScreenSharePicker.tsx | 54 +++++++++++++++++-- src/renderer/utils.ts | 1 + 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/src/main/screenShare.ts b/src/main/screenShare.ts index 4fb726b..8703bff 100644 --- a/src/main/screenShare.ts +++ b/src/main/screenShare.ts @@ -55,7 +55,10 @@ export function registerScreenShareHandler() { const choice = await request.frame .executeJavaScript(`Vesktop.Components.ScreenShare.openScreenSharePicker(${JSON.stringify(data)})`) .then(e => e as StreamPick) - .catch(() => null); + .catch(e => { + console.error("Error during screenshare picker", e); + return null; + }); if (!choice) return callback({}); diff --git a/src/renderer/components/ScreenSharePicker.tsx b/src/renderer/components/ScreenSharePicker.tsx index 1660a88..f62c84a 100644 --- a/src/renderer/components/ScreenSharePicker.tsx +++ b/src/renderer/components/ScreenSharePicker.tsx @@ -8,10 +8,10 @@ import "./screenSharePicker.css"; import { closeModal, Modals, openModal, useAwaiter } from "@vencord/types/utils"; import { findStoreLazy } from "@vencord/types/webpack"; -import { Button, Card, Forms, Switch, Text, useState } from "@vencord/types/webpack/common"; +import { Button, Card, Forms, Select, Switch, Text, useState } from "@vencord/types/webpack/common"; import type { Dispatch, SetStateAction } from "react"; import { addPatch } from "renderer/patches/shared"; -import { isWindows } from "renderer/utils"; +import { isLinux, isWindows } from "renderer/utils"; const StreamResolutions = ["480", "720", "1080", "1440"] as const; const StreamFps = ["15", "30", "60"] as const; @@ -25,6 +25,7 @@ interface StreamSettings { resolution: StreamResolution; fps: StreamFps; audio: boolean; + audioSource?: string; } export interface StreamPick extends StreamSettings { @@ -71,16 +72,21 @@ addPatch({ }); export function openScreenSharePicker(screens: Source[], skipPicker = false) { + let didSubmit = false; return new Promise((resolve, reject) => { const key = openModal( props => ( { + didSubmit = true; + if (v.audioSource && v.audioSource !== "None") await VesktopNative.virtmic.start(v.audioSource); + resolve(v); + }} close={() => { props.onClose(); - reject("Aborted"); + if (!didSubmit) reject("Aborted"); }} skipPicker={skipPicker} /> @@ -183,11 +189,51 @@ function StreamSettings({ Stream With Audio )} + + {isLinux && ( + setSettings(s => ({ ...s, audioSource: source }))} + /> + )} ); } +function AudioSourcePickerLinux({ + audioSource, + setAudioSource +}: { + audioSource?: string; + setAudioSource(s: string): void; +}) { + const [sources, _, loading] = useAwaiter(() => VesktopNative.virtmic.list(), { fallbackValue: [] }); + const sourcesWithNone = sources ? ["None", ...sources] : null; + + return ( +
+ Audio + {loading && Loading Audio sources...} + {sourcesWithNone === null && ( + + Failed to retrieve Audio Sources. If you would like to stream with Audio, make sure you're using + Pipewire, not Pulseaudio + + )} + + {sourcesWithNone && ( +