2024-05-05 21:07:28 -04:00
|
|
|
/*
|
|
|
|
* Vencord, a Discord client mod
|
|
|
|
* Copyright (c) 2024 Vendicated and contributors
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*/
|
|
|
|
|
2024-07-19 13:37:41 -04:00
|
|
|
import { definePluginSettings, migratePluginSettings } from "@api/Settings";
|
2024-05-05 21:07:28 -04:00
|
|
|
import { EquicordDevs } from "@utils/constants";
|
2024-07-19 13:37:41 -04:00
|
|
|
import definePlugin, { OptionType } from "@utils/types";
|
2024-05-05 21:07:28 -04:00
|
|
|
import { findByCodeLazy } from "@webpack";
|
|
|
|
import { FluxDispatcher, PresenceStore, UserStore } from "@webpack/common";
|
|
|
|
|
2024-07-19 13:37:41 -04:00
|
|
|
const updateAsync = findByCodeLazy("updateAsync", "status");
|
2024-05-05 21:07:28 -04:00
|
|
|
|
2024-07-19 13:37:41 -04:00
|
|
|
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-05-05 21:07:28 -04:00
|
|
|
}
|
2024-07-19 13:37:41 -04:00
|
|
|
});
|
2024-05-05 21:07:28 -04:00
|
|
|
|
2024-07-19 13:37:41 -04:00
|
|
|
migratePluginSettings("StatusWhilePlaying", "DNDWhilePlaying");
|
2024-05-05 21:07:28 -04:00
|
|
|
export default definePlugin({
|
2024-07-19 13:37:41 -04:00
|
|
|
name: "StatusWhilePlaying",
|
|
|
|
description: "Automatically updates your status when playing games",
|
2024-05-05 21:07:28 -04:00
|
|
|
authors: [EquicordDevs.thororen],
|
2024-07-19 13:37:41 -04:00
|
|
|
settings,
|
|
|
|
runningGamesChange(event) {
|
|
|
|
let savedStatus = "";
|
|
|
|
if (event.games.length > 0) {
|
2024-07-19 13:51:16 -04:00
|
|
|
const status = PresenceStore.getStatus(UserStore.getCurrentUser().id);
|
2024-07-19 13:37:41 -04:00
|
|
|
savedStatus = status;
|
|
|
|
updateAsync(settings.store.statusToSet);
|
|
|
|
} else if (event.games.length === 0) {
|
|
|
|
updateAsync(savedStatus);
|
|
|
|
}
|
|
|
|
},
|
2024-05-05 21:07:28 -04:00
|
|
|
start() {
|
2024-07-19 13:37:41 -04:00
|
|
|
FluxDispatcher.subscribe("RUNNING_GAMES_CHANGE", this.runningGamesChange);
|
2024-05-05 21:07:28 -04:00
|
|
|
},
|
|
|
|
stop() {
|
2024-07-19 13:37:41 -04:00
|
|
|
FluxDispatcher.unsubscribe("RUNNING_GAMES_CHANGE", this.runningGamesChange);
|
2024-05-05 21:07:28 -04:00
|
|
|
}
|
|
|
|
});
|