refactor(ScreenShare): review comments, add default audio source (fixes #638)

This commit is contained in:
Curve 2024-06-06 23:49:24 +02:00
parent 564665a2a7
commit b892315697
No known key found for this signature in database
GPG key ID: 460F6C466BD35813
3 changed files with 47 additions and 40 deletions

View file

@ -71,8 +71,10 @@ function getRendererAudioServicePid() {
ipcMain.handle(IpcEvents.VIRT_MIC_LIST, () => { ipcMain.handle(IpcEvents.VIRT_MIC_LIST, () => {
const audioPid = getRendererAudioServicePid(); const audioPid = getRendererAudioServicePid();
const { granularSelect } = Settings.store.audio ?? {};
const targets = obtainVenmic() const targets = obtainVenmic()
?.list(Settings.store.audioGranularSelect ? ["application.process.id"] : undefined) ?.list(granularSelect ? ["application.process.id"] : undefined)
.filter(s => s["application.process.id"] !== audioPid); .filter(s => s["application.process.id"] !== audioPid);
return targets ? { ok: true, targets, hasPipewirePulse } : { ok: false, isGlibCxxOutdated }; 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[]) => { ipcMain.handle(IpcEvents.VIRT_MIC_START, (_, include: Node[]) => {
const pid = getRendererAudioServicePid(); const pid = getRendererAudioServicePid();
const settings = Settings.store; const { ignoreDevices, ignoreInputMedia, ignoreVirtual, workaround } = Settings.store.audio ?? {};
const data: LinkData = { const data: LinkData = {
include: include, include: include,
exclude: [{ "application.process.id": pid }], exclude: [{ "application.process.id": pid }],
ignore_devices: settings.audioIgnoreDevices ignore_devices: ignoreDevices
}; };
if (settings.audioIgnoreInputMedia ?? true) { if (ignoreInputMedia ?? true) {
data.exclude?.push({ "media.class": "Stream/Input/Audio" }); data.exclude!.push({ "media.class": "Stream/Input/Audio" });
} }
if (settings.audioIgnoreVirtual) { if (ignoreVirtual) {
data.exclude?.push({ "node.virtual": "true" }); data.exclude!.push({ "node.virtual": "true" });
} }
if (settings.audioWorkaround) { if (workaround) {
data.workaround = [{ "application.process.id": pid, "media.name": "RecordStream" }]; 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[]) => { ipcMain.handle(IpcEvents.VIRT_MIC_START_SYSTEM, (_, exclude: Node[]) => {
const pid = getRendererAudioServicePid(); const pid = getRendererAudioServicePid();
const settings = Settings.store;
const { workaround, ignoreDevices, ignoreInputMedia, ignoreVirtual, onlySpeakers, onlyDefaultSpeakers } =
Settings.store.audio ?? {};
const data: LinkData = { const data: LinkData = {
exclude: [{ "application.process.id": pid }, ...exclude], exclude: [{ "application.process.id": pid }, ...exclude],
only_speakers: settings.audioOnlySpeakers, only_speakers: onlySpeakers,
ignore_devices: settings.audioIgnoreDevices, ignore_devices: ignoreDevices,
only_default_speakers: settings.audioOnlyDefaultSpeakers only_default_speakers: onlyDefaultSpeakers
}; };
if (settings.audioIgnoreInputMedia ?? true) { if (ignoreInputMedia ?? true) {
data.exclude?.push({ "media.class": "Stream/Input/Audio" }); data.exclude.push({ "media.class": "Stream/Input/Audio" });
} }
if (settings.audioIgnoreVirtual) { if (ignoreVirtual) {
data.exclude?.push({ "node.virtual": "true" }); data.exclude.push({ "node.virtual": "true" });
} }
if (settings.audioWorkaround) { if (workaround) {
data.workaround = [{ "application.process.id": pid, "media.name": "RecordStream" }]; data.workaround = [{ "application.process.id": pid, "media.name": "RecordStream" }];
} }

View file

@ -194,8 +194,8 @@ function AudioSettingsModal({
<Modals.ModalContent className="vcd-screen-picker-modal"> <Modals.ModalContent className="vcd-screen-picker-modal">
<Switch <Switch
hideBorder hideBorder
onChange={v => (Settings.audioWorkaround = v)} onChange={v => (Settings.audio = { ...Settings.audio, workaround: v })}
value={Settings.audioWorkaround ?? false} value={Settings.audio?.workaround ?? false}
note={ note={
<> <>
Work around an issue that causes the microphone to be shared instead of the correct audio. Work around an issue that causes the microphone to be shared instead of the correct audio.
@ -207,8 +207,8 @@ function AudioSettingsModal({
</Switch> </Switch>
<Switch <Switch
hideBorder hideBorder
onChange={v => (Settings.audioOnlySpeakers = v)} onChange={v => (Settings.audio = { ...Settings.audio, onlySpeakers: v })}
value={Settings.audioOnlySpeakers ?? true} value={Settings.audio?.onlySpeakers ?? true}
note={ note={
<> <>
When sharing entire desktop audio, only share apps that play to a speaker. You may want to When sharing entire desktop audio, only share apps that play to a speaker. You may want to
@ -220,8 +220,8 @@ function AudioSettingsModal({
</Switch> </Switch>
<Switch <Switch
hideBorder hideBorder
onChange={v => (Settings.audioOnlyDefaultSpeakers = v)} onChange={v => (Settings.audio = { ...Settings.audio, onlyDefaultSpeakers: v })}
value={Settings.audioOnlyDefaultSpeakers ?? true} value={Settings.audio?.onlyDefaultSpeakers ?? true}
note={ note={
<> <>
When sharing entire desktop audio, only share apps that play to the <b>default</b> speakers. When sharing entire desktop audio, only share apps that play to the <b>default</b> speakers.
@ -233,16 +233,16 @@ function AudioSettingsModal({
</Switch> </Switch>
<Switch <Switch
hideBorder hideBorder
onChange={v => (Settings.audioIgnoreInputMedia = v)} onChange={v => (Settings.audio = { ...Settings.audio, ignoreInputMedia: v })}
value={Settings.audioIgnoreInputMedia ?? true} value={Settings.audio?.ignoreInputMedia ?? true}
note={<>Exclude nodes that are intended to capture audio.</>} note={<>Exclude nodes that are intended to capture audio.</>}
> >
Ignore Inputs Ignore Inputs
</Switch> </Switch>
<Switch <Switch
hideBorder hideBorder
onChange={v => (Settings.audioIgnoreVirtual = v)} onChange={v => (Settings.audio = { ...Settings.audio, ignoreVirtual: v })}
value={Settings.audioIgnoreVirtual ?? false} value={Settings.audio?.ignoreVirtual ?? false}
note={ note={
<> <>
Exclude virtual nodes, such as nodes belonging to loopbacks. This might be useful when using Exclude virtual nodes, such as nodes belonging to loopbacks. This might be useful when using
@ -254,8 +254,8 @@ function AudioSettingsModal({
</Switch> </Switch>
<Switch <Switch
hideBorder hideBorder
onChange={v => (Settings.audioIgnoreDevices = v)} onChange={v => (Settings.audio = { ...Settings.audio, ignoreDevices: v })}
value={Settings.audioIgnoreDevices ?? true} value={Settings.audio?.ignoreDevices ?? true}
note={<>Exclude device nodes, such as nodes belonging to microphones or speakers.</>} note={<>Exclude device nodes, such as nodes belonging to microphones or speakers.</>}
> >
Ignore Devices Ignore Devices
@ -263,10 +263,10 @@ function AudioSettingsModal({
<Switch <Switch
hideBorder hideBorder
onChange={value => { onChange={value => {
Settings.audioGranularSelect = value; Settings.audio = { ...Settings.audio, granularSelect: value };
setAudioSources("None"); setAudioSources("None");
}} }}
value={Settings.audioGranularSelect ?? false} value={Settings.audio?.granularSelect ?? false}
note={<>Allow to select applications more granularly.</>} note={<>Allow to select applications more granularly.</>}
> >
Granular Selection Granular Selection
@ -423,7 +423,7 @@ function StreamSettings({
openSettings={openSettings} openSettings={openSettings}
includeSources={settings.includeSources} includeSources={settings.includeSources}
excludeSources={settings.excludeSources} excludeSources={settings.excludeSources}
granularSelect={Settings.audioGranularSelect} granularSelect={Settings.audio?.granularSelect}
setIncludeSources={sources => setSettings(s => ({ ...s, includeSources: sources }))} setIncludeSources={sources => setSettings(s => ({ ...s, includeSources: sources }))}
setExcludeSources={sources => setSettings(s => ({ ...s, excludeSources: sources }))} setExcludeSources={sources => setSettings(s => ({ ...s, excludeSources: sources }))}
/> />
@ -664,7 +664,8 @@ function ModalComponent({
resolution: "1080", resolution: "1080",
fps: "60", fps: "60",
contentHint: "motion", contentHint: "motion",
audio: true audio: true,
audioSources: "None"
}); });
return ( return (

View file

@ -31,15 +31,17 @@ export interface Settings {
spellCheckLanguages?: string[]; spellCheckLanguages?: string[];
audioWorkaround?: boolean; audio?: {
audioGranularSelect?: boolean; workaround?: boolean;
granularSelect?: boolean;
audioIgnoreVirtual?: boolean; ignoreVirtual?: boolean;
audioIgnoreDevices?: boolean; ignoreDevices?: boolean;
audioIgnoreInputMedia?: boolean; ignoreInputMedia?: boolean;
audioOnlySpeakers?: boolean; onlySpeakers?: boolean;
audioOnlyDefaultSpeakers?: boolean; onlyDefaultSpeakers?: boolean;
};
} }
export interface State { export interface State {