From 7948d56c00a03ef958fb9dc282db19bbed8e4797 Mon Sep 17 00:00:00 2001
From: thororen1234 <78185467+thororen1234@users.noreply.github.com>
Date: Fri, 6 Mar 2026 14:38:08 -0500
Subject: [PATCH] InstantScreenShare: Stop Stream If Already Streaming
---
.../instantScreenshare/index.tsx | 31 +++++++++++++------
src/plugins/betterSettings/index.tsx | 12 +++----
2 files changed, 28 insertions(+), 15 deletions(-)
diff --git a/src/equicordplugins/instantScreenshare/index.tsx b/src/equicordplugins/instantScreenshare/index.tsx
index 1a29d719f..1d0160048 100644
--- a/src/equicordplugins/instantScreenshare/index.tsx
+++ b/src/equicordplugins/instantScreenshare/index.tsx
@@ -15,8 +15,9 @@ import { ChannelStore, MediaEngineStore, PermissionsBits, PermissionStore, Selec
import { getCurrentMedia, settings } from "./utils";
-let hasStreamed;
+let hasStreamed, isStreaming, streamKey;
const startStream = findByCodeLazy('type:"STREAM_START"');
+const stopStream = findByCodeLazy('type:"STREAM_STOP"');
const StreamPreviewSettings = getUserSettingLazy("voiceAndVideo", "disableStreamPreviews")!;
const ApplicationStreamingSettingsStore = findStoreLazy("ApplicationStreamingSettingsStore");
@@ -44,14 +45,18 @@ async function autoStartStream(instant = true) {
let sourceId = streamMedia.id;
if (streamMedia.type === "video_device") sourceId = `camera:${streamMedia.id}`;
- startStream(channel.guild_id ?? null, selected, {
- "pid": null,
- "sourceId": sourceId,
- "sourceName": streamMedia.name,
- "audioSourceId": streamMedia.name,
- "sound": soundshareEnabled,
- "previewDisabled": preview
- });
+ if (isStreaming && streamKey.endsWith(UserStore.getCurrentUser().id)) {
+ stopStream(streamKey);
+ } else {
+ startStream(channel.guild_id ?? null, selected, {
+ "pid": null,
+ "sourceId": sourceId,
+ "sourceName": streamMedia.name,
+ "audioSourceId": streamMedia.name,
+ "sound": soundshareEnabled,
+ "previewDisabled": preview
+ });
+ }
}
export default definePlugin({
@@ -122,6 +127,14 @@ export default definePlugin({
break;
}
+ },
+ STREAM_CREATE: d => {
+ streamKey = d;
+ isStreaming = true;
+ },
+ STREAM_DELETE: d => {
+ streamKey = d;
+ isStreaming = false;
}
},
diff --git a/src/plugins/betterSettings/index.tsx b/src/plugins/betterSettings/index.tsx
index 2ff627903..7360c32a3 100644
--- a/src/plugins/betterSettings/index.tsx
+++ b/src/plugins/betterSettings/index.tsx
@@ -13,7 +13,7 @@ import { Logger } from "@utils/Logger";
import definePlugin, { OptionType } from "@utils/types";
import { findCssClassesLazy } from "@webpack";
import { ComponentDispatch, FocusLock, Menu, useEffect, useRef } from "@webpack/common";
-import type { HTMLAttributes } from "react";
+import type { HTMLAttributes, ReactNode } from "react";
import fullHeightStyle from "./fullHeightContext.css?managed";
@@ -154,8 +154,8 @@ export default definePlugin({
predicate: () => settings.store.organizeMenu,
replacement: [
{
- match: /(\i)=(.{0,20}openUserSettings\)\(\i\)\));/,
- replace: "$1=$self.transformSettingsElements($2);",
+ match: /children:\[(\i),(?<=\1=.{0,30}\.openUserSettings.+?)/,
+ replace: "children:[$self.transformSettingsEntries($1),",
},
]
},
@@ -179,8 +179,8 @@ export default definePlugin({
return