Skip to content

Commit

Permalink
stop virtmic on vc exit
Browse files Browse the repository at this point in the history
  • Loading branch information
Vendicated committed Oct 15, 2023
1 parent bc8587b commit baaecab
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/virtmic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ ipcMain.handle(
() => obtainVenmic()?.link("application.process.id", getRendererAudioServicePid(), "exclude")
);

ipcMain.handle(IpcEvents.VIRT_MIC_KILL, () => obtainVenmic()?.unlink());
ipcMain.handle(IpcEvents.VIRT_MIC_STOP, () => obtainVenmic()?.unlink());
2 changes: 1 addition & 1 deletion src/preload/VesktopNative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const VesktopNative = {
list: () => invoke<string[] | null>(IpcEvents.VIRT_MIC_LIST),
start: (target: string) => invoke<void>(IpcEvents.VIRT_MIC_START, target),
startSystem: () => invoke<void>(IpcEvents.VIRT_MIC_START_SYSTEM),
kill: () => invoke<void>(IpcEvents.VIRT_MIC_KILL)
stop: () => invoke<void>(IpcEvents.VIRT_MIC_STOP)
},
arrpc: {
onActivity(cb: (data: string) => void) {
Expand Down
25 changes: 23 additions & 2 deletions src/renderer/components/ScreenSharePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,18 @@
import "./screenSharePicker.css";

import { closeModal, Modals, openModal, useAwaiter } from "@vencord/types/utils";
import { findStoreLazy } from "@vencord/types/webpack";
import { Button, Card, Forms, Select, Switch, Text, useState } from "@vencord/types/webpack/common";
import { findStoreLazy, onceReady } from "@vencord/types/webpack";
import {
Button,
Card,
FluxDispatcher,
Forms,
Select,
Switch,
Text,
UserStore,
useState
} from "@vencord/types/webpack/common";
import type { Dispatch, SetStateAction } from "react";
import { addPatch } from "renderer/patches/shared";
import { isLinux, isWindows } from "renderer/utils";
Expand Down Expand Up @@ -71,6 +81,17 @@ addPatch({
}
});

if (isLinux) {
onceReady.then(() => {
FluxDispatcher.subscribe("VOICE_STATE_UPDATES", e => {
for (const state of e.voiceStates) {
if (state.userId === UserStore.getCurrentUser().id && state.oldChannelId && !state.channelId)
VesktopNative.virtmic.stop();
}
});
});
}

export function openScreenSharePicker(screens: Source[], skipPicker: boolean) {
let didSubmit = false;
return new Promise<StreamPick>((resolve, reject) => {
Expand Down
2 changes: 1 addition & 1 deletion src/shared/IpcEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const enum IpcEvents {
VIRT_MIC_LIST = "VCD_VIRT_MIC_LIST",
VIRT_MIC_START = "VCD_VIRT_MIC_START",
VIRT_MIC_START_SYSTEM = "VCD_VIRT_MIC_START_ALL",
VIRT_MIC_KILL = "VCD_VIRT_MIC_STOP",
VIRT_MIC_STOP = "VCD_VIRT_MIC_STOP",

ARRPC_ACTIVITY = "VCD_ARRPC_ACTIVITY"
}

0 comments on commit baaecab

Please sign in to comment.