From 62c4e1cdf03e5c25a91398979985d3a0f811033a Mon Sep 17 00:00:00 2001 From: Ryan Cao <70191398+ryanccn@users.noreply.github.com> Date: Sun, 29 Oct 2023 00:24:04 +0800 Subject: [PATCH] add video device patching as well --- src/renderer/components/ScreenSharePicker.tsx | 98 +++++++++++++++---- src/renderer/patches/index.ts | 2 +- src/renderer/patches/screenShareAudio.ts | 60 ------------ src/renderer/patches/screenSharePatch.ts | 68 +++++++++++++ 4 files changed, 149 insertions(+), 79 deletions(-) delete mode 100644 src/renderer/patches/screenShareAudio.ts create mode 100644 src/renderer/patches/screenSharePatch.ts diff --git a/src/renderer/components/ScreenSharePicker.tsx b/src/renderer/components/ScreenSharePicker.tsx index 453194347..a470d1fc4 100644 --- a/src/renderer/components/ScreenSharePicker.tsx +++ b/src/renderer/components/ScreenSharePicker.tsx @@ -20,7 +20,7 @@ import { useState } from "@vencord/types/webpack/common"; import type { Dispatch, SetStateAction } from "react"; -import { patchAudioWithDevice } from "renderer/patches/screenShareAudio"; +import { patchDisplayMedia } from "renderer/patches/screenSharePatch"; import { addPatch } from "renderer/patches/shared"; import { isLinux, isWindows } from "renderer/utils"; @@ -43,6 +43,7 @@ interface StreamSettings { export interface StreamPick extends StreamSettings { id: string; + cameraId?: string; } interface Source { @@ -51,6 +52,11 @@ interface Source { url: string; } +interface Camera { + id: string; + name: string; +} + let currentSettings: StreamSettings | null = null; addPatch({ @@ -100,6 +106,7 @@ if (isLinux) { export function openScreenSharePicker(screens: Source[], skipPicker: boolean) { let didSubmit = false; + return new Promise((resolve, reject) => { const key = openModal( props => ( @@ -109,16 +116,24 @@ export function openScreenSharePicker(screens: Source[], skipPicker: boolean) { submit={async v => { didSubmit = true; if (v.audioSource && v.audioSource !== "None") { - if (v.audioSource === "Entire System") { - await VesktopNative.virtmic.startSystem(v.workaround); - } else { - await VesktopNative.virtmic.start([v.audioSource], v.workaround); + patchDisplayMedia({ + audioId: v.audioDevice, + venmic: !!v.audioSource && v.audioSource !== "None", + videoId: v.cameraId + }); + + if (!v.audioDevice && v.audioSource && v.audioSource !== "None") { + if (v.audioSource === "Entire System") { + await VesktopNative.virtmic.startSystem(v.workaround); + } else { + await VesktopNative.virtmic.start([v.audioSource], v.workaround); + } } - } - patchAudioWithDevice(v.audioDevice); + patchAudioWithDevice(v.audioDevice); - resolve(v); + resolve(v); + } }} close={() => { props.onClose(); @@ -137,12 +152,26 @@ export function openScreenSharePicker(screens: Source[], skipPicker: boolean) { }); } -function ScreenPicker({ screens, chooseScreen }: { screens: Source[]; chooseScreen: (id: string) => void }) { +function ScreenPicker({ + screens, + chooseScreen, + isDisabled = false +}: { + screens: Source[]; + chooseScreen: (id: string) => void; + isDisabled?: boolean; +}) { return (
{screens.map(({ id, name, url }) => (