This commit is contained in:
thororen 2024-04-24 13:02:49 -04:00
parent 2cb6975f95
commit 97e59d3869
21 changed files with 75 additions and 287 deletions

View file

@ -1,31 +0,0 @@
/*
* Vencord, a modification for Discord's desktop app
* Copyright (c) 2023 Vendicated and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { Devs } from "@utils/constants";
import { types } from "../../philsPluginLibrary";
export const PluginInfo = {
PLUGIN_NAME: "BetterMicrophone",
DESCRIPTION: "This plugin allows you to further customize your microphone.",
AUTHOR: {
...Devs.philhk,
github: "https://github.com/philhk"
},
CONTRIBUTORS: {}
} as const satisfies types.PluginInfo;

View file

@ -1,19 +0,0 @@
/*
* Vencord, a modification for Discord's desktop app
* Copyright (c) 2023 Vendicated and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
export * from "./constants";

View file

@ -16,42 +16,32 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { PluginAuthor, PluginDef } from "@utils/types";
import { Devs } from "@utils/constants";
import definePlugin from "@utils/types";
import { addSettingsPanelButton, Emitter, MicrophoneSettingsIcon, removeSettingsPanelButton } from "../philsPluginLibrary";
import { PluginInfo } from "./constants";
import { openMicrophoneSettingsModal } from "./modals";
import { MicrophonePatcher } from "./patchers";
import { initMicrophoneStore } from "./stores";
export default new class Plugin implements PluginDef {
readonly name: string;
readonly description: string;
readonly authors: PluginAuthor[];
readonly dependencies: string[];
let microphonePatcher;
public microphonePatcher?: MicrophonePatcher;
constructor() {
this.name = PluginInfo.PLUGIN_NAME;
this.description = PluginInfo.DESCRIPTION;
this.authors = [PluginInfo.AUTHOR, ...Object.values(PluginInfo.CONTRIBUTORS)] as PluginAuthor[];
this.dependencies = ["PhilsPluginLibrary"];
}
start(): void {
export default definePlugin({
name: "BetterMicrophone",
description: "This plugin allows you to further customize your microphone.",
authors: [Devs.philhk],
dependencies: ["PhilsPluginLibrary"],
microphonePatcher,
start() {
initMicrophoneStore();
this.microphonePatcher = new MicrophonePatcher().patch();
addSettingsPanelButton({ name: PluginInfo.PLUGIN_NAME, icon: MicrophoneSettingsIcon, tooltipText: "Microphone Settings", onClick: openMicrophoneSettingsModal });
}
stop(): void {
addSettingsPanelButton({ name: "BetterMicrophone", icon: MicrophoneSettingsIcon, tooltipText: "Microphone Settings", onClick: openMicrophoneSettingsModal });
},
stop() {
this.microphonePatcher?.unpatch();
Emitter.removeAllListeners(PluginInfo.PLUGIN_NAME);
Emitter.removeAllListeners("BetterMicrophone");
removeSettingsPanelButton(PluginInfo.PLUGIN_NAME);
removeSettingsPanelButton("BetterMicrophone");
}
};
});

View file

@ -18,6 +18,4 @@
import { Logger } from "@utils/Logger";
import { PluginInfo } from "../constants";
export const logger = new Logger(PluginInfo.PLUGIN_NAME);
export const logger = new Logger("BetterMicrophone");

View file

@ -16,10 +16,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { Devs } from "@utils/constants";
import { openModalLazy } from "@utils/modal";
import { MicrophoneSettingsModal } from "../components";
import { PluginInfo } from "../constants";
import Plugin from "../index";
import { microphoneStore } from "../stores";
@ -37,7 +37,6 @@ export const openMicrophoneSettingsModal =
onDone={onMicrophoneModalDone}
showInfo
microphoneStore={microphoneStore}
author={PluginInfo.AUTHOR}
contributors={Object.values(PluginInfo.CONTRIBUTORS)}
author={Devs.philhk}
{...props} />;
});

View file

@ -18,7 +18,6 @@
import { Emitter, MediaEngineStore, Patcher, types } from "../../philsPluginLibrary";
import { patchConnectionAudioTransportOptions } from "../../philsPluginLibrary/patches/audio";
import { PluginInfo } from "../constants";
import { logger } from "../logger";
import { microphoneStore } from "../stores";
@ -59,7 +58,7 @@ export class MicrophonePatcher extends Patcher {
"on",
"connection",
connectionEventFunction,
PluginInfo.PLUGIN_NAME
"BetterMicrophone"
);
return this;

View file

@ -17,7 +17,6 @@
*/
import { createPluginStore, ProfilableInitializer, ProfilableStore, profileable, ProfileableProfile } from "../../philsPluginLibrary";
import { PluginInfo } from "../constants";
export interface MicrophoneProfile {
@ -84,7 +83,7 @@ export let microphoneStore: ProfilableStore<MicrophoneStore, MicrophoneProfile>;
export const initMicrophoneStore = () =>
microphoneStore = createPluginStore(
PluginInfo.PLUGIN_NAME,
"BetterMicrophone",
"MicrophoneStore",
profileable(
microphoneStoreDefault,

View file

@ -19,13 +19,12 @@
import { Flex } from "@components/Flex";
import { Switch } from "@components/Switch";
import { ModalSize, openModalLazy } from "@utils/modal";
import { Button, Card, Forms, React, Select, Slider, TextInput, useEffect, useState } from "@webpack/common";
import { Button, Forms, React, Select, Slider, TextInput, useEffect, useState } from "@webpack/common";
import { SelectOption } from "@webpack/types";
import { MicrophoneSettingsModal } from "../../betterMicrophone.desktop/components";
import {
MediaEngineStore,
openURL,
ProfilableStore,
SettingsModal,
SettingsModalCard,
@ -36,8 +35,6 @@ import {
validateNumberInput,
validateTextInputNumber
} from "../../philsPluginLibrary";
import { Styles } from "../../philsPluginLibrary/styles";
import { PluginInfo } from "../constants";
import { ScreenshareAudioProfile, ScreenshareAudioStore, ScreenshareProfile, ScreenshareStore } from "../stores";
const simpleResolutions: readonly (SelectOption & { value: types.Resolution; })[] = [
@ -403,12 +400,6 @@ export const ScreenshareSettingsModal = (props: ScreenshareSettingsModalProps) =
onChange: status => setHdrEnabled(status)
}} />;
const guideCard =
<Card style={{ ...Styles.infoCard, flex: 0.4 }}>
<Forms.FormTitle tag="h5">How to use?</Forms.FormTitle>
<Forms.FormText>If you want to know more about the settings or possible issues, please read <a onClick={() => openURL(PluginInfo.README + "#better-screenshare-plugin")}>this</a>.</Forms.FormText>
</Card>;
const settingsCardProfiles =
<SettingsModalProfilesCard flex={0.5} onSaveStateChanged={state => setIsSaving(state)} profileableStore={screenshareStore} />;
@ -456,7 +447,6 @@ export const ScreenshareSettingsModal = (props: ScreenshareSettingsModalProps) =
{screenshareAudioStore && settingsCardAudio}
</SettingsModalCardRow>
<SettingsModalCardRow>
{guideCard}
{settingsCardHdr}
{settingsCardProfiles}
</SettingsModalCardRow>

View file

@ -1,38 +0,0 @@
/*
* Vencord, a modification for Discord's desktop app
* Copyright (c) 2023 Vendicated and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { Devs } from "@utils/constants";
import { types } from "../../philsPluginLibrary";
export const PluginInfo = {
PLUGIN_NAME: "BetterScreenshare",
DESCRIPTION: "This plugin allows you to further customize your screen sharing.",
AUTHOR: {
...Devs.philhk,
github: "https://github.com/philhk"
},
CONTRIBUTORS: {
walrus: {
github: "https://github.com/philhk",
id: 305317288775778306n,
name: "walrus"
},
},
README: "https://github.com/Vendicated/Vencord/tree/main/src/plugins/betterScreenshare"
} as const satisfies types.PluginInfo;

View file

@ -1,19 +0,0 @@
/*
* Vencord, a modification for Discord's desktop app
* Copyright (c) 2023 Vendicated and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
export * from "./constants";

View file

@ -17,70 +17,55 @@
*/
import { definePluginSettings } from "@api/Settings";
import { DefinedSettings, OptionType, Patch, PluginAuthor, PluginDef, SettingsDefinition } from "@utils/types";
import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
import { addSettingsPanelButton, Emitter, removeSettingsPanelButton, ScreenshareSettingsIcon } from "../philsPluginLibrary";
import { PluginInfo } from "./constants";
import { openScreenshareModal } from "./modals";
import { ScreenshareAudioPatcher, ScreensharePatcher } from "./patchers";
import { replacedScreenshareModalComponent } from "./patches";
import { initScreenshareAudioStore, initScreenshareStore } from "./stores";
export default new class Plugin implements PluginDef {
readonly name: string;
readonly description: string;
readonly authors: PluginAuthor[];
readonly patches: Omit<Patch, "plugin">[];
readonly settings: DefinedSettings<SettingsDefinition, {}>;
readonly dependencies: string[];
private readonly replacedScreenshareModalComponent: typeof replacedScreenshareModalComponent;
public screensharePatcher?: ScreensharePatcher;
public screenshareAudioPatcher?: ScreenshareAudioPatcher;
constructor() {
this.name = PluginInfo.PLUGIN_NAME;
this.description = PluginInfo.DESCRIPTION;
this.authors = [PluginInfo.AUTHOR, ...Object.values(PluginInfo.CONTRIBUTORS)] as PluginAuthor[];
this.patches = [
{
find: "Messages.SCREENSHARE_RELAUNCH",
replacement: {
match: /(function .{1,2}\(.{1,2}\){)(.{1,40}(?=selectGuild).+?(?:]}\)}\)))(})/,
replace: "$1return $self.replacedScreenshareModalComponent(function(){$2}, this, arguments)$3"
}
}
];
this.settings = definePluginSettings({
hideDefaultSettings: {
type: OptionType.BOOLEAN,
description: "Hide Discord screen sharing settings",
default: true,
}
});
this.dependencies = ["PhilsPluginLibrary"];
this.replacedScreenshareModalComponent = replacedScreenshareModalComponent;
const settings = definePluginSettings({
hideDefaultSettings: {
type: OptionType.BOOLEAN,
description: "Hide Discord screen sharing settings",
default: true,
}
});
export default definePlugin({
name: "BetterScreenshare",
description: "This plugin allows you to further customize your screen sharing.",
authors: [Devs.philhk],
dependencies: ["PhilsPluginLibrary"],
settings,
patches: [
{
find: "Messages.SCREENSHARE_RELAUNCH",
replacement: {
match: /(function .{1,2}\(.{1,2}\){)(.{1,40}(?=selectGuild).+?(?:]}\)}\)))(})/,
replace: "$1return $self.replacedScreenshareModalComponent(function(){$2}, this, arguments)$3"
}
}
],
replacedScreenshareModalComponent: replacedScreenshareModalComponent,
start(): void {
initScreenshareStore();
initScreenshareAudioStore();
this.screensharePatcher = new ScreensharePatcher().patch();
this.screenshareAudioPatcher = new ScreenshareAudioPatcher().patch();
addSettingsPanelButton({
name: PluginInfo.PLUGIN_NAME,
name: "BetterScreenshare",
icon: ScreenshareSettingsIcon,
tooltipText: "Screenshare Settings",
onClick: openScreenshareModal
});
}
stop(): void {
},
stop() {
this.screensharePatcher?.unpatch();
this.screenshareAudioPatcher?.unpatch();
Emitter.removeAllListeners(PluginInfo.PLUGIN_NAME);
removeSettingsPanelButton(PluginInfo.PLUGIN_NAME);
Emitter.removeAllListeners("BetterScreenshare");
removeSettingsPanelButton("BetterScreenshare");
}
};
});

