Skip to content

Commit

Permalink
feat: updated microsdeck and event listening
Browse files Browse the repository at this point in the history
  • Loading branch information
CEbbinghaus committed Nov 20, 2023
1 parent 4053261 commit bd89c61
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"typescript": "^4.9.5"
},
"dependencies": {
"@cebbinghaus/microsdeck": "0.9.6-3b08037",
"@cebbinghaus/microsdeck": "0.9.7-ea88921",
"mobx": "^5.15.7",
"react-icons": "^4.10.1",
"react-virtualized-auto-sizer": "^1.0.20",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ import { LogController } from "./lib/controllers/LogController";
import { DocPage } from "./components/docs/DocsPage";
import { IncludeCategories } from "./lib/Utils";
import { PresetMenu } from './components/menus/PresetMenu';
import { MicroSDeckManager } from "@cebbinghaus/microsdeck";
import { MicroSDeck } from "@cebbinghaus/microsdeck";

declare global {
var MicroSDeck: MicroSDeckManager | undefined;
var MicroSDeck: MicroSDeck | undefined;
var SteamClient: SteamClient;
let collectionStore: CollectionStore;
let appStore: AppStore;
Expand Down Expand Up @@ -235,9 +235,7 @@ export default definePlugin((serverAPI: ServerAPI) => {

PythonInterop.setServer(serverAPI);

const microSDeckManager = window.MicroSDeck = (window.MicroSDeck || new MicroSDeckManager({url: "http://localhost:12412"}));

const tabMasterManager = new TabMasterManager(microSDeckManager);
const tabMasterManager = new TabMasterManager();
PluginController.setup(serverAPI, tabMasterManager);

const loginUnregisterer = PluginController.initOnLogin(async () => {
Expand Down
27 changes: 18 additions & 9 deletions src/state/TabMasterManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { LogController } from "../lib/controllers/LogController";
import { showModal } from "decky-frontend-lib";
import { FixTabErrorsModalRoot } from "../components/modals/FixTabErrorsModal";
import { PresetName, PresetOptions, getPreset } from '../presets/presets';
import { MicroSDeckManager } from "@cebbinghaus/microsdeck";

/**
* Converts a list of filters into a 1D array.
Expand Down Expand Up @@ -51,8 +50,6 @@ export class TabMasterManager {

public eventBus = new EventTarget();

public readonly microSDeck: MicroSDeckManager;

private allGamesReaction: IReactionDisposer | undefined;
private favoriteReaction: IReactionDisposer | undefined;
private soundtrackReaction: IReactionDisposer | undefined;
Expand All @@ -70,12 +67,26 @@ export class TabMasterManager {
/**
* Creates a new TabMasterManager.
*/
constructor(microSDeck: MicroSDeckManager) {
constructor() {
this.hasLoaded = false;
this.microSDeck = microSDeck;
this.tabsMap = new Map<string, TabContainer>();
}

private initMicroSDeck(): void {
if(MicroSDeck?.Enabled) {
LogController.log(`Initializing MicroSDeck`);

// make sure we unsubscribe first
MicroSDeck.eventBus.removeEventListener("change", this.microSDeckEvent.bind(this));
MicroSDeck.eventBus.addEventListener("change", this.microSDeckEvent.bind(this));
}
}

private microSDeckEvent(e: Event) {
LogController.log("Recieved Update", e);
this.rebuildCustomTabsOnCollectionChange();
}

private initReactions(): void {
//* subscribe to changes to all games
this.allGamesReaction = reaction(() => collectionStore.GetCollection("type-games").allApps, this.rebuildCustomTabsOnCollectionChange.bind(this), { delay: 600 });
Expand Down Expand Up @@ -111,6 +122,8 @@ export class TabMasterManager {
this.tagsReaction = reaction(() => appStore.m_mapStoreTagLocalization, this.storeTagReaction.bind(this), { delay: 50 });

this.storeTagReaction(appStore.m_mapStoreTagLocalization);

this.initMicroSDeck();
}

/**
Expand Down Expand Up @@ -163,10 +176,6 @@ export class TabMasterManager {
private async rebuildCustomTabsOnCollectionChange() {
if (!this.hasLoaded) return;

if(MicroSDeck?.Enabled) {
await MicroSDeck.fetchCurrent();
}

this.visibleTabsList.forEach((tabContainer) => {
if (tabContainer.filters && tabContainer.filters.length !== 0) {
(tabContainer as CustomTabContainer).buildCollection();
Expand Down

0 comments on commit bd89c61

Please sign in to comment.