Skip to content

Commit 1cdb85c

Browse files
committed
fix: workaround for multiple patches being left because of plugin reload spamming
1 parent 69900eb commit 1cdb85c

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { DocsRouter } from "./components/docs/DocsRouter";
2222
import { Fragment } from 'react';
2323

2424
declare global {
25-
let DeckyPluginLoader: { pluginReloadQueue: { name: string; version?: string; }[]; };
25+
let DeckyPluginLoader: DeckyLoader;
2626
var MicroSDeck: MicroSDeck | undefined;
2727
var SteamClient: SteamClient;
2828
let collectionStore: CollectionStore;

src/patches/LibraryPatch.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ let TabAppGridComponent: TabAppGridComponent | undefined;
2424
* @returns A routepatch for the library.
2525
*/
2626
export const patchLibrary = (serverAPI: ServerAPI, tabMasterManager: TabMasterManager): RoutePatch => {
27-
//* This only runs 1 time, which is perfect
28-
return serverAPI.routerHook.addPatch("/library", (props: { path: string; children: ReactElement; }) => {
27+
28+
const patch = (props: { path: string; children: ReactElement; }) => {
2929
afterPatch(props.children, "type", (_: Record<string, unknown>[], ret1: ReactElement) => {
3030
if (!ret1?.type) {
3131
LogController.raiseError('Failed to find outer library element to patch');
@@ -136,7 +136,15 @@ export const patchLibrary = (serverAPI: ServerAPI, tabMasterManager: TabMasterMa
136136
});
137137

138138
return props;
139-
});
139+
}
140+
141+
const route = "/library";
142+
//if you're decky team seeing this, it's necessary for leftover unremoved patches caused by decky spam loading the plugin when installing from store
143+
const existingPatches = [...DeckyPluginLoader.routerHook.routerState._routePatches.get(route) ?? []].filter(existingPatch => patch.toString() === existingPatch.toString());
144+
existingPatches.forEach(patch => serverAPI.routerHook.removePatch(route, patch as RoutePatch));
145+
146+
//* This only runs 1 time, which is perfect
147+
return serverAPI.routerHook.addPatch(route, patch);
140148
};
141149

142150
/**

src/types/decky.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
interface DeckyLoader {
2+
pluginReloadQueue: { name: string; version?: string; }[];
3+
routerHook: {
4+
routerState: {
5+
_routePatches: Map<string, Set<Function>>
6+
}
7+
}
8+
};

0 commit comments

Comments
 (0)