Update StatusWhilePlaying

This commit is contained in:
thororen1234 2024-08-15 00:58:55 -04:00
parent 88c8ae5f2b
commit 47f7411124

View file

@ -4,14 +4,14 @@
* SPDX-License-Identifier: GPL-3.0-or-later * SPDX-License-Identifier: GPL-3.0-or-later
*/ */
import { definePluginSettings, migratePluginSettings } from "@api/Settings"; import { definePluginSettings } from "@api/Settings";
import { EquicordDevs } from "@utils/constants"; import { EquicordDevs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
import { findByCodeLazy } from "@webpack"; import { findByCodeLazy } from "@webpack";
import { FluxDispatcher, PresenceStore, UserStore } from "@webpack/common"; import { PresenceStore, UserStore } from "@webpack/common";
let savedStatus = "";
const updateAsync = findByCodeLazy("updateAsync", "status"); const updateAsync = findByCodeLazy("updateAsync", "status");
const settings = definePluginSettings({ const settings = definePluginSettings({
statusToSet: { statusToSet: {
type: OptionType.SELECT, type: OptionType.SELECT,
@ -38,26 +38,23 @@ const settings = definePluginSettings({
} }
}); });
migratePluginSettings("StatusWhilePlaying", "DNDWhilePlaying");
export default definePlugin({ export default definePlugin({
name: "StatusWhilePlaying", name: "StatusWhilePlaying",
description: "Automatically updates your status when playing games", description: "Automatically updates your online status (online, idle, dnd) when launching games",
authors: [EquicordDevs.thororen], authors: [EquicordDevs.thororen],
settings, settings,
runningGamesChange(event) { flux: {
let savedStatus = ""; RUNNING_GAMES_CHANGE(event) {
if (event.games.length > 0) {
const status = PresenceStore.getStatus(UserStore.getCurrentUser().id); const status = PresenceStore.getStatus(UserStore.getCurrentUser().id);
savedStatus = status; if (event.games.length > 0) {
updateAsync(settings.store.statusToSet); if (savedStatus !== "" && savedStatus !== settings.store.statusToSet)
} else if (event.games.length === 0) { updateAsync(savedStatus);
updateAsync(savedStatus); } else {
} if (status !== settings.store.statusToSet) {
}, savedStatus = status;
start() { updateAsync(settings.store.statusToSet);
FluxDispatcher.subscribe("RUNNING_GAMES_CHANGE", this.runningGamesChange); }
}, }
stop() { },
FluxDispatcher.unsubscribe("RUNNING_GAMES_CHANGE", this.runningGamesChange);
} }
}); });