View file

@ -18,6 +18,5 @@
import { Logger } from "@utils/Logger";
import { PluginInfo } from "../constants";
export const logger = new Logger(PluginInfo.PLUGIN_NAME);
export const logger = new Logger("BetterScreenshare");

View file

@ -16,11 +16,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { Devs } from "@utils/constants";
import { openModalLazy } from "@utils/modal";
import Plugin from "..";
import { ScreenshareSettingsModal } from "../components";
import { PluginInfo } from "../constants";
import { screenshareAudioStore, screenshareStore } from "../stores";
const onScreenshareModalDone = () => {
@ -49,7 +49,6 @@ export const openScreenshareModal =
onDone={onScreenshareModalDone}
screenshareStore={screenshareStore}
screenshareAudioStore={screenshareAudioStore}
author={PluginInfo.AUTHOR}
contributors={Object.values(PluginInfo.CONTRIBUTORS)}
author={Devs.philhk}
{...props} />;
});

View file

@ -20,7 +20,6 @@ import { UserStore } from "@webpack/common";
import { Emitter, MediaEngineStore, Patcher, types } from "../../philsPluginLibrary";
import { patchConnectionVideoSetDesktopSourceWithOptions, patchConnectionVideoTransportOptions } from "../../philsPluginLibrary/patches/video";
import { PluginInfo } from "../constants";
import { logger } from "../logger";
import { screenshareStore } from "../stores";
@ -87,7 +86,7 @@ export class ScreensharePatcher extends Patcher {
"on",
"connection",
connectionEventFunction,
PluginInfo.PLUGIN_NAME
"BetterScreenshare"
);
return this;

