Game Activity Toggle and SettingsStoreAPI (#587)
This commit is contained in:
parent
8c47b7080d
commit
ae80749dd8
|
@ -6,7 +6,7 @@ The cutest Discord client mod
|
|||
|
||||
- Super easy to install (Download Installer, open, click install button, done)
|
||||
- 100+ plugins built in: [See a list](https://gist.github.com/Vendicated/8696cde7b92548064a3ae92ead84d033)
|
||||
- Some highlights: SpotifyControls, Experiments, NoTrack, MessageLogger, QuickReply, Free Emotes/Stickers, CustomCommands, ShowHiddenChannels, PronounDB
|
||||
- Some highlights: SpotifyControls, GameActivityToggle, Experiments, NoTrack, MessageLogger, QuickReply, Free Emotes/Stickers, CustomCommands, ShowHiddenChannels, PronounDB
|
||||
- Fairly lightweight despite the many inbuilt plugins
|
||||
- Excellent Browser Support: Run Vencord in your Browser via extension or UserScript
|
||||
- Works on any Discord branch: Stable, Canary or PTB all work (though for the best experience I recommend stable!)
|
||||
|
|
71
src/api/SettingsStore.ts
Normal file
71
src/api/SettingsStore.ts
Normal file
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* 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 Logger from "@utils/Logger";
|
||||
import { proxyLazy } from "@utils/proxyLazy";
|
||||
import { findModuleId, wreq } from "@webpack";
|
||||
|
||||
import { Settings } from "./settings";
|
||||
|
||||
interface Setting<T> {
|
||||
/**
|
||||
* Get the setting value
|
||||
*/
|
||||
getSetting(): T;
|
||||
/**
|
||||
* Update the setting value
|
||||
* @param value The new value
|
||||
*/
|
||||
updateSetting(value: T | ((old: T) => T)): Promise<void>;
|
||||
/**
|
||||
* React hook for automatically updating components when the setting is updated
|
||||
*/
|
||||
useSetting(): T;
|
||||
settingsStoreApiGroup: string;
|
||||
settingsStoreApiName: string;
|
||||
}
|
||||
|
||||
const SettingsStores: Array<Setting<any>> | undefined = proxyLazy(() => {
|
||||
const modId = findModuleId('"textAndImages","renderSpoilers"');
|
||||
if (modId == null) return new Logger("SettingsStoreAPI").error("Didn't find stores module.");
|
||||
|
||||
const mod = wreq(modId);
|
||||
if (mod == null) return;
|
||||
|
||||
return Object.values(mod).filter((s: any) => s?.settingsStoreApiGroup) as any;
|
||||
});
|
||||
|
||||
/**
|
||||
* Get the store for a setting
|
||||
* @param group The setting group
|
||||
* @param name The name of the setting
|
||||
*/
|
||||
export function getSettingStore<T = any>(group: string, name: string): Setting<T> | undefined {
|
||||
if (!Settings.plugins.SettingsStoreAPI.enabled) throw new Error("Cannot use SettingsStoreAPI without setting as dependency.");
|
||||
|
||||
return SettingsStores?.find(s => s?.settingsStoreApiGroup === group && s?.settingsStoreApiName === name);
|
||||
}
|
||||
|
||||
/**
|
||||
* getSettingStore but lazy
|
||||
*/
|
||||
export function getSettingStoreLazy<T = any>(group: string, name: string) {
|
||||
if (!Settings.plugins.SettingsStoreAPI.enabled) throw new Error("Cannot use SettingsStoreAPI without setting as dependency.");
|
||||
|
||||
return proxyLazy(() => getSettingStore<T>(group, name));
|
||||
}
|
|
@ -28,6 +28,7 @@ import * as $MessagePopover from "./MessagePopover";
|
|||
import * as $Notices from "./Notices";
|
||||
import * as $Notifications from "./Notifications";
|
||||
import * as $ServerList from "./ServerList";
|
||||
import * as $SettingsStore from "./SettingsStore";
|
||||
import * as $Styles from "./Styles";
|
||||
|
||||
/**
|
||||
|
@ -85,6 +86,10 @@ export const MessageDecorations = $MessageDecorations;
|
|||
* An API allowing you to add components to member list users, in both DM's and servers
|
||||
*/
|
||||
export const MemberListDecorators = $MemberListDecorators;
|
||||
/**
|
||||
* An API allowing you to read, manipulate and automatically update components based on Discord settings
|
||||
*/
|
||||
export const SettingsStore = $SettingsStore;
|
||||
/**
|
||||
* An API allowing you to dynamically load styles
|
||||
* a
|
||||
|
|
38
src/plugins/apiSettingsStore.ts
Normal file
38
src/plugins/apiSettingsStore.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Vencord, a modification for Discord's desktop app
|
||||
* Copyright (c) 2022 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 definePlugin from "@utils/types";
|
||||
|
||||
export default definePlugin({
|
||||
name: "SettingsStoreAPI",
|
||||
description: "Patches Discord's SettingsStores to expose their group and name",
|
||||
authors: [Devs.Nuckyz],
|
||||
|
||||
patches: [
|
||||
{
|
||||
find: '"textAndImages","renderSpoilers"',
|
||||
replacement: [
|
||||
{
|
||||
match: /(?<=INFREQUENT_USER_ACTION.{0,20}),useSetting:function/,
|
||||
replace: ",settingsStoreApiGroup:arguments[0],settingsStoreApiName:arguments[1]$&"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
});
|
73
src/plugins/gameActivityToggle/index.tsx
Normal file
73
src/plugins/gameActivityToggle/index.tsx
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* 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 "./style.css";
|
||||
|
||||
import { getSettingStoreLazy } from "@api/SettingsStore";
|
||||
import ErrorBoundary from "@components/ErrorBoundary";
|
||||
import { Devs } from "@utils/constants";
|
||||
import definePlugin from "@utils/types";
|
||||
import { Tooltip } from "@webpack/common";
|
||||
|
||||
const ShowCurrentGame = getSettingStoreLazy<boolean>("status", "showCurrentGame");
|
||||
|
||||
function GameActivityToggleButton() {
|
||||
const showCurrentGame = ShowCurrentGame?.useSetting();
|
||||
|
||||
return (
|
||||
<Tooltip text="Toggle Game Activity">
|
||||
{tooltipProps => (
|
||||
<button
|
||||
{...tooltipProps}
|
||||
className="game-activity-toggle-btn"
|
||||
onClick={() => ShowCurrentGame?.updateSetting(old => !old)}
|
||||
>
|
||||
<svg
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 96 960 960"
|
||||
>
|
||||
<g fill="currentColor">
|
||||
<path d="M182 856q-51 0-79-35.5T82 734l42-300q9-60 53.5-99T282 296h396q60 0 104.5 39t53.5 99l42 300q7 51-21 86.5T778 856q-21 0-39-7.5T706 826l-90-90H344l-90 90q-15 15-33 22.5t-39 7.5Zm498-240q17 0 28.5-11.5T720 576q0-17-11.5-28.5T680 536q-17 0-28.5 11.5T640 576q0 17 11.5 28.5T680 616Zm-80-120q17 0 28.5-11.5T640 456q0-17-11.5-28.5T600 416q-17 0-28.5 11.5T560 456q0 17 11.5 28.5T600 496ZM310 616h60v-70h70v-60h-70v-70h-60v70h-70v60h70v70Z" />
|
||||
{!showCurrentGame && <line x1="920" y1="280" x2="40" y2="880" stroke="var(--status-danger)" stroke-width="80" />}
|
||||
</g>
|
||||
</svg>
|
||||
</button>
|
||||
)}
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
|
||||
export default definePlugin({
|
||||
name: "GameActivityToggle",
|
||||
description: "Adds a button next to the mic and deafen button to toggle game activity.",
|
||||
authors: [Devs.Nuckyz],
|
||||
dependencies: ["SettingsStoreAPI"],
|
||||
|
||||
patches: [
|
||||
{
|
||||
find: ".Messages.ACCOUNT_SPEAKING_WHILE_MUTED",
|
||||
replacement: {
|
||||
match: /this\.renderNameZone\(\).+?children:\[/,
|
||||
replace: "$&$self.GameActivityToggleButton(),"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
GameActivityToggleButton: ErrorBoundary.wrap(GameActivityToggleButton, { noop: true })
|
||||
});
|
19
src/plugins/gameActivityToggle/style.css
Normal file
19
src/plugins/gameActivityToggle/style.css
Normal file
|
@ -0,0 +1,19 @@
|
|||
[class*="withTagAsButton"] {
|
||||
min-width: 88px;
|
||||
}
|
||||
|
||||
.game-activity-toggle-btn {
|
||||
all: unset;
|
||||
color: var(--interactive-normal);
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border-radius: 4px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.game-activity-toggle-btn:hover {
|
||||
color: var(--interactive-hover);
|
||||
background-color: var(--background-modifier-selected);
|
||||
}
|
Loading…
Reference in a new issue