fix(Ignore Activities): Fixes games manually added not being able to be ignored (#162)
Co-authored-by: Ven <vendicated@riseup.net>
This commit is contained in:
parent
c65f757bc4
commit
bbd3633038
@ -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<string[]>("IgnoreActivities_ignoredActivities")) ?? [];
|
||||
|
||||
if (ignoredActivitiesCache.length !== 0) {
|
||||
const gamesSeen: Record<string, any>[] = 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<string, any>) {
|
||||
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<string, any>) {
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user