Skip to content

Commit

Permalink
chore: refactored groups to profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
Tormak9970 committed Jan 8, 2024
1 parent 4bedc05 commit 2ffe928
Show file tree
Hide file tree
Showing 12 changed files with 310 additions and 208 deletions.
16 changes: 8 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,18 @@ async def get_friends_games(self) -> dict[int, list[int]] | None:
log(f"Got {len(friends_games)} friendsGames")
return friends_games or {}

async def get_tab_groups(self) -> dict[str, list[str]] | None:
async def get_tab_profiles(self) -> dict[str, list[str]] | None:
"""
Waits until users_dict is loaded, then returns the tab groups
Waits until users_dict is loaded, then returns the tab profiles
:return: User's tab groups
:return: User's tab profiles
"""
while Plugin.users_dict is None:
await asyncio.sleep(0.1)

tab_groups = Plugin.users_dict[Plugin.user_id]["tabGroups"]
log(f"Got tab groups {tab_groups}")
return tab_groups or {}
tab_profiles = Plugin.users_dict[Plugin.user_id]["tabProfiles"]
log(f"Got tab profiles {tab_profiles}")
return tab_profiles or {}

# Plugin settings setters
async def set_tabs(self, tabs: dict[str, dict]):
Expand All @@ -178,8 +178,8 @@ async def set_friends_games(self, friends_games: dict[str, list[int]]):
Plugin.users_dict[Plugin.user_id]["friendsGames"] = friends_games
await Plugin.set_setting(self, "usersDict", Plugin.users_dict)

async def set_tab_groups(self, tab_groups: dict[str, list[str]]):
Plugin.users_dict[Plugin.user_id]["tabGroups"] = tab_groups
async def set_tab_profiles(self, tab_profiles: dict[str, list[str]]):
Plugin.users_dict[Plugin.user_id]["tabProfiles"] = tab_profiles
await Plugin.set_setting(self, "usersDict", Plugin.users_dict)

async def get_docs(self):
Expand Down
6 changes: 3 additions & 3 deletions src/components/QuickAccessContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { TabListLabel } from './TabListLabel';
import { MicroSDeckInstallState, MicroSDeckInterop, microSDeckLibVersion } from '../lib/controllers/MicroSDeckInterop';
import { MicroSDeckNotice } from './MicroSDeckNotice';
import { CustomTabContainer } from './CustomTabContainer';
import { TabGroupsMenu } from './context-menus/TabGroupMenu';
import { TabProfilesMenu } from './context-menus/TabProfileMenu';