View file

@ -19,7 +19,6 @@
import { UserStore } from "@webpack/common";
import { Emitter, MediaEngineStore, patchConnectionAudioTransportOptions, Patcher, types } from "../../philsPluginLibrary";
import { PluginInfo } from "../constants";
import { logger } from "../logger";
import { screenshareAudioStore } from "../stores/screenshareAudioStore";
@ -73,7 +72,7 @@ export class ScreenshareAudioPatcher extends Patcher {
"on",
"connection",
connectionEventFunction,
PluginInfo.PLUGIN_NAME
"BetterScreenshare"
);
return this;

View file

@ -23,7 +23,6 @@ import { Settings } from "Vencord";
import { SettingsModalCard, SettingsModalCardItem } from "../../philsPluginLibrary";
import Plugin from "..";
import { AudioSourceSelect, OpenScreenshareSettingsButton } from "../components";
import { PluginInfo } from "../constants";
import { screenshareStore } from "../stores";
const ReplacedStreamSettings = () => {
@ -59,7 +58,7 @@ const ReplacedStreamSettings = () => {
};
export function replacedScreenshareModalSettingsContentType(oldType: (...args: any[]) => any, thisContext: any, functionArguments: any) {
const { hideDefaultSettings } = Settings.plugins[PluginInfo.PLUGIN_NAME];
const { hideDefaultSettings } = Settings.plugins.BetterScreenshare;
const oldTypeResult = Reflect.apply(oldType, thisContext, functionArguments);
if (hideDefaultSettings)

View file

@ -23,13 +23,12 @@ import {
microphoneStoreDefault as screenshareAudioStoreDefault
} from "../../betterMicrophone.desktop/stores";
import { createPluginStore, ProfilableStore, profileable } from "../../philsPluginLibrary";
import { PluginInfo } from "../constants";
export let screenshareAudioStore: ProfilableStore<ScreenshareAudioStore, ScreenshareAudioProfile>;
export const initScreenshareAudioStore = () =>
screenshareAudioStore = createPluginStore(
PluginInfo.PLUGIN_NAME,
"BetterScreenshare",
"ScreenshareAudioStore",
profileable(
screenshareAudioStoreDefault,

View file

@ -17,7 +17,6 @@
*/
import { createPluginStore, ProfilableInitializer, ProfilableStore, profileable, ProfileableProfile } from "../../philsPluginLibrary";
import { PluginInfo } from "../constants";
export interface ScreenshareProfile {
@ -112,7 +111,7 @@ export let screenshareStore: ProfilableStore<ScreenshareStore, ScreenshareProfil
export const initScreenshareStore = () =>
screenshareStore = createPluginStore(
PluginInfo.PLUGIN_NAME,
"BetterScreenshare",
"ScreenshareStore",
profileable(
screenshareStoreDefault,

View file

@ -1,30 +0,0 @@
/*
* Vencord, a modification for Discord's desktop app
* Copyright (c) 2023 Vendicated and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { Devs } from "@utils/constants";
import * as types from "../types/constants";
export const PluginInfo: types.PluginInfo = {
PLUGIN_NAME: "PhilsPluginLibrary",
DESCRIPTION: "A library for phil's plugins",
AUTHOR: {
...Devs.philhk,
github: "https://github.com/philhk"
},
} as const;

View file

@ -1,19 +0,0 @@
/*
* Vencord, a modification for Discord's desktop app
* Copyright (c) 2023 Vendicated and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
export * from "./constants";

View file

@ -16,33 +16,24 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { Patch, PluginAuthor, PluginDef } from "@utils/types";
import { Devs } from "@utils/constants";
import definePlugin from "@utils/types";
import { PluginInfo } from "./constants";
import { replacedUserPanelComponent } from "./patches";
export default new class Plugin implements PluginDef {
readonly name: string;
readonly description: string;
readonly authors: PluginAuthor[];
readonly patches: Omit<Patch, "plugin">[];
readonly replacedUserPanelComponent: typeof replacedUserPanelComponent;
constructor() {
this.name = PluginInfo.PLUGIN_NAME;
this.description = PluginInfo.DESCRIPTION;
this.authors = PluginInfo.AUTHORS as PluginAuthor[];
this.patches = [{
find: "Messages.ACCOUNT_A11Y_LABEL",
replacement: {
match: /(?<=function)( .{0,8}(?={).)(.{0,1000}isFullscreenInContext\(\).+?\)]}\))(})/,
replace: "$1return $self.replacedUserPanelComponent(function(){$2}, this, arguments)$3"
}
}];
this.replacedUserPanelComponent = replacedUserPanelComponent;
}
};
export default definePlugin({
name: "PhilsPluginLibrary",
description: "A library for phil's plugins",
authors: [Devs.philhk],
patches: [{
find: "Messages.ACCOUNT_A11Y_LABEL",
replacement: {
match: /(?<=function)( .{0,8}(?={).)(.{0,1000}isFullscreenInContext\(\).+?\)]}\))(})/,
replace: "$1return $self.replacedUserPanelComponent(function(){$2}, this, arguments)$3"
}
}],
replacedUserPanelComponent: replacedUserPanelComponent
});
export * from "./components";
export * from "./discordModules";