Skip to content

Commit

Permalink
chore: renamed snapshots to tab groups
Browse files Browse the repository at this point in the history
  • Loading branch information
Tormak9970 committed Jan 8, 2024
1 parent 957e804 commit 813bd56
Show file tree
Hide file tree
Showing 16 changed files with 180 additions and 135 deletions.
18 changes: 9 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,26 +148,26 @@ 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_snapshots(self) -> dict[str, list[str]] | None:
async def get_tab_groups(self) -> dict[str, list[str]] | None:
"""
Waits until users_dict is loaded, then returns snapshots
Waits until users_dict is loaded, then returns the tab groups
:return: Users tab visibility snapshots
:return: User's tab groups
"""
while Plugin.users_dict is None:
await asyncio.sleep(0.1)

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

# Plugin settings setters
async def set_tabs(self, tabs: dict[str, dict]):
Plugin.users_dict[Plugin.user_id]["tabs"] = tabs
await Plugin.set_setting(self, "usersDict", Plugin.users_dict)

async def set_tags(self, tags: list[dict]):
Plugin.tags= tags
Plugin.tags = tags
await Plugin.set_setting(self, "tags", Plugin.tags)

async def set_friends(self, friends: list[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_snapshots(self, snapshots: dict[str, list[str]]):
Plugin.users_dict[Plugin.user_id]["snapshots"] = snapshots
async def set_tab_groups(self, tab_groups: dict[str, list[str]]):
Plugin.users_dict[Plugin.user_id]["tabGroups"] = tab_groups
await Plugin.set_setting(self, "usersDict", Plugin.users_dict)

async def get_docs(self):
Expand Down
8 changes: 4 additions & 4 deletions src/components/QuickAccessContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import { QamStyles } from "./styles/QamStyles";
import { showModalNewTab } from "./modals/EditTabModal";
import { TabActionsButton } from "./TabActions";
import { LogController } from "../lib/controllers/LogController";
import { PresetMenu } from './menus/PresetMenu';
import { PresetMenu } from './context-menus/PresetMenu';
import { TabListLabel } from './TabListLabel';
import { MicroSDeckInstallState, MicroSDeckInterop, microSDeckLibVersion } from '../lib/controllers/MicroSDeckInterop';
import { MicroSDeckNotice } from './MicroSDeckNotice';
import { CustomTabContainer } from './CustomTabContainer';
import { SnapshotMenu } from './menus/SnapshotMenu';
import { TabGroupsMenu } from './context-menus/TabGroupMenu';


export type TabIdEntryType = {
Expand Down Expand Up @@ -103,11 +103,11 @@ export const QuickAccessContent: VFC<{}> = ({ }) => {
<Focusable
actionDescriptionMap={{
[GamepadButton.START]: 'Open Docs',
[GamepadButton.SELECT]: 'Visibility Snapshots'
[GamepadButton.SELECT]: 'Manage Tab Groups'
}}
onButtonDown={(evt: GamepadEvent) => {
if(evt.detail.button === GamepadButton.SELECT) {
showContextMenu(<SnapshotMenu tabMasterManager={tabMasterManager}/>);
showContextMenu(<TabGroupsMenu tabMasterManager={tabMasterManager}/>);
}
}}
onMenuButton={() => { Navigation.CloseSideMenus(); Navigation.Navigate("/tab-master-docs"); }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Menu, MenuItem, showModal, Focusable, MenuGroup, ReorderableEntry, ReorderableList, MenuItemProps } from 'decky-frontend-lib';
import { FC, Fragment, VFC, useState } from 'react';
import { TabMasterManager } from '../../state/TabMasterManager';
import { TabIdEntryType } from '../..';
import { TabMasterContextProvider, useTabMasterContext } from '../../state/TabMasterContext';
import { showModalEditTab, showModalNewTab } from '../modals/EditTabModal';
import { LibraryMenuStyles } from '../styles/LibraryMenuStyles';
Expand All @@ -11,7 +10,8 @@ import { PresetMenuItems } from './PresetMenu';
import { CustomTabContainer } from '../CustomTabContainer';
import { TabListLabel } from '../TabListLabel';
import { MicroSDeckInterop } from '../../lib/controllers/MicroSDeckInterop';
import { ApplySnapshotMenuGroup } from './SnapshotMenu';
import { TabGroupsSubMenu } from './TabGroupMenu';
import { TabIdEntryType } from "../QuickAccessContent";

export interface LibraryMenuProps {
closeMenu: () => void;
Expand Down Expand Up @@ -66,7 +66,7 @@ const LibraryMenuItems: VFC<LibraryMenuItemsProps> = ({ selectedTabId, closeMenu
<PresetMenuItems tabMasterManager={tabMasterManager} isMicroSDeckInstalled={isMicroSDeckInstalled} />
</MenuGroup>
<div className={gamepadContextMenuClasses.ContextMenuSeparator} />
<ApplySnapshotMenuGroup label='Apply Visibilty Snapshot' tabMasterManager={tabMasterManager}/>
<TabGroupsSubMenu 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
File renamed without changes.
78 changes: 78 additions & 0 deletions src/components/context-menus/TabGroupMenu.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 { CreateTabGroupModal, OverwriteTabGroupModal } from '../modals/TabGroupModals';

interface TabsGroupMenuProps {
tabMasterManager: TabMasterManager,
}

/**
* Context menu for managing Tab Groups.
*/
export const TabGroupsMenu: VFC<TabsGroupMenuProps> = ({ tabMasterManager }) => {
return <Menu label='Manage Tab Groups'>
<TabGroupMenuItems tabMasterManager={tabMasterManager} />
</Menu>;
};

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

/**
* Menu items for the Tab Group context menu.
*/
const TabGroupMenuItems: VFC<TabsGroupMenuProps> = ({ tabMasterManager }) => {
return (
<>
<MenuItem onClick={() => showModal(<CreateTabGroupModal tabMasterManager={tabMasterManager} />)}>
Create Group
</MenuItem>
<OverwriteTabGroupMenu tabMasterManager={tabMasterManager} />
{/* <div className={gamepadContextMenuClasses.ContextMenuSeparator} /> */}
<ApplyTabGroupMenu tabMasterManager={tabMasterManager} />
</>
);
};

/**
* The overwrite menu for Tab Groups.
*/
const OverwriteTabGroupMenu: VFC<TabsGroupMenuProps> = ({ tabMasterManager }) => {
return (
<MenuGroup label='Overwrite Tab Group' disabled={Object.keys(tabMasterManager.tabGroupManager?.snapshots ?? {}).length === 0}>
{Object.keys(tabMasterManager.tabGroupManager?.snapshots ?? {}).map(snapshotName => {
return (
<MenuItem onClick={() => showModal(<OverwriteTabGroupModal groupName={snapshotName} tabMasterManager={tabMasterManager} />)}>
{snapshotName}
</MenuItem>
);
})}
</MenuGroup>
);
};

/**
* The apply menu for Tab Groups.
*/
const ApplyTabGroupMenu: VFC<TabsGroupMenuProps> = ({ tabMasterManager }) => {
return (
<MenuGroup label='Apply Tab Group' disabled={Object.keys(tabMasterManager.tabGroupManager?.snapshots ?? {}).length === 0}>
{Object.keys(tabMasterManager.tabGroupManager?.snapshots ?? {}).map(snapshotName => {
return (
<MenuItem onClick={() => tabMasterManager.tabGroupManager?.apply(snapshotName, tabMasterManager)}>
{snapshotName}
</MenuItem>
);
})}
</MenuGroup>
);
};


3 changes: 3 additions & 0 deletions src/components/filters/FilterSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,15 @@ interface FilterSelectElement {
const FilterSelectElement: VFC<FilterSelectElement> = ({ filterType, focusable, onClick }) => {
let disabled = false;
let requiredMicroSDeckVer = '';

if (filterType === 'sd card') {
disabled = !MicroSDeckInterop.isInstallOk();
const [major, minor, patch] = microSDeckLibVersion.split(/[.+-]/, 3);

if (+major > 0) requiredMicroSDeckVer = major + '.x.x';
if (+major === 0) requiredMicroSDeckVer = `0.${minor}.${patch}`;
}

const canFocus = focusable && !disabled;

return (
Expand Down
65 changes: 0 additions & 65 deletions src/components/menus/SnapshotMenu.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,41 @@ import { ConfirmModal, TextField } from 'decky-frontend-lib';
import { VFC, useState } from 'react';
import { TabMasterManager } from '../../state/TabMasterManager';

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

export const CreateSnapshotModal: VFC<CreateSnapshotModalProps> = ({ tabMasterManager, closeModal }) => {
export const CreateTabGroupModal: VFC<CreateTabGroupModalProps> = ({ tabMasterManager, closeModal }) => {
const [name, setName] = useState<string>('');
const visibleTabs = tabMasterManager.getTabs().visibleTabsList;

return (
<ConfirmModal
onOK={() => {
tabMasterManager.snapshotManager?.write(name, visibleTabs.map(tabContainer => tabContainer.id));
tabMasterManager.tabGroupManager?.write(name, visibleTabs.map(tabContainer => tabContainer.id));
closeModal!();
}}
onCancel={() => closeModal!()}
>
<TextField value={name} placeholder="The name for this snapshot" onChange={e => setName(e?.target.value)} />
<TextField value={name} placeholder="The name for this group" onChange={e => setName(e?.target.value)} />
{visibleTabs.map(tabContainer => <div>{tabContainer.title}</div>)}
</ConfirmModal>
);
};

export interface OverwriteSnapshotModalProps extends CreateSnapshotModalProps {
snapshotName: string;
export interface OverwriteTabGroupModalProps extends CreateTabGroupModalProps {
groupName: string;
}

export const OverwriteSnapshotModal: VFC<OverwriteSnapshotModalProps> = ({ snapshotName, tabMasterManager, closeModal }) => {
export const OverwriteTabGroupModal: VFC<OverwriteTabGroupModalProps> = ({ groupName, tabMasterManager, closeModal }) => {
const { visibleTabsList, tabsMap } = tabMasterManager.getTabs();
const existingTabs = tabMasterManager.snapshotManager!.snapshots[snapshotName].map(tabId => tabsMap.get(tabId));
const existingTabs = tabMasterManager.tabGroupManager!.tabGroups[groupName].map(tabId => tabsMap.get(tabId));

return (
<ConfirmModal
onOK={() => {
tabMasterManager.snapshotManager?.write(snapshotName, visibleTabsList.map(tabContainer => tabContainer.id));
tabMasterManager.tabGroupManager?.write(groupName, visibleTabsList.map(tabContainer => tabContainer.id));
closeModal!();
}}
onCancel={() => closeModal!()}
Expand Down
3 changes: 0 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ export default definePlugin((serverAPI: ServerAPI) => {
settingsPatch = patchSettings(serverAPI, tabMasterManager);
});

const onWakeUnregister = SteamClient.System.RegisterForOnResumeFromSuspend(PluginController.onWakeFromSleep.bind(PluginController)).unregister;

PythonInterop.getDocs().then((pages: DocPages | Error) => {
if (pages instanceof Error) {
LogController.error(pages);
Expand All @@ -79,7 +77,6 @@ export default definePlugin((serverAPI: ServerAPI) => {
serverAPI.routerHook.removeRoute("/tab-master-docs");

loginUnregisterer.unregister();
onWakeUnregister();
PluginController.dismount();
},
};
Expand Down
7 changes: 7 additions & 0 deletions src/lib/controllers/PluginController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export class PluginController {

private static steamController: SteamController;

private static onWakeSub: Unregisterer;

/**
* Sets the plugin's serverAPI.
* @param server The serverAPI to use.
Expand Down Expand Up @@ -79,6 +81,8 @@ export class PluginController {
*/
static async init(): Promise<void> {
LogController.log("PluginController initialized.");

this.onWakeSub = this.steamController.registerForOnResumeFromSuspend(this.onWakeFromSleep.bind(this));

// @ts-ignore
return new Promise(async (resolve, reject) => {
Expand Down Expand Up @@ -121,7 +125,10 @@ export class PluginController {
* Function to run when the plugin dismounts.
*/
static dismount(): void {
if (this.onWakeSub) this.onWakeSub.unregister();

this.tabMasterManager.disposeReactions();

LogController.log("PluginController dismounted.");
}
}
16 changes: 8 additions & 8 deletions src/lib/controllers/PythonInterop.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ServerAPI } from "decky-frontend-lib";
import { validateTabs } from "../Utils";
import { SnapshotDictionary } from '../../state/SnapshotManager';
import { TabGroupDictionary } from '../../state/TabGroupManager';

/**
* Class for frontend -> backend communication.
Expand Down Expand Up @@ -185,8 +185,8 @@ export class PythonInterop {
* Gets the visible tab snapshots.
* @returns A promise resolving the snapshots.
*/
static async getSnapshots(): Promise<SnapshotDictionary | Error> {
let result = await PythonInterop.serverAPI.callPluginMethod<{}, SnapshotDictionary>("get_snapshots", {});
static async getSnapshots(): Promise<TabGroupDictionary | Error> {
let result = await PythonInterop.serverAPI.callPluginMethod<{}, TabGroupDictionary>("get_snapshots", {});

if (result.success) {
return result.result;
Expand Down Expand Up @@ -267,12 +267,12 @@ export class PythonInterop {
}

/**
* Sets the visible tab snapshots.
* @param snapshots The snapshots.
* @returns A promise resolving to whether or not the snapshots were successfully set.
* Sets the tab groups.
* @param tabGroups The tab groups.
* @returns A promise resolving to whether or not the tab groups were successfully set.
*/
static async setSnapshots(snapshots: SnapshotDictionary): Promise<void | Error> {
let result = await PythonInterop.serverAPI.callPluginMethod<{ snapshots: SnapshotDictionary }, void>("set_snapshots", { snapshots: snapshots });
static async setTabGroups(tabGroups: TabGroupDictionary): Promise<void | Error> {
let result = await PythonInterop.serverAPI.callPluginMethod<{ tab_groups: TabGroupDictionary }, void>("set_tab_groups", { tab_groups: tabGroups });

if (result.success) {
return result.result;
Expand Down
Loading

0 comments on commit 813bd56

Please sign in to comment.