export type TabIdEntryType = {
Expand Down Expand Up @@ -103,11 +103,11 @@ export const QuickAccessContent: VFC<{}> = ({ }) => {
<Focusable
actionDescriptionMap={{
[GamepadButton.START]: 'Open Docs',
[GamepadButton.SELECT]: 'Manage Tab Groups'
[GamepadButton.SELECT]: 'Manage Tab Profiles'
}}
onButtonDown={(evt: GamepadEvent) => {
if(evt.detail.button === GamepadButton.SELECT) {
showContextMenu(<TabGroupsMenu tabMasterManager={tabMasterManager}/>);
showContextMenu(<TabProfilesMenu tabMasterManager={tabMasterManager}/>);
}
}}
onMenuButton={() => { Navigation.CloseSideMenus(); Navigation.Navigate("/tab-master-docs"); }}
Expand Down
4 changes: 2 additions & 2 deletions src/components/context-menus/LibraryMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { PresetMenuItems } from './PresetMenu';
import { CustomTabContainer } from '../CustomTabContainer';
import { TabListLabel } from '../TabListLabel';
import { MicroSDeckInterop } from '../../lib/controllers/MicroSDeckInterop';
import { TabGroupsSubMenu } from './TabGroupMenu';
import { TabProfilesSubMenu } from './TabProfileMenu';
import { TabIdEntryType } from "../QuickAccessContent";

export interface LibraryMenuProps {
Expand Down Expand Up @@ -66,7 +66,7 @@ const LibraryMenuItems: VFC<LibraryMenuItemsProps> = ({ selectedTabId, closeMenu
<PresetMenuItems tabMasterManager={tabMasterManager} isMicroSDeckInstalled={isMicroSDeckInstalled} />
</MenuGroup>
<div className={gamepadContextMenuClasses.ContextMenuSeparator} />
<TabGroupsSubMenu tabMasterManager={tabMasterManager}/>
<TabProfilesSubMenu tabMasterManager={tabMasterManager}/>
<MenuGroup label='Reorder Tabs'>
<Focusable style={{ width: '240px', background: "#23262e", margin: '0' }} className='tab-master-library-menu-reorderable-group' onOKActionDescription=''>
<ReorderableList<TabIdEntryType>
Expand Down
78 changes: 0 additions & 78 deletions src/components/context-menus/TabGroupMenu.tsx

This file was deleted.

78 changes: 78 additions & 0 deletions src/components/context-menus/TabProfileMenu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { Menu, MenuGroup, MenuItem, showModal } from 'decky-frontend-lib';
import { VFC, Fragment } from 'react';
import { TabMasterManager } from '../../state/TabMasterManager';
import { CreateTabProfileModal, OverwriteTabProfileModal } from '../modals/TabProfileModals';

interface TabsProfilesMenuProps {
tabMasterManager: TabMasterManager,
}

/**
* Context menu for managing Tab Profiles.
*/
export const TabProfilesMenu: VFC<TabsProfilesMenuProps> = ({ tabMasterManager }) => {
return <Menu label='Manage Tab Groups'>
<TabProfileMenuItems tabMasterManager={tabMasterManager} />
</Menu>;
};

/**
* Context menu sub-menu for managing Tab Profiles.
*/
export const TabProfilesSubMenu: VFC<TabsProfilesMenuProps> = ({ tabMasterManager }) => {
return <MenuGroup label='Manage Tab Groups'>
<TabProfileMenuItems tabMasterManager={tabMasterManager} />
</MenuGroup>;
};

/**
* Menu items for the Tab Profiles context menu.
*/
const TabProfileMenuItems: VFC<TabsProfilesMenuProps> = ({ tabMasterManager }) => {
return (
<>
<MenuItem onClick={() => showModal(<CreateTabProfileModal tabMasterManager={tabMasterManager} />)}>
Create Profile
</MenuItem>
<OverwriteTabProfileMenu tabMasterManager={tabMasterManager} />
{/* <div className={gamepadContextMenuClasses.ContextMenuSeparator} /> */}
<ApplyTabProfile tabMasterManager={tabMasterManager} />
</>
);
};

/**
* The overwrite menu for Tab Profiles.
*/
const OverwriteTabProfileMenu: VFC<TabsProfilesMenuProps> = ({ tabMasterManager }) => {
return (
<MenuGroup label='Overwrite Tab Profile' disabled={Object.keys(tabMasterManager.tabProfileManager?.tabProfiles ?? {}).length === 0}>
{Object.keys(tabMasterManager.tabProfileManager?.tabProfiles ?? {}).map(snapshotName => {
return (
<MenuItem onClick={() => showModal(<OverwriteTabProfileModal profileName={snapshotName} tabMasterManager={tabMasterManager} />)}>
{snapshotName}
</MenuItem>
);
})}
</MenuGroup>
);
};

/**
* The apply menu for Tab Profiles.
*/
const ApplyTabProfile: VFC<TabsProfilesMenuProps> = ({ tabMasterManager }) => {
return (
<MenuGroup label='Apply Tab Profile' disabled={Object.keys(tabMasterManager.tabProfileManager?.tabProfiles ?? {}).length === 0}>
{Object.keys(tabMasterManager.tabProfileManager?.tabProfiles ?? {}).map(snapshotName => {
return (
<MenuItem onClick={() => tabMasterManager.tabProfileManager?.apply(snapshotName, tabMasterManager)}>
{snapshotName}
</MenuItem>
);
})}
</MenuGroup>
);
};


57 changes: 0 additions & 57 deletions src/components/modals/TabGroupModals.tsx

This file was deleted.

103 changes: 103 additions & 0 deletions src/components/modals/TabProfileModals.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { ConfirmModal, Field, TextField, afterPatch, quickAccessControlsClasses } from 'decky-frontend-lib';
import { VFC, useEffect, useState, Fragment } from 'react';
import { TabMasterManager } from '../../state/TabMasterManager';
import { TabMasterContextProvider } from "../../state/TabMasterContext";
import { TabProfileModalStyles } from "../styles/TabProfileModalStyles";

export interface CreateTabProfileModalProps {
tabMasterManager: TabMasterManager,
closeModal?: () => void,
}

export const CreateTabProfileModal: VFC<CreateTabProfileModalProps> = ({ tabMasterManager, closeModal }) => {
const [name, setName] = useState<string>('');
const visibleTabs = tabMasterManager.getTabs().visibleTabsList;
const [patchInput, setPatchInput] = useState<boolean>(true);

const nameInputElement = <TextField value={name} placeholder="The name of this tab profile" onChange={onNameChange} />;

//reference to input field class component instance, which has a focus method
let inputComponentInstance: any;

if (patchInput) {
afterPatch(nameInputElement.type.prototype, 'render', function (_: any, ret: any) {
//@ts-ignore get reference to instance
inputComponentInstance = this;
return ret;
}, { singleShot: true });
}

useEffect(() => {
inputComponentInstance.Focus();
setPatchInput(false);
}, []);

function onNameChange(e: React.ChangeEvent<HTMLInputElement>) {
setName(e?.target.value);
}

return (
<TabMasterContextProvider tabMasterManager={tabMasterManager}>
<TabProfileModalStyles />
<div className="tab-master-tab-profile-modal-scope">
<ConfirmModal
strTitle={"Create New Tab Profile"}
onOK={() => {
tabMasterManager.tabProfileManager?.write(name, visibleTabs.map(tabContainer => tabContainer.id));
closeModal!();
}}
onCancel={() => closeModal!()}
>
<div style={{ padding: "4px 16px 1px" }} className="name-field">
<Field description={
<>
<div style={{ paddingBottom: "6px" }} className={quickAccessControlsClasses.PanelSectionTitle}>
Profile Name
</div>
{nameInputElement}
</>
} />
</div>
{visibleTabs.map(tabContainer => <div>{tabContainer.title}</div>)}
</ConfirmModal>
</div>
</TabMasterContextProvider>
);
};

export interface OverwriteTabProfileModalProps extends CreateTabProfileModalProps {
profileName: string;
}

export const OverwriteTabProfileModal: VFC<OverwriteTabProfileModalProps> = ({ profileName, tabMasterManager, closeModal }) => {
const { visibleTabsList, tabsMap } = tabMasterManager.getTabs();
const existingTabs = tabMasterManager.tabProfileManager!.tabProfiles[profileName].map(tabId => tabsMap.get(tabId));

return (
<TabMasterContextProvider tabMasterManager={tabMasterManager}>
<TabProfileModalStyles />
<div className="tab-master-tab-profile-modal-scope">
<ConfirmModal
strTitle={`Overwriting Profile: ${profileName}`}
onOK={() => {
tabMasterManager.tabProfileManager?.write(profileName, visibleTabsList.map(tabContainer => tabContainer.id));
closeModal!();
}}
onCancel={() => closeModal!()}
>
<div style={{ display: 'flex', flexDirection: 'row' }}>
<div>
New Tabs:
{visibleTabsList.map(tabContainer => <div>{tabContainer.title}</div>)}
</div>
<div>
Existing Tabs:
{existingTabs.map(tabContainer => <div>{tabContainer?.title}</div>)}
</div>
</div>
</ConfirmModal>
</div>
</TabMasterContextProvider>
);
};

Loading

0 comments on commit 2ffe928

Please sign in to comment.