From b89231569780f94a9a56768950094f600604074f Mon Sep 17 00:00:00 2001 From: Curve Date: Thu, 6 Jun 2024 23:49:24 +0200 Subject: [PATCH] refactor(ScreenShare): review comments, add default audio source (fixes #638) --- src/main/venmic.ts | 38 ++++++++++--------- src/renderer/components/ScreenSharePicker.tsx | 33 ++++++++-------- src/shared/settings.d.ts | 16 ++++---- 3 files changed, 47 insertions(+), 40 deletions(-) diff --git a/src/main/venmic.ts b/src/main/venmic.ts index f269a00..d17b507 100644 --- a/src/main/venmic.ts +++ b/src/main/venmic.ts @@ -71,8 +71,10 @@ function getRendererAudioServicePid() { ipcMain.handle(IpcEvents.VIRT_MIC_LIST, () => { const audioPid = getRendererAudioServicePid(); + const { granularSelect } = Settings.store.audio ?? {}; + const targets = obtainVenmic() - ?.list(Settings.store.audioGranularSelect ? ["application.process.id"] : undefined) + ?.list(granularSelect ? ["application.process.id"] : undefined) .filter(s => s["application.process.id"] !== audioPid); return targets ? { ok: true, targets, hasPipewirePulse } : { ok: false, isGlibCxxOutdated }; @@ -80,23 +82,23 @@ ipcMain.handle(IpcEvents.VIRT_MIC_LIST, () => { ipcMain.handle(IpcEvents.VIRT_MIC_START, (_, include: Node[]) => { const pid = getRendererAudioServicePid(); - const settings = Settings.store; + const { ignoreDevices, ignoreInputMedia, ignoreVirtual, workaround } = Settings.store.audio ?? {}; const data: LinkData = { include: include, exclude: [{ "application.process.id": pid }], - ignore_devices: settings.audioIgnoreDevices + ignore_devices: ignoreDevices }; - if (settings.audioIgnoreInputMedia ?? true) { - data.exclude?.push({ "media.class": "Stream/Input/Audio" }); + if (ignoreInputMedia ?? true) { + data.exclude!.push({ "media.class": "Stream/Input/Audio" }); } - if (settings.audioIgnoreVirtual) { - data.exclude?.push({ "node.virtual": "true" }); + if (ignoreVirtual) { + data.exclude!.push({ "node.virtual": "true" }); } - if (settings.audioWorkaround) { + if (workaround) { data.workaround = [{ "application.process.id": pid, "media.name": "RecordStream" }]; } @@ -105,24 +107,26 @@ ipcMain.handle(IpcEvents.VIRT_MIC_START, (_, include: Node[]) => { ipcMain.handle(IpcEvents.VIRT_MIC_START_SYSTEM, (_, exclude: Node[]) => { const pid = getRendererAudioServicePid(); - const settings = Settings.store; + + const { workaround, ignoreDevices, ignoreInputMedia, ignoreVirtual, onlySpeakers, onlyDefaultSpeakers } = + Settings.store.audio ?? {}; const data: LinkData = { exclude: [{ "application.process.id": pid }, ...exclude], - only_speakers: settings.audioOnlySpeakers, - ignore_devices: settings.audioIgnoreDevices, - only_default_speakers: settings.audioOnlyDefaultSpeakers + only_speakers: onlySpeakers, + ignore_devices: ignoreDevices, + only_default_speakers: onlyDefaultSpeakers }; - if (settings.audioIgnoreInputMedia ?? true) { - data.exclude?.push({ "media.class": "Stream/Input/Audio" }); + if (ignoreInputMedia ?? true) { + data.exclude.push({ "media.class": "Stream/Input/Audio" }); } - if (settings.audioIgnoreVirtual) { - data.exclude?.push({ "node.virtual": "true" }); + if (ignoreVirtual) { + data.exclude.push({ "node.virtual": "true" }); } - if (settings.audioWorkaround) { + if (workaround) { data.workaround = [{ "application.process.id": pid, "media.name": "RecordStream" }]; } diff --git a/src/renderer/components/ScreenSharePicker.tsx b/src/renderer/components/ScreenSharePicker.tsx index 7748ea5..6ed3776 100644 --- a/src/renderer/components/ScreenSharePicker.tsx +++ b/src/renderer/components/ScreenSharePicker.tsx @@ -194,8 +194,8 @@ function AudioSettingsModal({ (Settings.audioWorkaround = v)} - value={Settings.audioWorkaround ?? false} + onChange={v => (Settings.audio = { ...Settings.audio, workaround: v })} + value={Settings.audio?.workaround ?? false} note={ <> Work around an issue that causes the microphone to be shared instead of the correct audio. @@ -207,8 +207,8 @@ function AudioSettingsModal({ (Settings.audioOnlySpeakers = v)} - value={Settings.audioOnlySpeakers ?? true} + onChange={v => (Settings.audio = { ...Settings.audio, onlySpeakers: v })} + value={Settings.audio?.onlySpeakers ?? true} note={ <> When sharing entire desktop audio, only share apps that play to a speaker. You may want to @@ -220,8 +220,8 @@ function AudioSettingsModal({ (Settings.audioOnlyDefaultSpeakers = v)} - value={Settings.audioOnlyDefaultSpeakers ?? true} + onChange={v => (Settings.audio = { ...Settings.audio, onlyDefaultSpeakers: v })} + value={Settings.audio?.onlyDefaultSpeakers ?? true} note={ <> When sharing entire desktop audio, only share apps that play to the default speakers. @@ -233,16 +233,16 @@ function AudioSettingsModal({ (Settings.audioIgnoreInputMedia = v)} - value={Settings.audioIgnoreInputMedia ?? true} + onChange={v => (Settings.audio = { ...Settings.audio, ignoreInputMedia: v })} + value={Settings.audio?.ignoreInputMedia ?? true} note={<>Exclude nodes that are intended to capture audio.} > Ignore Inputs (Settings.audioIgnoreVirtual = v)} - value={Settings.audioIgnoreVirtual ?? false} + onChange={v => (Settings.audio = { ...Settings.audio, ignoreVirtual: v })} + value={Settings.audio?.ignoreVirtual ?? false} note={ <> Exclude virtual nodes, such as nodes belonging to loopbacks. This might be useful when using @@ -254,8 +254,8 @@ function AudioSettingsModal({ (Settings.audioIgnoreDevices = v)} - value={Settings.audioIgnoreDevices ?? true} + onChange={v => (Settings.audio = { ...Settings.audio, ignoreDevices: v })} + value={Settings.audio?.ignoreDevices ?? true} note={<>Exclude device nodes, such as nodes belonging to microphones or speakers.} > Ignore Devices @@ -263,10 +263,10 @@ function AudioSettingsModal({ { - Settings.audioGranularSelect = value; + Settings.audio = { ...Settings.audio, granularSelect: value }; setAudioSources("None"); }} - value={Settings.audioGranularSelect ?? false} + value={Settings.audio?.granularSelect ?? false} note={<>Allow to select applications more granularly.} > Granular Selection @@ -423,7 +423,7 @@ function StreamSettings({ openSettings={openSettings} includeSources={settings.includeSources} excludeSources={settings.excludeSources} - granularSelect={Settings.audioGranularSelect} + granularSelect={Settings.audio?.granularSelect} setIncludeSources={sources => setSettings(s => ({ ...s, includeSources: sources }))} setExcludeSources={sources => setSettings(s => ({ ...s, excludeSources: sources }))} /> @@ -664,7 +664,8 @@ function ModalComponent({ resolution: "1080", fps: "60", contentHint: "motion", - audio: true + audio: true, + audioSources: "None" }); return ( diff --git a/src/shared/settings.d.ts b/src/shared/settings.d.ts index 596f30b..3eb96a0 100644 --- a/src/shared/settings.d.ts +++ b/src/shared/settings.d.ts @@ -31,15 +31,17 @@ export interface Settings { spellCheckLanguages?: string[]; - audioWorkaround?: boolean; - audioGranularSelect?: boolean; + audio?: { + workaround?: boolean; + granularSelect?: boolean; - audioIgnoreVirtual?: boolean; - audioIgnoreDevices?: boolean; - audioIgnoreInputMedia?: boolean; + ignoreVirtual?: boolean; + ignoreDevices?: boolean; + ignoreInputMedia?: boolean; - audioOnlySpeakers?: boolean; - audioOnlyDefaultSpeakers?: boolean; + onlySpeakers?: boolean; + onlyDefaultSpeakers?: boolean; + }; } export interface State {