diff --git a/src/plugins/statusWhilePlaying.desktop/README.md b/src/plugins/statusWhilePlaying.desktop/README.md new file mode 100644 index 00000000..5e3abf28 --- /dev/null +++ b/src/plugins/statusWhilePlaying.desktop/README.md @@ -0,0 +1,5 @@ +# StatusWhilePlaying + +This plugin automatically updates your online status (online, idle, dnd) when launching games. + +It will change your status back to the prior status when the game is closed. diff --git a/src/plugins/statusWhilePlaying.desktop/index.ts b/src/plugins/statusWhilePlaying.desktop/index.ts new file mode 100644 index 00000000..e4a53ed4 --- /dev/null +++ b/src/plugins/statusWhilePlaying.desktop/index.ts @@ -0,0 +1,58 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { definePluginSettings } from "@api/Settings"; +import { Devs } from "@utils/constants"; +import definePlugin, { OptionType } from "@utils/types"; +import { findByCodeLazy } from "@webpack"; +import { PresenceStore, UserStore } from "@webpack/common"; + +let savedStatus = ""; +const updateAsync = findByCodeLazy("updateAsync", "status"); +const settings = definePluginSettings({ + statusToSet: { + type: OptionType.SELECT, + description: "Status to set while playing a game", + options: [ + { + label: "Online", + value: "online", + }, + { + label: "Idle", + value: "idle", + }, + { + label: "Do Not Disturb", + value: "dnd", + default: true + }, + { + label: "Invisible", + value: "invisible", + } + ] + } +}); + +export default definePlugin({ + name: "StatusWhilePlaying", + description: "Automatically updates your online status (online, idle, dnd) when launching games", + authors: [Devs.thororen], + settings, + flux: { + RUNNING_GAMES_CHANGE(event) { + const status = PresenceStore.getStatus(UserStore.getCurrentUser().id); + if (event.games.length > 0 && status !== settings.store.statusToSet) { + savedStatus = status; + updateAsync(settings.store.statusToSet); + } else { + if (savedStatus !== "" && savedStatus !== settings.store.statusToSet) + updateAsync(savedStatus); + } + }, + } +}); diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 70eca56f..a0b41bb1 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -575,10 +575,14 @@ export const Devs = /* #__PURE__*/ Object.freeze({ name: "RamziAH", id: 1279957227612147747n, }, - SomeAspy: { + SomeAspy: { name: "SomeAspy", id: 516750892372852754n, }, + thororen: { + name: "thororen", + id: 848339671629299742n, + }, } satisfies Record); // iife so #__PURE__ works correctly