From bbd3633038adf30c9476ef6b95152a92ebb4823b Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Wed, 26 Oct 2022 10:31:55 -0300 Subject: fix(Ignore Activities): Fixes games manually added not being able to be ignored (#162) Co-authored-by: Ven --- src/plugins/ignoreActivities.ts | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/ignoreActivities.ts b/src/plugins/ignoreActivities.ts index cc1538a..dd4650b 100644 --- a/src/plugins/ignoreActivities.ts +++ b/src/plugins/ignoreActivities.ts @@ -28,7 +28,7 @@ interface MatchAndReplace { } /** Used to re-render the Registered Games tab to update how our button looks like */ -const RunningGameStore = lazyWebpack(filters.byProps(["IgnoreActivities_reRenderGames"])); +const RunningGameStoreModule = lazyWebpack(filters.byProps(["IgnoreActivities_reRenderGames"])); let ignoredActivitiesCache: string[] = []; @@ -134,19 +134,44 @@ export default definePlugin({ async start() { ignoredActivitiesCache = (await DataStore.get("IgnoreActivities_ignoredActivities")) ?? []; + + if (ignoredActivitiesCache.length !== 0) { + const gamesSeen: Record[] = RunningGameStoreModule.Z.getGamesSeen(); + + for (const [index, ignoredActivity] of ignoredActivitiesCache.entries()) { + if (!gamesSeen.some(game => (game.id !== undefined && game.id === ignoredActivity) || game.exePath === ignoredActivity)) { + ignoredActivitiesCache.splice(index, 1); + } + } + + await DataStore.set("IgnoreActivities_ignoredActivities", ignoredActivitiesCache); + } }, - /** This method is used in different places. The Registered Games tab game props only have an id and the LocalActivityStore have the application_id */ isActivityEnabled(props: Record) { - if ("application_id" in props) return !ignoredActivitiesCache.includes(props.application_id); - else if ("id" in props) return !ignoredActivitiesCache.includes(props.id); + /** LocalActivityStore games have a "type" prop */ + if ("type" in props) { + if (props.application_id !== undefined) return !ignoredActivitiesCache.includes(props.application_id); + else { + const exePath = RunningGameStoreModule.Z.getRunningGames().find(game => game.name === props.name)?.exePath; + if (exePath) return !ignoredActivitiesCache.includes(exePath); + } + } + /** Registered Games tab games have an "id" prop */ + else if ("id" in props) { + if (props.id !== undefined) return !ignoredActivitiesCache.includes(props.id); + else return !ignoredActivitiesCache.includes(props.exePath); + } return true; }, async handleActivityToggle(props: Record) { - if (ignoredActivitiesCache.includes(props.id)) ignoredActivitiesCache.splice(ignoredActivitiesCache.indexOf(props.id, 1)); - else ignoredActivitiesCache.push(props.id); - RunningGameStore.IgnoreActivities_reRenderGames(); + const id = props.id ?? props.exePath; + if (id === undefined) return; + + if (ignoredActivitiesCache.includes(id)) ignoredActivitiesCache.splice(ignoredActivitiesCache.indexOf(id, 1)); + else ignoredActivitiesCache.push(id); + RunningGameStoreModule.IgnoreActivities_reRenderGames(); await DataStore.set("IgnoreActivities_ignoredActivities", ignoredActivitiesCache); } }); -- cgit