diff options
| author | AAGaming <aa@mail.catvibers.me> | 2022-10-14 23:33:16 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-14 23:33:16 -0400 |
| commit | 87a7361dc76949325421d9579e1e1813e84dcc1e (patch) | |
| tree | 463574c28429c4196b44a3ac1c58b52765744b26 /frontend/src | |
| parent | acdea6da44fc3640934b10e40f9f73ecf3bb592a (diff) | |
| download | decky-loader-87a7361dc76949325421d9579e1e1813e84dcc1e.tar.gz decky-loader-87a7361dc76949325421d9579e1e1813e84dcc1e.zip | |
Allow B button to close active plugin and return to menu. (#218)v2.2.6-pre1
Diffstat (limited to 'frontend/src')
| -rw-r--r-- | frontend/src/components/PluginView.tsx | 58 | ||||
| -rw-r--r-- | frontend/src/components/QuickAccessVisibleState.tsx | 13 | ||||
| -rw-r--r-- | frontend/src/plugin-loader.tsx | 2 | ||||
| -rw-r--r-- | frontend/src/tabs-hook.tsx (renamed from frontend/src/tabs-hook.ts) | 11 |
4 files changed, 53 insertions, 31 deletions
diff --git a/frontend/src/components/PluginView.tsx b/frontend/src/components/PluginView.tsx index 0d0a52cf..2ae0b555 100644 --- a/frontend/src/components/PluginView.tsx +++ b/frontend/src/components/PluginView.tsx @@ -1,5 +1,6 @@ import { ButtonItem, + Focusable, PanelSection, PanelSectionRow, joinClassNames, @@ -10,38 +11,47 @@ import { VFC } from 'react'; import { useDeckyState } from './DeckyState'; import NotificationBadge from './NotificationBadge'; +import { useQuickAccessVisible } from './QuickAccessVisibleState'; +import TitleView from './TitleView'; const PluginView: VFC = () => { - const { plugins, updates, activePlugin, setActivePlugin } = useDeckyState(); + const { plugins, updates, activePlugin, setActivePlugin, closeActivePlugin } = useDeckyState(); + const visible = useQuickAccessVisible(); if (activePlugin) { return ( - <div - className={joinClassNames(staticClasses.TabGroupPanel, scrollClasses.ScrollPanel, scrollClasses.ScrollY)} - style={{ height: '100%' }} - > - {activePlugin.content} - </div> + <Focusable onCancelButton={closeActivePlugin}> + <TitleView /> + <div + className={joinClassNames(staticClasses.TabGroupPanel, scrollClasses.ScrollPanel, scrollClasses.ScrollY)} + style={{ height: '100%' }} + > + {visible && activePlugin.content} + </div> + </Focusable> ); } return ( - <div className={joinClassNames(staticClasses.TabGroupPanel, scrollClasses.ScrollPanel, scrollClasses.ScrollY)}> - <PanelSection> - {plugins - .filter((p) => p.content) - .map(({ name, icon }) => ( - <PanelSectionRow key={name}> - <ButtonItem layout="below" onClick={() => setActivePlugin(name)}> - <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}> - {icon} - <div>{name}</div> - <NotificationBadge show={updates?.has(name)} style={{ top: '-5px', right: '-5px' }} /> - </div> - </ButtonItem> - </PanelSectionRow> - ))} - </PanelSection> - </div> + <> + <TitleView /> + <div className={joinClassNames(staticClasses.TabGroupPanel, scrollClasses.ScrollPanel, scrollClasses.ScrollY)}> + <PanelSection> + {plugins + .filter((p) => p.content) + .map(({ name, icon }) => ( + <PanelSectionRow key={name}> + <ButtonItem layout="below" onClick={() => setActivePlugin(name)}> + <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}> + {icon} + <div>{name}</div> + <NotificationBadge show={updates?.has(name)} style={{ top: '-5px', right: '-5px' }} /> + </div> + </ButtonItem> + </PanelSectionRow> + ))} + </PanelSection> + </div> + </> ); }; diff --git a/frontend/src/components/QuickAccessVisibleState.tsx b/frontend/src/components/QuickAccessVisibleState.tsx new file mode 100644 index 00000000..b5ee3b98 --- /dev/null +++ b/frontend/src/components/QuickAccessVisibleState.tsx @@ -0,0 +1,13 @@ +import { FC, createContext, useContext } from 'react'; + +const QuickAccessVisibleState = createContext<boolean>(true); + +export const useQuickAccessVisible = () => useContext(QuickAccessVisibleState); + +interface Props { + visible: boolean; +} + +export const QuickAccessVisibleStateProvider: FC<Props> = ({ children, visible }) => { + return <QuickAccessVisibleState.Provider value={visible}>{children}</QuickAccessVisibleState.Provider>; +}; diff --git a/frontend/src/plugin-loader.tsx b/frontend/src/plugin-loader.tsx index a1414b3a..6eee9bc0 100644 --- a/frontend/src/plugin-loader.tsx +++ b/frontend/src/plugin-loader.tsx @@ -17,7 +17,6 @@ import { deinitFilepickerPatches, initFilepickerPatches } from './components/mod import PluginInstallModal from './components/modals/PluginInstallModal'; import NotificationBadge from './components/NotificationBadge'; import PluginView from './components/PluginView'; -import TitleView from './components/TitleView'; import WithSuspense from './components/WithSuspense'; import Logger from './logger'; import { Plugin } from './plugin'; @@ -64,7 +63,6 @@ class PluginLoader extends Logger { title: null, content: ( <DeckyStateContextProvider deckyState={this.deckyState}> - <TitleView /> <PluginView /> </DeckyStateContextProvider> ), diff --git a/frontend/src/tabs-hook.ts b/frontend/src/tabs-hook.tsx index e75e043d..c5072e27 100644 --- a/frontend/src/tabs-hook.ts +++ b/frontend/src/tabs-hook.tsx @@ -1,6 +1,7 @@ import { Patch, QuickAccessTab, afterPatch, sleep } from 'decky-frontend-lib'; import { memo } from 'react'; +import { QuickAccessVisibleStateProvider } from './components/QuickAccessVisibleState'; import Logger from './logger'; declare global { @@ -83,17 +84,17 @@ class TabsHook extends Logger { if (ret) { if (!newQATabRenderer) { this.tabRenderer = ret.props.children[1].children.type; - newQATabRenderer = (...args: any) => { + newQATabRenderer = (...qamArgs: any[]) => { const oFilter = Array.prototype.filter; Array.prototype.filter = function (...args: any[]) { if (isTabsArray(this)) { - self.render(this); + self.render(this, qamArgs[0].visible); } // @ts-ignore return oFilter.call(this, ...args); }; // TODO remove array hack entirely and use this instead const tabs = ret.props.children.props.children[0].props.children[1].props.children[0].props.children[0].props.tabs - const ret = this.tabRenderer(...args); + const ret = this.tabRenderer(...qamArgs); Array.prototype.filter = oFilter; return ret; }; @@ -135,13 +136,13 @@ class TabsHook extends Logger { this.tabs = this.tabs.filter((tab) => tab.id !== id); } - render(existingTabs: any[]) { + render(existingTabs: any[], visible: boolean) { for (const { title, icon, content, id } of this.tabs) { existingTabs.push({ key: id, title, tab: icon, - panel: content, + panel: <QuickAccessVisibleStateProvider visible={visible}>{content}</QuickAccessVisibleStateProvider>, }); } } |
