From 8f629c3d4fcad3fbafc428494ccf3734ef37d8cc Mon Sep 17 00:00:00 2001 From: thororen <78185467+thororen1234@users.noreply.github.com> Date: Sun, 5 May 2024 21:07:28 -0400 Subject: [PATCH] Requests + Size GlobalBadges margin properly --- src/equicordplugins/customIdle/index.ts | 84 +++++++++++++++++++ src/equicordplugins/dndWhilePlaying/index.ts | 39 +++++++++ .../globalBadges/fixBadgeOverflow.css | 3 - src/equicordplugins/globalBadges/index.tsx | 4 +- 4 files changed, 124 insertions(+), 6 deletions(-) create mode 100644 src/equicordplugins/customIdle/index.ts create mode 100644 src/equicordplugins/dndWhilePlaying/index.ts delete mode 100644 src/equicordplugins/globalBadges/fixBadgeOverflow.css diff --git a/src/equicordplugins/customIdle/index.ts b/src/equicordplugins/customIdle/index.ts new file mode 100644 index 00000000..0f746585 --- /dev/null +++ b/src/equicordplugins/customIdle/index.ts @@ -0,0 +1,84 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { Notices } from "@api/index"; +import { definePluginSettings } from "@api/Settings"; +import { makeRange } from "@components/PluginSettings/components"; +import { Devs } from "@utils/constants"; +import definePlugin, { OptionType } from "@utils/types"; +import { FluxDispatcher } from "@webpack/common"; + +const settings = definePluginSettings({ + idleTimeout: { + description: "Minutes before Discord goes idle (0 to disable auto-idle)", + type: OptionType.SLIDER, + markers: makeRange(0, 60, 5), + default: 10, + stickToMarkers: false + }, + remainInIdle: { + description: "When you come back to Discord, remain idle until you confirm you want to go online", + type: OptionType.BOOLEAN, + default: true + } +}); + +let sentNotif = false; +export default definePlugin({ + name: "CustomIdle", + description: "Allows you to set the time before Discord goes idle (or disable auto-idle)", + authors: [Devs.newwares], + settings, + patches: [ + { + find: "IDLE_DURATION:function(){return", + replacement: { + match: /(IDLE_DURATION:function\(\){return )\i/, + replace: "$1$self.getIdleTimeout()" + } + }, + { + find: "type:\"IDLE\",idle:", + replacement: [ + { + match: /Math\.min\((\i\.AfkTimeout\.getSetting\(\)\*\i\.default\.Millis\.SECOND),\i\.IDLE_DURATION\)/, + replace: "$1" // decouple idle from afk (phone notifs will remain at 10 mins) + }, + { + match: /\i\.default\.dispatch\({type:"IDLE",idle:!1}\)/, + replace: "$self.handleOnline()" + } + ] + } + ], + handleOnline() { // might be called in quick succession + if (!settings.store.remainInIdle) { + FluxDispatcher.dispatch({ + type: "IDLE", + idle: false + }); + return; + } + if (!sentNotif) { + sentNotif = true; + Notices.showNotice("Welcome back! Click the button to go online. Click the X to stay idle until reload.", "Exit idle", () => { + Notices.popNotice(); + FluxDispatcher.dispatch({ + type: "IDLE", + idle: false + }); + sentNotif = false; + }); + } + }, + getIdleTimeout() { // milliseconds, default is 6e5 + const { idleTimeout } = settings.store; + return idleTimeout === 0 ? Number.MAX_SAFE_INTEGER : idleTimeout * 60000; + }, + start() { + sentNotif = false; + } +}); diff --git a/src/equicordplugins/dndWhilePlaying/index.ts b/src/equicordplugins/dndWhilePlaying/index.ts new file mode 100644 index 00000000..f598e191 --- /dev/null +++ b/src/equicordplugins/dndWhilePlaying/index.ts @@ -0,0 +1,39 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { EquicordDevs } from "@utils/constants"; +import definePlugin from "@utils/types"; +import { findByCodeLazy } from "@webpack"; +import { FluxDispatcher, PresenceStore, UserStore } from "@webpack/common"; + +const updateAsync = findByCodeLazy("updateAsync"); + +async function runningGamesChange(event) { + const { games } = event; + let status; + let savedStatus; + if (games.length > 0) { + const currentUser = UserStore.getCurrentUser(); + status = PresenceStore.getStatus(currentUser.id); + savedStatus = status; + if (status === "invisible") return; + if (status !== "dnd") updateAsync("dnd"); + } else if (games.length === 0) { + updateAsync(savedStatus); + } +} + +export default definePlugin({ + name: "DNDWhilePlaying", + description: "Automatically updates your status to Do Not Disturb when playing games and resets it back when stopped playing", + authors: [EquicordDevs.thororen], + start() { + FluxDispatcher.subscribe("RUNNING_GAMES_CHANGE", runningGamesChange); + }, + stop() { + FluxDispatcher.unsubscribe("RUNNING_GAMES_CHANGE", runningGamesChange); + } +}); diff --git a/src/equicordplugins/globalBadges/fixBadgeOverflow.css b/src/equicordplugins/globalBadges/fixBadgeOverflow.css deleted file mode 100644 index 348d0ff3..00000000 --- a/src/equicordplugins/globalBadges/fixBadgeOverflow.css +++ /dev/null @@ -1,3 +0,0 @@ -[class*="profileBadges"] { - flex: none; -} diff --git a/src/equicordplugins/globalBadges/index.tsx b/src/equicordplugins/globalBadges/index.tsx index 00ea82c6..b08c4077 100644 --- a/src/equicordplugins/globalBadges/index.tsx +++ b/src/equicordplugins/globalBadges/index.tsx @@ -16,8 +16,6 @@ * along with this program. If not, see . */ -import "./fixBadgeOverflow.css"; - import { addBadge, BadgePosition, ProfileBadge, removeBadge } from "@api/Badges"; import { Devs, EquicordDevs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; @@ -62,7 +60,7 @@ const BadgeComponent = ({ name, img }: { name: string, img: string; }) => { )}