mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-07 13:43:03 -04:00
InstantScreenshare: Mass Rewrite Settings
This commit is contained in:
parent
88c03c79bc
commit
70286e4867
2 changed files with 112 additions and 39 deletions
|
@ -4,60 +4,31 @@
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { definePluginSettings } from "@api/Settings";
|
|
||||||
import { Devs, EquicordDevs } from "@utils/constants";
|
import { Devs, EquicordDevs } from "@utils/constants";
|
||||||
import definePlugin, { OptionType } from "@utils/types";
|
import definePlugin from "@utils/types";
|
||||||
import { findByCode, findByProps } from "@webpack";
|
import { findByCodeLazy } from "@webpack";
|
||||||
import { ChannelStore, PermissionsBits, PermissionStore, SelectedChannelStore, UserStore } from "@webpack/common";
|
import { ChannelStore, PermissionsBits, PermissionStore, SelectedChannelStore, UserStore } from "@webpack/common";
|
||||||
import { VoiceState } from "@webpack/types";
|
import { VoiceState } from "@webpack/types";
|
||||||
|
|
||||||
const settings = definePluginSettings({
|
import { getCurrentMedia, settings } from "./utils";
|
||||||
streamType: {
|
|
||||||
description: "Stream screen or window",
|
const startStream = findByCodeLazy('type:"STREAM_START"');
|
||||||
type: OptionType.SELECT,
|
|
||||||
options: [
|
|
||||||
{ label: "Screen", value: "screen" },
|
|
||||||
{ label: "Window", value: "window" }
|
|
||||||
],
|
|
||||||
default: "screen"
|
|
||||||
},
|
|
||||||
streamWindowKeyword: {
|
|
||||||
description: "Keyword to search for in window title",
|
|
||||||
type: OptionType.STRING,
|
|
||||||
default: "",
|
|
||||||
placeholder: "Enter keyword"
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let hasStreamed;
|
let hasStreamed;
|
||||||
let sources;
|
|
||||||
let source;
|
|
||||||
|
|
||||||
async function startStream() {
|
async function autoStartStream() {
|
||||||
const startStream = findByCode('type:"STREAM_START"');
|
|
||||||
const mediaEngine = findByProps("getMediaEngine").getMediaEngine();
|
|
||||||
const getDesktopSources = findByCode("desktop sources");
|
|
||||||
const selected = SelectedChannelStore.getVoiceChannelId();
|
const selected = SelectedChannelStore.getVoiceChannelId();
|
||||||
if (!selected) return;
|
if (!selected) return;
|
||||||
const channel = ChannelStore.getChannel(selected);
|
const channel = ChannelStore.getChannel(selected);
|
||||||
|
|
||||||
if (channel.type === 13 || !PermissionStore.can(PermissionsBits.STREAM, channel)) return;
|
if (channel.type === 13 || !PermissionStore.can(PermissionsBits.STREAM, channel)) return;
|
||||||
|
|
||||||
if (settings.store.streamType === "screen") {
|
const streamMedia = await getCurrentMedia();
|
||||||
sources = await getDesktopSources(mediaEngine, ["screen"], null);
|
|
||||||
source = sources[0];
|
|
||||||
} else if (settings.store.streamType === "window") {
|
|
||||||
const keyword = settings.store.streamWindowKeyword?.toLowerCase();
|
|
||||||
sources = await getDesktopSources(mediaEngine, ["window", "application"], null);
|
|
||||||
source = sources.find(s => s.name?.toLowerCase().includes(keyword));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!source) return;
|
|
||||||
|
|
||||||
startStream(channel.guild_id, selected, {
|
startStream(channel.guild_id, selected, {
|
||||||
"pid": null,
|
"pid": null,
|
||||||
"sourceId": source.id,
|
"sourceId": streamMedia.id,
|
||||||
"sourceName": source.name,
|
"sourceName": streamMedia.name,
|
||||||
"audioSourceId": null,
|
"audioSourceId": null,
|
||||||
"sound": true,
|
"sound": true,
|
||||||
"previewDisabled": false
|
"previewDisabled": false
|
||||||
|
@ -78,7 +49,7 @@ export default definePlugin({
|
||||||
|
|
||||||
if (channelId && !hasStreamed) {
|
if (channelId && !hasStreamed) {
|
||||||
hasStreamed = true;
|
hasStreamed = true;
|
||||||
await startStream();
|
await autoStartStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!channelId) {
|
if (!channelId) {
|
||||||
|
|
102
src/equicordplugins/instantScreenshare/utils.tsx
Normal file
102
src/equicordplugins/instantScreenshare/utils.tsx
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
/*
|
||||||
|
* Vencord, a Discord client mod
|
||||||
|
* Copyright (c) 2025 Vendicated and contributors
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { definePluginSettings } from "@api/Settings";
|
||||||
|
import { Logger } from "@utils/Logger";
|
||||||
|
import { OptionType } from "@utils/types";
|
||||||
|
import { findByCodeLazy, findByPropsLazy } from "@webpack";
|
||||||
|
import { Forms, SearchableSelect, useEffect, useState } from "@webpack/common";
|
||||||
|
|
||||||
|
interface PickerProps {
|
||||||
|
streamMediaSelection: any[];
|
||||||
|
streamMedia: any[];
|
||||||
|
}
|
||||||
|
|
||||||
|
const mediaEngine = findByPropsLazy("getMediaEngine");
|
||||||
|
const getDesktopSources = findByCodeLazy("desktop sources");
|
||||||
|
|
||||||
|
export const settings = definePluginSettings({
|
||||||
|
streamMedia: {
|
||||||
|
description: "Media source to stream resets to main screen if not found",
|
||||||
|
type: OptionType.COMPONENT,
|
||||||
|
component: SettingSection,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export async function getCurrentMedia() {
|
||||||
|
const media = mediaEngine.getMediaEngine();
|
||||||
|
const sources = [
|
||||||
|
...(await getDesktopSources(media, ["screen"], null) ?? []),
|
||||||
|
...(await getDesktopSources(media, ["window", "application"], null) ?? [])
|
||||||
|
];
|
||||||
|
const streamMedia = sources.find(screen => screen.id === settings.store.streamMedia);
|
||||||
|
console.log(sources);
|
||||||
|
|
||||||
|
if (streamMedia) return streamMedia;
|
||||||
|
|
||||||
|
new Logger("InstantScreenShare").error(`Stream Media "${settings.store.streamMedia}" not found. Resetting to default.`);
|
||||||
|
|
||||||
|
settings.store.streamMedia = sources[0];
|
||||||
|
return sources[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
function StreamSimplePicker({ streamMediaSelection, streamMedia }: PickerProps) {
|
||||||
|
const options = streamMediaSelection.map(screen => ({
|
||||||
|
label: screen.name,
|
||||||
|
value: screen.id,
|
||||||
|
default: streamMediaSelection[0],
|
||||||
|
}));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SearchableSelect
|
||||||
|
placeholder="Select a media source"
|
||||||
|
maxVisibleItems={5}
|
||||||
|
options={options}
|
||||||
|
value={options.find(o => o.value === streamMedia)}
|
||||||
|
onChange={v => settings.store.streamMedia = v}
|
||||||
|
closeOnSelect
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function ScreenSetting() {
|
||||||
|
const { streamMedia } = settings.use(["streamMedia"]);
|
||||||
|
const media = mediaEngine.getMediaEngine();
|
||||||
|
const [streamMediaSelection, setStreamMediaSelection] = useState<any[]>([]);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let active = true;
|
||||||
|
async function fetchMedia() {
|
||||||
|
setLoading(true);
|
||||||
|
const sources = [
|
||||||
|
...(await getDesktopSources(media, ["screen"], null) ?? []),
|
||||||
|
...(await getDesktopSources(media, ["window", "application"], null) ?? [])
|
||||||
|
];
|
||||||
|
|
||||||
|
if (active) {
|
||||||
|
setStreamMediaSelection(sources);
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fetchMedia();
|
||||||
|
return () => { active = false; };
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
if (loading) return <Forms.FormText>Loading media sources...</Forms.FormText>;
|
||||||
|
if (!streamMediaSelection.length) return <Forms.FormText>No Media found.</Forms.FormText>;
|
||||||
|
|
||||||
|
return <StreamSimplePicker streamMediaSelection={streamMediaSelection} streamMedia={streamMedia} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
function SettingSection() {
|
||||||
|
return (
|
||||||
|
<Forms.FormSection>
|
||||||
|
<Forms.FormTitle>Stream Media</Forms.FormTitle>
|
||||||
|
<ScreenSetting />
|
||||||
|
</Forms.FormSection>
|
||||||
|
);
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue