mirror of
https://github.com/SteamDeckHomebrew/decky-frontend-lib.git
synced 2026-05-20 18:10:08 +02:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4646f22b0c | ||
|
|
7eb484d55c | ||
|
|
5164f980b3 | ||
|
|
0457feec95 | ||
|
|
73b8d52c7f | ||
|
|
2b8d2ae4db | ||
|
|
48de8928e4 |
14
CHANGELOG.md
14
CHANGELOG.md
@@ -1,3 +1,17 @@
|
||||
# [4.7.0](https://github.com/SteamDeckHomebrew/decky-frontend-lib/compare/v4.6.0...v4.7.0) (2024-07-28)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **router:** support desktop bpm overlay ([7eb484d](https://github.com/SteamDeckHomebrew/decky-frontend-lib/commit/7eb484d55c6be6e7844878eb47eda55591a6cf51))
|
||||
|
||||
# [4.6.0](https://github.com/SteamDeckHomebrew/decky-frontend-lib/compare/v4.5.0...v4.6.0) (2024-07-26)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **classMapper:** add findClassByName back ([2b8d2ae](https://github.com/SteamDeckHomebrew/decky-frontend-lib/commit/2b8d2ae4dbd9a0c4a59a43be0101a0a8fe1c518f))
|
||||
|
||||
# [4.5.0](https://github.com/SteamDeckHomebrew/decky-frontend-lib/compare/v4.4.0...v4.5.0) (2024-07-24)
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@decky/ui",
|
||||
"version": "4.5.0",
|
||||
"version": "4.7.0",
|
||||
"description": "A library for interacting with the Steam frontend in Decky plugins and elsewhere.",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
|
||||
@@ -17,15 +17,18 @@ export const classModuleMap: Map<ModuleID, ClassModule> = createModuleMapping((m
|
||||
return false;
|
||||
});
|
||||
|
||||
export const classMap = classModuleMap.values();
|
||||
export const classMap = [...classModuleMap.values()];
|
||||
|
||||
export function findClass(id: string, name: string): string | void {
|
||||
return classModuleMap.get(id)?.[name];
|
||||
}
|
||||
|
||||
export function findClassByName(name: string): string | void {
|
||||
return classMap.find((m) => m[name])?.[name];
|
||||
}
|
||||
|
||||
export function findClassModule(filter: (module: any) => boolean): ClassModule | void {
|
||||
// TODO optimize
|
||||
return [...classModuleMap.values()].find((m) => filter(m));
|
||||
return classMap.find((m) => filter(m));
|
||||
}
|
||||
|
||||
export function unminifyClass(minifiedClass: string): string | void {
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import { FC, ReactNode, createElement, useEffect, useState } from 'react';
|
||||
|
||||
import { fakeRenderComponent, findInReactTree, sleep } from '../utils';
|
||||
import { Export, findModuleByExport } from '../webpack';
|
||||
import { FC, ReactNode } from 'react';
|
||||
import { findModuleByExport } from '../webpack';
|
||||
import { FooterLegendProps } from './FooterLegend';
|
||||
import { SteamSpinner } from './SteamSpinner';
|
||||
|
||||
/**
|
||||
* Individual tab objects for the Tabs component
|
||||
@@ -65,63 +62,9 @@ export interface TabsProps {
|
||||
autoFocusContents?: boolean;
|
||||
}
|
||||
|
||||
let tabsComponent: any;
|
||||
|
||||
const getTabs = async () => {
|
||||
if (tabsComponent) return tabsComponent;
|
||||
// @ts-ignore
|
||||
while (!window?.DeckyPluginLoader?.routerHook?.routes) {
|
||||
console.debug('[DFL:Tabs]: Waiting for Decky router...');
|
||||
await sleep(500);
|
||||
}
|
||||
return (tabsComponent = fakeRenderComponent(
|
||||
() => {
|
||||
return findInReactTree(
|
||||
findInReactTree(
|
||||
// @ts-ignore
|
||||
window.DeckyPluginLoader.routerHook.routes
|
||||
.find((x: any) => x.props.path == '/library/app/:appid/achievements')
|
||||
.props.children.type(),
|
||||
(x) => x?.props?.scrollTabsTop,
|
||||
).type({ appid: 1 }),
|
||||
(x) => x?.props?.tabs,
|
||||
).type;
|
||||
},
|
||||
{
|
||||
useRef: () => ({ current: { reaction: { track: () => {} } } }),
|
||||
useContext: () => ({ match: { params: { appid: 1 } } }),
|
||||
useMemo: () => ({ data: {} }),
|
||||
},
|
||||
));
|
||||
};
|
||||
|
||||
let oldTabs: any;
|
||||
|
||||
try {
|
||||
const oldTabsModule = findModuleByExport((e: Export) => e.Unbleed);
|
||||
if (oldTabsModule)
|
||||
oldTabs = Object.values(oldTabsModule).find((x: any) => x?.type?.toString()?.includes('((function(){'));
|
||||
} catch (e) {
|
||||
console.error('Error finding oldTabs:', e);
|
||||
}
|
||||
const tabsModule = findModuleByExport(e => e?.toString()?.includes(".TabRowTabs") && e?.toString()?.includes("activeTab:"));
|
||||
|
||||
/**
|
||||
* Tabs component as used in the library and media tabs. See {@link TabsProps}.
|
||||
* Unlike other components in `decky-frontend-lib`, this requires Decky Loader to be running.
|
||||
*/
|
||||
export const Tabs = (oldTabs ||
|
||||
((props: TabsProps) => {
|
||||
const found = tabsComponent;
|
||||
const [tc, setTC] = useState<FC<TabsProps>>(found);
|
||||
useEffect(() => {
|
||||
if (found) return;
|
||||
(async () => {
|
||||
console.debug('[DFL:Tabs]: Finding component...');
|
||||
const t = await getTabs();
|
||||
console.debug('[DFL:Tabs]: Found!');
|
||||
setTC(t);
|
||||
})();
|
||||
}, []);
|
||||
console.log('tc', tc);
|
||||
return tc ? createElement(tc, props) : <SteamSpinner />;
|
||||
})) as FC<TabsProps>;
|
||||
export const Tabs = tabsModule && Object.values(tabsModule).find((e: any) => e?.type?.toString()?.includes("((function()")) as FC<TabsProps>;
|
||||
|
||||
@@ -11,12 +11,14 @@ function getQuickAccessWindow(): Window | null {
|
||||
|
||||
/**
|
||||
* Returns state indicating the visibility of quick access menu.
|
||||
*
|
||||
* @deprecated moved to @decky/api
|
||||
*
|
||||
* @returns `true` if quick access menu is visible and `false` otherwise.
|
||||
*
|
||||
* @example
|
||||
* import { FC, useEffect } from "react";
|
||||
* import { useQuickAccessVisible } from "decky-frontend-lib";
|
||||
* import { useQuickAccessVisible } from "@decky/ui";
|
||||
*
|
||||
* export const PluginPanelView: FC<{}> = ({ }) => {
|
||||
* const isVisible = useQuickAccessVisible();
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { WindowRouter } from '../modules/Router';
|
||||
import { AppDetails, LogoPosition, SteamAppOverview } from './SteamClient';
|
||||
declare global {
|
||||
interface Window {
|
||||
@@ -46,5 +47,11 @@ declare global {
|
||||
GetCustomLogoPosition: (app: SteamAppOverview) => LogoPosition | null;
|
||||
SaveCustomLogoPosition: (app: SteamAppOverview, logoPositions: LogoPosition) => any;
|
||||
};
|
||||
SteamUIStore: {
|
||||
GetFocusedWindowInstance: () => WindowRouter;
|
||||
};
|
||||
securitystore: {
|
||||
IsLockScreenActive: () => boolean;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { sleep } from '../utils';
|
||||
import Logger from '../logger';
|
||||
import { Export, findModuleExport } from '../webpack';
|
||||
|
||||
export enum SideMenu {
|
||||
@@ -88,14 +88,23 @@ export interface WindowStore {
|
||||
|
||||
export interface Router {
|
||||
WindowStore?: WindowStore;
|
||||
/** @deprecated use {@link Navigation} instead */
|
||||
CloseSideMenus(): void;
|
||||
/** @deprecated use {@link Navigation} instead */
|
||||
Navigate(path: string): void;
|
||||
/** @deprecated use {@link Navigation} instead */
|
||||
NavigateToAppProperties(): void;
|
||||
/** @deprecated use {@link Navigation} instead */
|
||||
NavigateToExternalWeb(url: string): void;
|
||||
/** @deprecated use {@link Navigation} instead */
|
||||
NavigateToInvites(): void;
|
||||
/** @deprecated use {@link Navigation} instead */
|
||||
NavigateToChat(): void;
|
||||
/** @deprecated use {@link Navigation} instead */
|
||||
NavigateToLibraryTab(): void;
|
||||
/** @deprecated use {@link Navigation} instead */
|
||||
NavigateToLayoutPreview(e: unknown): void;
|
||||
/** @deprecated use {@link Navigation} instead */
|
||||
OpenPowerMenu(unknown?: any): void;
|
||||
get RunningApps(): AppOverview[];
|
||||
get MainRunningApp(): AppOverview | undefined;
|
||||
@@ -122,53 +131,52 @@ export interface Navigation {
|
||||
|
||||
export let Navigation = {} as Navigation;
|
||||
|
||||
const logger = new Logger("Navigation");
|
||||
|
||||
try {
|
||||
(async () => {
|
||||
let InternalNavigators: any = {};
|
||||
if (!Router.NavigateToAppProperties || (Router as unknown as any).deckyShim) {
|
||||
function initInternalNavigators() {
|
||||
try {
|
||||
InternalNavigators = findModuleExport((e: Export) => e.GetNavigator && e.SetNavigator)?.GetNavigator();
|
||||
} catch (e) {
|
||||
console.error('[DFL:Router]: Failed to init internal navigators, trying again');
|
||||
}
|
||||
function createNavigationFunction(fncName: string, handler?: (win: any) => any) {
|
||||
return (...args: any) => {
|
||||
let win: WindowRouter | undefined;
|
||||
try {
|
||||
win = window.SteamUIStore.GetFocusedWindowInstance();
|
||||
} catch (e) {
|
||||
logger.warn("Navigation interface failed to call GetFocusedWindowInstance", e);
|
||||
}
|
||||
initInternalNavigators();
|
||||
while (!InternalNavigators?.AppProperties) {
|
||||
console.log('[DFL:Router]: Trying to init internal navigators again');
|
||||
await sleep(2000);
|
||||
initInternalNavigators();
|
||||
if (!win) {
|
||||
logger.warn("Navigation interface could not find any focused window. Falling back to GamepadUIMainWindowInstance");
|
||||
win = Router.WindowStore?.GamepadUIMainWindowInstance;
|
||||
}
|
||||
|
||||
if (win) {
|
||||
try {
|
||||
const thisObj = handler && handler(win);
|
||||
(thisObj || win)[fncName](...args);
|
||||
} catch (e) {
|
||||
logger.error("Navigation handler failed", e);
|
||||
}
|
||||
} else {
|
||||
logger.error("Navigation interface could not find a window to navigate");
|
||||
}
|
||||
}
|
||||
const newNavigation = {
|
||||
Navigate: Router.Navigate?.bind(Router),
|
||||
NavigateBack: Router.WindowStore?.GamepadUIMainWindowInstance?.NavigateBack?.bind(
|
||||
Router.WindowStore.GamepadUIMainWindowInstance,
|
||||
),
|
||||
NavigateToAppProperties: InternalNavigators?.AppProperties || Router.NavigateToAppProperties?.bind(Router),
|
||||
NavigateToExternalWeb: InternalNavigators?.ExternalWeb || Router.NavigateToExternalWeb?.bind(Router),
|
||||
NavigateToInvites: InternalNavigators?.Invites || Router.NavigateToInvites?.bind(Router),
|
||||
NavigateToChat: InternalNavigators?.Chat || Router.NavigateToChat?.bind(Router),
|
||||
NavigateToLibraryTab: InternalNavigators?.LibraryTab || Router.NavigateToLibraryTab?.bind(Router),
|
||||
NavigateToLayoutPreview: Router.NavigateToLayoutPreview?.bind(Router),
|
||||
NavigateToSteamWeb: Router.WindowStore?.GamepadUIMainWindowInstance?.NavigateToSteamWeb?.bind(
|
||||
Router.WindowStore.GamepadUIMainWindowInstance,
|
||||
),
|
||||
OpenSideMenu: Router.WindowStore?.GamepadUIMainWindowInstance?.MenuStore.OpenSideMenu?.bind(
|
||||
Router.WindowStore.GamepadUIMainWindowInstance.MenuStore,
|
||||
),
|
||||
OpenQuickAccessMenu: Router.WindowStore?.GamepadUIMainWindowInstance?.MenuStore.OpenQuickAccessMenu?.bind(
|
||||
Router.WindowStore.GamepadUIMainWindowInstance.MenuStore,
|
||||
),
|
||||
OpenMainMenu: Router.WindowStore?.GamepadUIMainWindowInstance?.MenuStore.OpenMainMenu?.bind(
|
||||
Router.WindowStore.GamepadUIMainWindowInstance.MenuStore,
|
||||
),
|
||||
CloseSideMenus: Router.CloseSideMenus?.bind(Router),
|
||||
OpenPowerMenu: Router.OpenPowerMenu?.bind(Router),
|
||||
} as Navigation;
|
||||
}
|
||||
const newNavigation = {
|
||||
Navigate: createNavigationFunction("Navigate"),
|
||||
NavigateBack: createNavigationFunction("NavigateBack"),
|
||||
NavigateToAppProperties: createNavigationFunction("AppProperties", win => win.Navigator),
|
||||
NavigateToExternalWeb: createNavigationFunction("ExternalWeb", win => win.Navigator),
|
||||
NavigateToInvites: createNavigationFunction("Invites", win => win.Navigator),
|
||||
NavigateToChat: createNavigationFunction("Chat", win => win.Navigator),
|
||||
NavigateToLibraryTab: createNavigationFunction("LibraryTab", win => win.Navigator),
|
||||
NavigateToLayoutPreview: Router.NavigateToLayoutPreview?.bind(Router),
|
||||
NavigateToSteamWeb: createNavigationFunction("NavigateToSteamWeb"),
|
||||
OpenSideMenu: createNavigationFunction("OpenSideMenu", win => win.MenuStore),
|
||||
OpenQuickAccessMenu: createNavigationFunction("OpenQuickAccessMenu", win => win.MenuStore),
|
||||
OpenMainMenu: createNavigationFunction("OpenMainMenu", win => win.MenuStore),
|
||||
CloseSideMenus: createNavigationFunction("CloseSideMenus", win => win.MenuStore),
|
||||
OpenPowerMenu: Router.OpenPowerMenu?.bind(Router),
|
||||
} as Navigation;
|
||||
|
||||
Object.assign(Navigation, newNavigation);
|
||||
})();
|
||||
Object.assign(Navigation, newNavigation);
|
||||
} catch (e) {
|
||||
console.error('[DFL:Router]: Error initializing Navigation interface', e);
|
||||
logger.error('Error initializing Navigation interface', e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user