Equicord/src/equicordplugins/statusWhilePlaying.desktop/index.ts

61 lines
1.8 KiB
TypeScript
Raw Normal View History

/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
2024-08-15 00:58:55 -04:00
import { definePluginSettings } from "@api/Settings";
import { EquicordDevs } from "@utils/constants";
2024-07-19 13:37:41 -04:00
import definePlugin, { OptionType } from "@utils/types";
import { findByCodeLazy } from "@webpack";
2024-08-15 00:58:55 -04:00
import { PresenceStore, UserStore } from "@webpack/common";
2024-08-15 00:58:55 -04:00
let savedStatus = "";
2024-07-19 13:37:41 -04:00
const updateAsync = findByCodeLazy("updateAsync", "status");
const settings = definePluginSettings({
statusToSet: {
type: OptionType.SELECT,
2024-07-19 13:51:16 -04:00
description: "Status to set while playing a game",
2024-07-19 13:37:41 -04:00
options: [
{
label: "Online",
value: "online",
},
{
label: "Idle",
value: "idle",
},
{
label: "Do Not Disturb",
value: "dnd",
2024-07-19 13:40:26 -04:00
default: true
2024-07-19 13:37:41 -04:00
},
{
label: "Invisible",
value: "invisible",
}
]
}
2024-07-19 13:37:41 -04:00
});
export default definePlugin({
2024-07-19 13:37:41 -04:00
name: "StatusWhilePlaying",
2024-08-15 00:58:55 -04:00
description: "Automatically updates your online status (online, idle, dnd) when launching games",
authors: [EquicordDevs.thororen],
2024-07-19 13:37:41 -04:00
settings,
2024-08-15 00:58:55 -04:00
flux: {
RUNNING_GAMES_CHANGE(event) {
2024-07-19 13:51:16 -04:00
const status = PresenceStore.getStatus(UserStore.getCurrentUser().id);
2024-08-15 00:58:55 -04:00
if (event.games.length > 0) {
if (savedStatus !== "" && savedStatus !== settings.store.statusToSet)
updateAsync(savedStatus);
} else {
if (status !== settings.store.statusToSet) {
savedStatus = status;
updateAsync(settings.store.statusToSet);
}
}
},
}
});