Allow B button to close active plugin and return to menu. (#218)

This commit is contained in:
AAGaming
2022-10-14 23:33:16 -04:00
committed by GitHub
parent acdea6da44
commit 87a7361dc7
4 changed files with 53 additions and 31 deletions
+12 -2
View File
@@ -1,5 +1,6 @@
import { import {
ButtonItem, ButtonItem,
Focusable,
PanelSection, PanelSection,
PanelSectionRow, PanelSectionRow,
joinClassNames, joinClassNames,
@@ -10,21 +11,29 @@ import { VFC } from 'react';
import { useDeckyState } from './DeckyState'; import { useDeckyState } from './DeckyState';
import NotificationBadge from './NotificationBadge'; import NotificationBadge from './NotificationBadge';
import { useQuickAccessVisible } from './QuickAccessVisibleState';
import TitleView from './TitleView';
const PluginView: VFC = () => { const PluginView: VFC = () => {
const { plugins, updates, activePlugin, setActivePlugin } = useDeckyState(); const { plugins, updates, activePlugin, setActivePlugin, closeActivePlugin } = useDeckyState();
const visible = useQuickAccessVisible();
if (activePlugin) { if (activePlugin) {
return ( return (
<Focusable onCancelButton={closeActivePlugin}>
<TitleView />
<div <div
className={joinClassNames(staticClasses.TabGroupPanel, scrollClasses.ScrollPanel, scrollClasses.ScrollY)} className={joinClassNames(staticClasses.TabGroupPanel, scrollClasses.ScrollPanel, scrollClasses.ScrollY)}
style={{ height: '100%' }} style={{ height: '100%' }}
> >
{activePlugin.content} {visible && activePlugin.content}
</div> </div>
</Focusable>
); );
} }
return ( return (
<>
<TitleView />
<div className={joinClassNames(staticClasses.TabGroupPanel, scrollClasses.ScrollPanel, scrollClasses.ScrollY)}> <div className={joinClassNames(staticClasses.TabGroupPanel, scrollClasses.ScrollPanel, scrollClasses.ScrollY)}>
<PanelSection> <PanelSection>
{plugins {plugins
@@ -42,6 +51,7 @@ const PluginView: VFC = () => {
))} ))}
</PanelSection> </PanelSection>
</div> </div>
</>
); );
}; };
@@ -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>;
};
-2
View File
@@ -17,7 +17,6 @@ import { deinitFilepickerPatches, initFilepickerPatches } from './components/mod
import PluginInstallModal from './components/modals/PluginInstallModal'; import PluginInstallModal from './components/modals/PluginInstallModal';
import NotificationBadge from './components/NotificationBadge'; import NotificationBadge from './components/NotificationBadge';
import PluginView from './components/PluginView'; import PluginView from './components/PluginView';
import TitleView from './components/TitleView';
import WithSuspense from './components/WithSuspense'; import WithSuspense from './components/WithSuspense';
import Logger from './logger'; import Logger from './logger';
import { Plugin } from './plugin'; import { Plugin } from './plugin';
@@ -64,7 +63,6 @@ class PluginLoader extends Logger {
title: null, title: null,
content: ( content: (
<DeckyStateContextProvider deckyState={this.deckyState}> <DeckyStateContextProvider deckyState={this.deckyState}>
<TitleView />
<PluginView /> <PluginView />
</DeckyStateContextProvider> </DeckyStateContextProvider>
), ),
@@ -1,6 +1,7 @@
import { Patch, QuickAccessTab, afterPatch, sleep } from 'decky-frontend-lib'; import { Patch, QuickAccessTab, afterPatch, sleep } from 'decky-frontend-lib';
import { memo } from 'react'; import { memo } from 'react';
import { QuickAccessVisibleStateProvider } from './components/QuickAccessVisibleState';
import Logger from './logger'; import Logger from './logger';
declare global { declare global {
@@ -83,17 +84,17 @@ class TabsHook extends Logger {
if (ret) { if (ret) {
if (!newQATabRenderer) { if (!newQATabRenderer) {
this.tabRenderer = ret.props.children[1].children.type; this.tabRenderer = ret.props.children[1].children.type;
newQATabRenderer = (...args: any) => { newQATabRenderer = (...qamArgs: any[]) => {
const oFilter = Array.prototype.filter; const oFilter = Array.prototype.filter;
Array.prototype.filter = function (...args: any[]) { Array.prototype.filter = function (...args: any[]) {
if (isTabsArray(this)) { if (isTabsArray(this)) {
self.render(this); self.render(this, qamArgs[0].visible);
} }
// @ts-ignore // @ts-ignore
return oFilter.call(this, ...args); 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 // 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; Array.prototype.filter = oFilter;
return ret; return ret;
}; };
@@ -135,13 +136,13 @@ class TabsHook extends Logger {
this.tabs = this.tabs.filter((tab) => tab.id !== id); 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) { for (const { title, icon, content, id } of this.tabs) {
existingTabs.push({ existingTabs.push({
key: id, key: id,
title, title,
tab: icon, tab: icon,
panel: content, panel: <QuickAccessVisibleStateProvider visible={visible}>{content}</QuickAccessVisibleStateProvider>,
}); });
} }
} }