Skip to content

Commit

Permalink
Merge branch 'dev-visibility-groups' of https://github.com/Tormak9970…
Browse files Browse the repository at this point in the history
…/TabMaster into dev-visibility-groups
  • Loading branch information
Tormak9970 committed Jan 8, 2024
2 parents daa6afc + 6584b03 commit 5c298c5
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 40 deletions.
5 changes: 4 additions & 1 deletion src/components/CustomTabContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ export class CustomTabContainer implements TabContainer {
this.checkMicroSDeckDependency();
}

getActualTab(TabContentComponent: TabContentComponent, sortingProps: Omit<TabContentProps, 'collection'>, footer: SteamTab['footer'], collectionAppFilter: any): SteamTab {
getActualTab(TabContentComponent: TabContentComponent, sortingProps: Omit<TabContentProps, 'collection'>, footer: SteamTab['footer'], collectionAppFilter: any, isMicroSDeckInstalled: boolean): SteamTab | null {
if (!isMicroSDeckInstalled && this.dependsOnMicroSDeck) return null;
if (this.autoHide && this.collection.visibleApps.length === 0) return null;

return {
title: this.title,
id: this.id,
Expand Down
60 changes: 45 additions & 15 deletions src/components/QuickAccessContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import {
ReorderableEntry,
ReorderableList,
showContextMenu,
GamepadEvent,
GamepadButton
quickAccessMenuClasses
} from "decky-frontend-lib";
import { VFC, useState } from "react";

Expand All @@ -28,6 +27,7 @@ import { MicroSDeckInstallState, MicroSDeckInterop, microSDeckLibVersion } from
import { MicroSDeckNotice } from './MicroSDeckNotice';
import { CustomTabContainer } from './CustomTabContainer';
import { TabProfilesMenu } from './context-menus/TabProfileMenu';
import { TabMasterManager } from '../state/TabMasterManager';


export type TabIdEntryType = {
Expand All @@ -46,7 +46,7 @@ export const QuickAccessContent: VFC<{}> = ({ }) => {
const { visibleTabsList, hiddenTabsList, tabsMap, tabMasterManager } = useTabMasterContext();

const microSDeckInstallState = MicroSDeckInterop.getInstallState();
const isMicroSDeckInstalled = microSDeckInstallState === MicroSDeckInstallState['good'];
const isMicroSDeckInstalled = microSDeckInstallState === MicroSDeckInstallState['good'];
const hasSdTabs = !!visibleTabsList.find(tabContainer => (tabContainer as CustomTabContainer).dependsOnMicroSDeck);

function TabEntryInteractables({ entry }: TabEntryInteractablesProps) {
Expand Down Expand Up @@ -100,18 +100,7 @@ export const QuickAccessContent: VFC<{}> = ({ }) => {
</div>
)}
<QamStyles />
<Focusable
actionDescriptionMap={{
[GamepadButton.START]: 'Open Docs',
[GamepadButton.SELECT]: 'Manage Tab Profiles'
}}
onButtonDown={(evt: GamepadEvent) => {
if(evt.detail.button === GamepadButton.SELECT) {
showContextMenu(<TabProfilesMenu tabMasterManager={tabMasterManager}/>);
}
}}
onMenuButton={() => { Navigation.CloseSideMenus(); Navigation.Navigate("/tab-master-docs"); }}
>
<Focusable >
<div style={{ margin: "5px", marginTop: "0px" }}>
Here you can add, re-order, or remove tabs from the library.
</div>
Expand Down Expand Up @@ -175,3 +164,44 @@ export const QuickAccessContent: VFC<{}> = ({ }) => {
</div>
);
};

export interface QuickAccessTitleViewProps {
title: string;
tabMasterManager: TabMasterManager;
}

const buttonStyle = { height: '28px', width: '40px', minWidth: 0, padding: 0, display: 'flex', justifyContent: 'center', alignItems: 'center' };

export const QuickAccessTitleView: VFC<QuickAccessTitleViewProps> = ({ title, tabMasterManager }) => {

return (
<Focusable
style={{
display: 'flex',
padding: '0',
flex: 'auto',
boxShadow: 'none',
}}
className={quickAccessMenuClasses.Title}
>
<div style={{ marginRight: "auto" }}>{title}</div>
<DialogButton
onOKActionDescription="Manage Tab Profiles"
style={buttonStyle}
onClick={() => showContextMenu(<TabProfilesMenu tabMasterManager={tabMasterManager} />)}
>
{/* {profiles icon} */}
</DialogButton>
<DialogButton
onOKActionDescription="Open Docs"
style={buttonStyle}
onClick={() => {
Navigation.CloseSideMenus();
Navigation.Navigate("/tab-master-docs");
}}
>
{/* {docs icon} */}
</DialogButton>
</Focusable>
);
};
4 changes: 2 additions & 2 deletions src/components/context-menus/TabProfileMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface TabsProfilesMenuProps {
* Context menu for managing Tab Profiles.
*/
export const TabProfilesMenu: VFC<TabsProfilesMenuProps> = ({ tabMasterManager }) => {
return <Menu label='Manage Tab Groups'>
return <Menu label='Manage Tab Profiles'>
<TabProfileMenuItems tabMasterManager={tabMasterManager} />
</Menu>;
};
Expand All @@ -20,7 +20,7 @@ export const TabProfilesMenu: VFC<TabsProfilesMenuProps> = ({ tabMasterManager }
* Context menu sub-menu for managing Tab Profiles.
*/
export const TabProfilesSubMenu: VFC<TabsProfilesMenuProps> = ({ tabMasterManager }) => {
return <MenuGroup label='Manage Tab Groups'>
return <MenuGroup label='Manage Tab Profiles'>
<TabProfileMenuItems tabMasterManager={tabMasterManager} />
</MenuGroup>;
};
Expand Down
8 changes: 4 additions & 4 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
definePlugin,
RoutePatch,
ServerAPI,
staticClasses,
} from "decky-frontend-lib";

import { TbLayoutNavbarExpand } from "react-icons/tb";
Expand All @@ -19,8 +18,9 @@ import { patchSettings } from "./patches/SettingsPatch";
import { LogController } from "./lib/controllers/LogController";
import { MicroSDeck } from "@cebbinghaus/microsdeck";
import { MicroSDeckInterop } from './lib/controllers/MicroSDeckInterop';
import { QuickAccessContent } from "./components/QuickAccessContent";
import { QuickAccessContent, QuickAccessTitleView } from "./components/QuickAccessContent";
import { DocsRouter } from "./components/docs/DocsRouter";
import { Fragment } from 'react';

declare global {
let DeckyPluginLoader: { pluginReloadQueue: { name: string; version?: string; }[]; };
Expand Down Expand Up @@ -63,9 +63,9 @@ export default definePlugin((serverAPI: ServerAPI) => {
));
}
});

return {
title: <div className={staticClasses.Title}>TabMaster</div>,
title: <></>,
titleView: <QuickAccessTitleView title="TabMaster" tabMasterManager={tabMasterManager} />,
content:
<TabMasterContextProvider tabMasterManager={tabMasterManager}>
<QuickAccessContent />
Expand Down
6 changes: 1 addition & 5 deletions src/patches/LibraryPatch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,7 @@ export const patchLibrary = (serverAPI: ServerAPI, tabMasterManager: TabMasterMa
pacthedTabs = tablist.flatMap((tabContainer) => {
if (tabContainer.filters) {
const footer = { ...(tabTemplate!.footer ?? {}), onMenuButton: getShowMenu(tabContainer.id, tabMasterManager), onMenuActionDescription: 'Tab Master' };

//if MicroSDeck isn't installed don't display any tabs that depend on it; return empty array for flat map
if (!isMicroSDeckInstalled && (tabContainer as CustomTabContainer).dependsOnMicroSDeck) return [];
if ((tabContainer as CustomTabContainer).autoHide && (tabContainer as CustomTabContainer).collection.visibleApps.length === 0) return [];
return (tabContainer as CustomTabContainer).getActualTab(tabContentComponent, sortingProps, footer, collectionsAppFilterGamepad);
return (tabContainer as CustomTabContainer).getActualTab(tabContentComponent, sortingProps, footer, collectionsAppFilterGamepad, isMicroSDeckInstalled) || [];
} else {
return tabs.find(actualTab => {
if (actualTab.id === tabContainer.id) {
Expand Down
34 changes: 21 additions & 13 deletions src/state/TabMasterManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,8 @@ export class TabMasterManager {
}
}
this.tabsMap.delete(tabId);
this.tabProfileManager?.onDeleteTab(tabId);
if (!this.tabProfileManager) LogController.error('Attempted to delete a tab before TabProfileManager has been initialized.', 'This should not be possible.');
this.updateAndSave();
}

Expand Down Expand Up @@ -487,12 +489,9 @@ export class TabMasterManager {
}

/**
* Loads the user's tabs from the backend.
* Other async load calls that don't need to be waited for when starting the plugin
*/
loadTabs = async () => {
this.initReactions();
const settings = await PythonInterop.getTabs();
//* We don't need to wait for these, since if we get the store ones, we don't care about them
asyncLoadOther() {
PythonInterop.getTags().then((res: TagResponse[] | Error) => {
if (res instanceof Error) {
LogController.log("TabMaster couldn't load tags settings");
Expand Down Expand Up @@ -523,21 +522,30 @@ export class TabMasterManager {
}
}
});
PythonInterop.getTabProfiles().then((res: TabProfileDictionary | Error) => {
if (res instanceof Error) {
LogController.log("TabMaster couldn't load tab profiles");
LogController.error(res.message);
} else {
this.tabProfileManager = new TabProfileManager(res);
}
});
}

/**
* Loads the user's tabs from the backend.
*/
loadTabs = async () => {
this.initReactions();
const settings = await PythonInterop.getTabs();
const profiles = await PythonInterop.getTabProfiles();

this.asyncLoadOther();

if (settings instanceof Error) {
LogController.log("TabMaster couldn't load tab settings");
LogController.error(settings.message);
return;
}
if (profiles instanceof Error) {
LogController.log("TabMaster couldn't load tab profiles");
LogController.error(profiles.message);
return;
}

this.tabProfileManager = new TabProfileManager(profiles);
TabErrorController.validateSettingsOnLoad((Object.keys(settings).length > 0) ? settings : defaultTabsSettings, this, this.finishLoadingTabs.bind(this));
};

Expand Down
8 changes: 8 additions & 0 deletions src/state/TabProfileManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ export class TabProfileManager {
tabMasterManager.reorderTabs(this.tabProfiles[tabProfileName]);
}

onDeleteTab(deletedId: string) {
Object.values(this.tabProfiles).forEach(tabs => {
const deletedIndex = tabs.findIndex(tabId => tabId === deletedId);
if (deletedIndex > -1) tabs.splice(deletedIndex, 1);
});
this.save();
}

/**
* Saves all changes made to the tab profiles.
*/
Expand Down

0 comments on commit 5c298c5

Please sign in to comment.