Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround screenshare audio using microphone on debian bug #360

Merged
merged 4 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions src/main/venmic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
* Copyright (c) 2023 Vendicated and Vencord contributors
*/

import { PatchBay } from "@vencord/venmic";
Curve marked this conversation as resolved.
Show resolved Hide resolved
import { app, ipcMain } from "electron";
import { join } from "path";
import { IpcEvents } from "shared/IpcEvents";
import { STATIC_DIR } from "shared/paths";

type LinkData = Parameters<PatchBay["link"]>[0];

let initialized = false;
let patchBay: import("@vencord/venmic").PatchBay | undefined;
let isGlibcxxToOld = false;
Expand Down Expand Up @@ -51,17 +54,35 @@
: { ok: false, isGlibcxxToOld };
});

ipcMain.handle(IpcEvents.VIRT_MIC_START, (_, targets: string[]) =>
obtainVenmic()?.link({
ipcMain.handle(IpcEvents.VIRT_MIC_START, (_, targets: string[], workaround?: boolean) => {
const data: LinkData = {
include: targets.map(target => ({ key: "application.name", value: target })),
exclude: [{ key: "application.process.id", value: getRendererAudioServicePid() }]
})
);
};

if (workaround) {
data.workaround = [

Check failure on line 64 in src/main/venmic.ts

View workflow job for this annotation

GitHub Actions / test

Property 'workaround' does not exist on type 'Optional<LinkData, "exclude"> | Optional<LinkData, "include">'.
{ key: "application.process.id", value: getRendererAudioServicePid() },
Curve marked this conversation as resolved.
Show resolved Hide resolved
{ key: "media.name", value: "RecordStream" }
];
}

return obtainVenmic()?.link(data);
});

ipcMain.handle(IpcEvents.VIRT_MIC_START_SYSTEM, () =>
obtainVenmic()?.link({
ipcMain.handle(IpcEvents.VIRT_MIC_START_SYSTEM, (_, workaround?: boolean) => {
const data: LinkData = {
exclude: [{ key: "application.process.id", value: getRendererAudioServicePid() }]
})
);
};

if (workaround) {
data.workaround = [

Check failure on line 79 in src/main/venmic.ts

View workflow job for this annotation

GitHub Actions / test

Property 'workaround' does not exist on type 'Optional<LinkData, "include">'.
{ key: "application.process.id", value: getRendererAudioServicePid() },
{ key: "media.name", value: "RecordStream" }
];
}

return obtainVenmic()?.link(data);
});

ipcMain.handle(IpcEvents.VIRT_MIC_STOP, () => obtainVenmic()?.unlink());
4 changes: 2 additions & 2 deletions src/preload/VesktopNative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ export const VesktopNative = {
virtmic: {
list: () =>
invoke<{ ok: false; isGlibcxxToOld: boolean } | { ok: true; targets: string[] }>(IpcEvents.VIRT_MIC_LIST),
start: (targets: string[]) => invoke<void>(IpcEvents.VIRT_MIC_START, targets),
startSystem: () => invoke<void>(IpcEvents.VIRT_MIC_START_SYSTEM),
start: (targets: string[], workaround?: boolean) => invoke<void>(IpcEvents.VIRT_MIC_START, targets, workaround),
startSystem: (workaround?: boolean) => invoke<void>(IpcEvents.VIRT_MIC_START_SYSTEM, workaround),
stop: () => invoke<void>(IpcEvents.VIRT_MIC_STOP)
},
arrpc: {
Expand Down
30 changes: 26 additions & 4 deletions src/renderer/components/ScreenSharePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import "./screenSharePicker.css";

import { closeModal, Modals, openModal, useAwaiter } from "@vencord/types/utils";
import { closeModal, Margins, Modals, openModal, useAwaiter } from "@vencord/types/utils";
import { findStoreLazy, onceReady } from "@vencord/types/webpack";
import {
Button,
Expand Down Expand Up @@ -36,6 +36,7 @@ interface StreamSettings {
fps: StreamFps;
audio: boolean;
audioSource?: string;
workaround?: boolean;
}

export interface StreamPick extends StreamSettings {
Expand Down Expand Up @@ -107,9 +108,9 @@ export function openScreenSharePicker(screens: Source[], skipPicker: boolean) {
didSubmit = true;
if (v.audioSource && v.audioSource !== "None") {
if (v.audioSource === "Entire System") {
await VesktopNative.virtmic.startSystem();
await VesktopNative.virtmic.startSystem(v.workaround);
} else {
await VesktopNative.virtmic.start([v.audioSource]);
await VesktopNative.virtmic.start([v.audioSource], v.workaround);
}
}
resolve(v);
Expand Down Expand Up @@ -228,7 +229,9 @@ function StreamSettings({
{isLinux && (
<AudioSourcePickerLinux
audioSource={settings.audioSource}
workaround={settings.workaround}
setAudioSource={source => setSettings(s => ({ ...s, audioSource: source }))}
setWorkaround={workaround => setSettings(s => ({ ...s, workaround: workaround }))}
/>
)}
</Card>
Expand All @@ -238,10 +241,14 @@ function StreamSettings({

function AudioSourcePickerLinux({
audioSource,
setAudioSource
workaround,
setAudioSource,
setWorkaround
}: {
audioSource?: string;
workaround?: boolean;
setAudioSource(s: string): void;
setWorkaround(b: boolean): void;
}) {
const [sources, _, loading] = useAwaiter(() => VesktopNative.virtmic.list(), {
fallbackValue: { ok: true, targets: [] }
Expand Down Expand Up @@ -276,6 +283,21 @@ function AudioSourcePickerLinux({
serialize={String}
/>
)}

<Forms.FormDivider className={Margins.top16 + " " + Margins.bottom16} />

<Switch
onChange={setWorkaround}
value={workaround ?? false}
note={
<>
Work around an issue that causes the microphone to be shared instead of the correct audio. Only
enable if you're experiencing this issue.
</>
}
>
Microphone Workaround
</Switch>
</section>
);
}
Expand Down
Loading