mirror of
https://github.com/SteamDeckHomebrew/decky-frontend-lib.git
synced 2026-05-21 10:29:00 +02:00
Compare commits
40 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
41401b1d01 | ||
|
|
8117693427 | ||
|
|
d6ecba605d | ||
|
|
bf58e08e4b | ||
|
|
e965816144 | ||
|
|
59ce9e450c | ||
|
|
980df687e7 | ||
|
|
bea9ac7774 | ||
|
|
063dedbbc1 | ||
|
|
723e2ff76e | ||
|
|
241b22cad7 | ||
|
|
93c59d8026 | ||
|
|
0f9fb5a3b8 | ||
|
|
8c6043b5a7 | ||
|
|
3aa07dc9ce | ||
|
|
3f335b3583 | ||
|
|
4c97097757 | ||
|
|
1ee43e86d6 | ||
|
|
db6ab9c448 | ||
|
|
4646f22b0c | ||
|
|
7eb484d55c | ||
|
|
5164f980b3 | ||
|
|
0457feec95 | ||
|
|
73b8d52c7f | ||
|
|
2b8d2ae4db | ||
|
|
48de8928e4 | ||
|
|
d60715b755 | ||
|
|
a370c1f7d3 | ||
|
|
d83bada4af | ||
|
|
1f7178f175 | ||
|
|
44fdf9ed3b | ||
|
|
1b5fd78bc2 | ||
|
|
d64c42ac31 | ||
|
|
0ec60edf4d | ||
|
|
2c3a9f81de | ||
|
|
00079a71cc | ||
|
|
c04f024b34 | ||
|
|
5dae77b003 | ||
|
|
6b8c28e69c | ||
|
|
3ef9648355 |
6
.github/workflows/docs.yaml
vendored
6
.github/workflows/docs.yaml
vendored
@@ -12,19 +12,19 @@ jobs:
|
|||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
steps:
|
steps:
|
||||||
- name: Setup | Checkout
|
- name: Setup | Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
path: lib
|
path: lib
|
||||||
- name: Setup | Checkout wiki
|
- name: Setup | Checkout wiki
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
repository: SteamDeckHomebrew/wiki
|
repository: SteamDeckHomebrew/wiki
|
||||||
path: wiki
|
path: wiki
|
||||||
ssh-key: ${{ secrets.SSH_DEPLOY_KEY }}
|
ssh-key: ${{ secrets.SSH_DEPLOY_KEY }}
|
||||||
persist-credentials: true
|
persist-credentials: true
|
||||||
- name: Setup | Node.js
|
- name: Setup | Node.js
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 18
|
node-version: 18
|
||||||
- name: Setup | Dependencies
|
- name: Setup | Dependencies
|
||||||
|
|||||||
6
.github/workflows/release.yaml
vendored
6
.github/workflows/release.yaml
vendored
@@ -4,7 +4,7 @@ on:
|
|||||||
pull_request:
|
pull_request:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- v4-dev
|
- main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release:
|
release:
|
||||||
@@ -12,11 +12,11 @@ jobs:
|
|||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
steps:
|
steps:
|
||||||
- name: Setup | Checkout
|
- name: Setup | Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- name: Setup | Node.js
|
- name: Setup | Node.js
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 20
|
node-version: 20
|
||||||
- name: Setup | Dependencies
|
- name: Setup | Dependencies
|
||||||
|
|||||||
113
CHANGELOG.md
113
CHANGELOG.md
@@ -1,3 +1,116 @@
|
|||||||
|
## [4.8.2](https://github.com/SteamDeckHomebrew/decky-frontend-lib/compare/v4.8.1...v4.8.2) (2024-11-20)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **Footer:** add missing focus/nav properties ([#113](https://github.com/SteamDeckHomebrew/decky-frontend-lib/issues/113)) ([8117693](https://github.com/SteamDeckHomebrew/decky-frontend-lib/commit/8117693427e4dba2f3b5bd24f36704d8d5e65ae2))
|
||||||
|
|
||||||
|
## [4.8.1](https://github.com/SteamDeckHomebrew/decky-frontend-lib/compare/v4.8.0...v4.8.1) (2024-10-11)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **DialogCheckbox:** prevent some potential issues in dialogcheckbox ([bf58e08](https://github.com/SteamDeckHomebrew/decky-frontend-lib/commit/bf58e08e4b5b183737c9ad43a858b642ce593f93))
|
||||||
|
* prevent issues where toString may not be a function (what) ([e965816](https://github.com/SteamDeckHomebrew/decky-frontend-lib/commit/e96581614471524cbf91bf962742df867ba3c3e9))
|
||||||
|
|
||||||
|
# [4.8.0](https://github.com/SteamDeckHomebrew/decky-frontend-lib/compare/v4.7.4...v4.8.0) (2024-10-05)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **components/Modal:** dont break in desktop ui ([bea9ac7](https://github.com/SteamDeckHomebrew/decky-frontend-lib/commit/bea9ac777452b883c2f3f3ebf8510c22c4577cd0))
|
||||||
|
* **components/Router:** dont break in desktop ui ([980df68](https://github.com/SteamDeckHomebrew/decky-frontend-lib/commit/980df687e7b7bf389f478e831f992fb9475eeb15))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* **utils/react:** add some window-related utils ([063dedb](https://github.com/SteamDeckHomebrew/decky-frontend-lib/commit/063dedbbc1573a825571c675bf6bfa8a1bc1c6cd))
|
||||||
|
|
||||||
|
## [4.7.4](https://github.com/SteamDeckHomebrew/decky-frontend-lib/compare/v4.7.3...v4.7.4) (2024-10-04)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **DialogCheckbox:** don't access getters to prevent their side effects from breaking the component ([241b22c](https://github.com/SteamDeckHomebrew/decky-frontend-lib/commit/241b22cad711621a1695dfd11da857f13c3fffdf))
|
||||||
|
|
||||||
|
## [4.7.3](https://github.com/SteamDeckHomebrew/decky-frontend-lib/compare/v4.7.2...v4.7.3) (2024-10-03)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **components:** fix missing components on oct 2 2024 beta ([0f9fb5a](https://github.com/SteamDeckHomebrew/decky-frontend-lib/commit/0f9fb5a3b8ef4f9978025a28323ab080fb0e7a4c))
|
||||||
|
|
||||||
|
## [4.7.2](https://github.com/SteamDeckHomebrew/decky-frontend-lib/compare/v4.7.1...v4.7.2) (2024-09-16)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **utils:** fix potential race condition in findSP ([3aa07dc](https://github.com/SteamDeckHomebrew/decky-frontend-lib/commit/3aa07dc9ce798ff8d1148424ee9e8a8bf2ba78c6))
|
||||||
|
|
||||||
|
## [4.7.1](https://github.com/SteamDeckHomebrew/decky-frontend-lib/compare/v4.7.0...v4.7.1) (2024-08-08)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **utils/react:** fix potential race condition in injectFCTrampoline ([4c97097](https://github.com/SteamDeckHomebrew/decky-frontend-lib/commit/4c97097757919580a380b70785e6c161de6b03cc))
|
||||||
|
|
||||||
|
# [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)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* **classMapper:** add classModuleMap, make findClass require ID ([a370c1f](https://github.com/SteamDeckHomebrew/decky-frontend-lib/commit/a370c1f7d3dca0db56a346c98c28ed9681a415e0))
|
||||||
|
* **webpack:** refactor to prepare for classMapper changes ([d83bada](https://github.com/SteamDeckHomebrew/decky-frontend-lib/commit/d83bada4af2d16c750955de9a52f94a0080a2c14))
|
||||||
|
|
||||||
|
# [4.4.0](https://github.com/SteamDeckHomebrew/decky-frontend-lib/compare/v4.3.1...v4.4.0) (2024-07-18)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* **utils/react:** add injectFCTrampoline ([44fdf9e](https://github.com/SteamDeckHomebrew/decky-frontend-lib/commit/44fdf9ed3b9a676a88b0ddc6a1c2c89d46ff7651))
|
||||||
|
|
||||||
|
## [4.3.1](https://github.com/SteamDeckHomebrew/decky-frontend-lib/compare/v4.3.0...v4.3.1) (2024-07-17)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **Menu/MenuGroup:** rewrite filter to work on beta and prevent future errors ([d64c42a](https://github.com/SteamDeckHomebrew/decky-frontend-lib/commit/d64c42ac310d3c3266c4ff610d9ec5ab6c7707b6))
|
||||||
|
|
||||||
|
# [4.3.0](https://github.com/SteamDeckHomebrew/decky-frontend-lib/compare/v4.2.2...v4.3.0) (2024-07-09)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* **utils:** react tree patching api ([2c3a9f8](https://github.com/SteamDeckHomebrew/decky-frontend-lib/commit/2c3a9f81de0b63364bb31f4a4dd8e559784ece16))
|
||||||
|
|
||||||
|
## [4.2.2](https://github.com/SteamDeckHomebrew/decky-frontend-lib/compare/v4.2.1...v4.2.2) (2024-07-04)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **SteamSpinner:** add background option ([c04f024](https://github.com/SteamDeckHomebrew/decky-frontend-lib/commit/c04f024b34b1148c965850965127f9fd44204157))
|
||||||
|
|
||||||
|
## [4.2.1](https://github.com/SteamDeckHomebrew/decky-frontend-lib/compare/v4.2.0...v4.2.1) (2024-06-27)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **errorboundary:** work around broken react types ([3ef9648](https://github.com/SteamDeckHomebrew/decky-frontend-lib/commit/3ef96483550020cecf656b94a73d2bb9313bda07))
|
||||||
|
|
||||||
# [4.2.0](https://github.com/SteamDeckHomebrew/decky-frontend-lib/compare/v4.1.1...v4.2.0) (2024-06-27)
|
# [4.2.0](https://github.com/SteamDeckHomebrew/decky-frontend-lib/compare/v4.1.1...v4.2.0) (2024-06-27)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@decky/ui",
|
"name": "@decky/ui",
|
||||||
"version": "4.2.0",
|
"version": "4.8.2",
|
||||||
"description": "A library for interacting with the Steam frontend in Decky plugins and elsewhere.",
|
"description": "A library for interacting with the Steam frontend in Decky plugins and elsewhere.",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
|||||||
7701
pnpm-lock.yaml
generated
7701
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -1,10 +1,10 @@
|
|||||||
import { Module, findAllModules } from './webpack';
|
import { Module, ModuleID, createModuleMapping } from './webpack';
|
||||||
|
|
||||||
export interface ClassModule {
|
export interface ClassModule {
|
||||||
[name: string]: string;
|
[name: string]: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const classMap: ClassModule[] = findAllModules((m: Module) => {
|
export const classModuleMap: Map<ModuleID, ClassModule> = createModuleMapping((m: Module) => {
|
||||||
if (typeof m == 'object' && !m.__esModule) {
|
if (typeof m == 'object' && !m.__esModule) {
|
||||||
const keys = Object.keys(m);
|
const keys = Object.keys(m);
|
||||||
// special case some libraries
|
// special case some libraries
|
||||||
@@ -17,8 +17,14 @@ export const classMap: ClassModule[] = findAllModules((m: Module) => {
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
export function findClass(name: string): string | void {
|
export const classMap = [...classModuleMap.values()];
|
||||||
return classMap.find((m) => m?.[name])?.[name];
|
|
||||||
|
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 {
|
export function findClassModule(filter: (module: any) => boolean): ClassModule | void {
|
||||||
@@ -26,7 +32,7 @@ export function findClassModule(filter: (module: any) => boolean): ClassModule |
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function unminifyClass(minifiedClass: string): string | void {
|
export function unminifyClass(minifiedClass: string): string | void {
|
||||||
for (let m of classMap) {
|
for (let m of classModuleMap.values()) {
|
||||||
for (let className of Object.keys(m)) {
|
for (let className of Object.keys(m)) {
|
||||||
if (m[className] == minifiedClass) return className;
|
if (m[className] == minifiedClass) return className;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,11 +78,11 @@ export const DialogControlsSection = MappedDialogDivs.get('DialogControlsSection
|
|||||||
export const DialogControlsSectionHeader = MappedDialogDivs.get('DialogControlsSectionHeader') as FC<DialogCommonProps>;
|
export const DialogControlsSectionHeader = MappedDialogDivs.get('DialogControlsSectionHeader') as FC<DialogCommonProps>;
|
||||||
|
|
||||||
export const DialogButtonPrimary = Object.values(CommonUIModule).find(
|
export const DialogButtonPrimary = Object.values(CommonUIModule).find(
|
||||||
(mod: any) => mod?.render?.toString()?.includes('"DialogButton","_DialogLayout","Primary"'),
|
(mod: any) => mod?.render?.toString?.()?.includes('"DialogButton","_DialogLayout","Primary"'),
|
||||||
) as FC<DialogButtonProps>;
|
) as FC<DialogButtonProps>;
|
||||||
|
|
||||||
export const DialogButtonSecondary = Object.values(CommonUIModule).find(
|
export const DialogButtonSecondary = Object.values(CommonUIModule).find(
|
||||||
(mod: any) => mod?.render?.toString()?.includes('"DialogButton","_DialogLayout","Secondary"')
|
(mod: any) => mod?.render?.toString?.()?.includes('"DialogButton","_DialogLayout","Secondary"')
|
||||||
) as FC<DialogButtonProps>;
|
) as FC<DialogButtonProps>;
|
||||||
|
|
||||||
// This is the "main" button. The Primary can act as a submit button,
|
// This is the "main" button. The Primary can act as a submit button,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { FC, ReactNode } from 'react';
|
import { FC, ReactNode } from 'react';
|
||||||
|
|
||||||
import { findModule } from '../webpack';
|
import { findModuleExport } from '../webpack';
|
||||||
import { DialogCommonProps } from './Dialog';
|
import { DialogCommonProps } from './Dialog';
|
||||||
import { FooterLegendProps } from './FooterLegend';
|
import { FooterLegendProps } from './FooterLegend';
|
||||||
|
|
||||||
@@ -18,19 +18,16 @@ export interface DialogCheckboxProps extends DialogCommonProps, FooterLegendProp
|
|||||||
onClick?(evt: Event): void;
|
onClick?(evt: Event): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DialogCheckbox = Object.values(
|
// Do not access KeyDown, SetChecked, Toggle here as they are getters and accessing them outside of a render breaks them globally
|
||||||
findModule((m: any) => {
|
export const DialogCheckbox = findModuleExport(e =>
|
||||||
if (typeof m !== 'object') return false;
|
e?.prototype &&
|
||||||
for (const prop in m) {
|
typeof e?.prototype == "object" &&
|
||||||
if (m[prop]?.prototype?.GetPanelElementProps) return true;
|
"GetPanelElementProps" in e?.prototype &&
|
||||||
}
|
"SetChecked" in e?.prototype &&
|
||||||
return false;
|
"Toggle" in e?.prototype &&
|
||||||
}),
|
// beta || stable as of oct 2 2024
|
||||||
).find(
|
(e?.prototype?.render?.toString?.().includes('="DialogCheckbox"') || (
|
||||||
(m: any) =>
|
e.contextType &&
|
||||||
m.contextType &&
|
e.prototype?.render?.toString?.().includes('fallback:')
|
||||||
m.prototype?.render.toString().includes('fallback:') &&
|
))
|
||||||
m?.prototype?.SetChecked &&
|
|
||||||
m?.prototype?.Toggle &&
|
|
||||||
m?.prototype?.GetPanelElementProps,
|
|
||||||
) as FC<DialogCheckboxProps>;
|
) as FC<DialogCheckboxProps>;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Component, PropsWithChildren } from "react";
|
import { FC, PropsWithChildren } from "react";
|
||||||
import { findModuleExport } from "../webpack";
|
import { findModuleExport } from "../webpack";
|
||||||
|
|
||||||
export const ErrorBoundary = findModuleExport(
|
export const ErrorBoundary = findModuleExport(
|
||||||
(e) => e.InstallErrorReportingStore && e?.prototype?.Reset && e?.prototype?.componentDidCatch,
|
(e) => e.InstallErrorReportingStore && e?.prototype?.Reset && e?.prototype?.componentDidCatch,
|
||||||
) as Component<PropsWithChildren>;
|
) as FC<PropsWithChildren>; // Actually a class but @types/react is broken lol
|
||||||
@@ -11,5 +11,5 @@ export interface FocusRingProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const FocusRing = findModuleExport((e: Export) =>
|
export const FocusRing = findModuleExport((e: Export) =>
|
||||||
e?.toString()?.includes('.GetShowDebugFocusRing())'),
|
e?.toString?.()?.includes('.GetShowDebugFocusRing())'),
|
||||||
) as FC<FocusRingProps>;
|
) as FC<FocusRingProps>;
|
||||||
|
|||||||
@@ -31,11 +31,42 @@ export enum GamepadButton {
|
|||||||
STEAM_GUIDE,
|
STEAM_GUIDE,
|
||||||
STEAM_QUICK_MENU,
|
STEAM_QUICK_MENU,
|
||||||
}
|
}
|
||||||
export declare enum NavEntryPositionPreferences {
|
export enum NavEntryPositionPreferences {
|
||||||
|
/**
|
||||||
|
* Always give focus to the first child element.
|
||||||
|
*/
|
||||||
FIRST,
|
FIRST,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Always give focus to the last child element.
|
||||||
|
*/
|
||||||
LAST,
|
LAST,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Give focus to the child element that would maintain the flow in the X axis.
|
||||||
|
*
|
||||||
|
* Imagine you have a calculator window with 9 standard buttons.
|
||||||
|
* You have 3 rows of buttons, with 3 buttons per row.
|
||||||
|
* If you select button with number 8 and navigate down, the buttons
|
||||||
|
* will be navigated in the following order 8->5->3.
|
||||||
|
* The flow is maintained for the X axis while you're navigating the Y axis.
|
||||||
|
*/
|
||||||
MAINTAIN_X,
|
MAINTAIN_X,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Give focus to the child element that would maintain the flow in the Y axis.
|
||||||
|
*
|
||||||
|
* Imagine you have a calculator window with 9 standard buttons.
|
||||||
|
* You have 3 columns of buttons, with 3 buttons per column.
|
||||||
|
* If you select button with number 4 and navigate right, the buttons
|
||||||
|
* will be navigated in the following order 4->5->6.
|
||||||
|
* The flow is maintained for the Y axis while you're navigating the X axis.
|
||||||
|
*/
|
||||||
MAINTAIN_Y,
|
MAINTAIN_Y,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Give focus to the first child element with `preferredFocus == true` prop.
|
||||||
|
*/
|
||||||
PREFERRED_CHILD,
|
PREFERRED_CHILD,
|
||||||
}
|
}
|
||||||
export interface GamepadEventDetail {
|
export interface GamepadEventDetail {
|
||||||
@@ -48,6 +79,25 @@ export declare type ActionDescriptionMap = {
|
|||||||
};
|
};
|
||||||
export declare type GamepadEvent = CustomEvent<GamepadEventDetail>;
|
export declare type GamepadEvent = CustomEvent<GamepadEventDetail>;
|
||||||
export interface FooterLegendProps {
|
export interface FooterLegendProps {
|
||||||
|
/**
|
||||||
|
* Navigation entry strategy to be used when gaining focus during navigation.
|
||||||
|
*
|
||||||
|
* This is meant to be used on a parent container that has children. Once the
|
||||||
|
* container (e.g. Focusable) is navigated to and has children in it, the children
|
||||||
|
* is then navigated to (focused) using the provided strategy.
|
||||||
|
*
|
||||||
|
* If no strategy is provided, it seems that the `NavEntryPositionPreferences.FIRST`
|
||||||
|
* is used initialy, but for the next time the parent remembers previously focused
|
||||||
|
* child and focused back on it instead.
|
||||||
|
*/
|
||||||
|
navEntryPreferPosition?: NavEntryPositionPreferences;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mark the element as the preferred child (to be focused) whenever the parent uses the
|
||||||
|
* `NavEntryPositionPreferences.PREFERRED_CHILD` navigation strategy.
|
||||||
|
*/
|
||||||
|
preferredFocus?: boolean;
|
||||||
|
|
||||||
actionDescriptionMap?: ActionDescriptionMap;
|
actionDescriptionMap?: ActionDescriptionMap;
|
||||||
onOKActionDescription?: ReactNode;
|
onOKActionDescription?: ReactNode;
|
||||||
onCancelActionDescription?: ReactNode;
|
onCancelActionDescription?: ReactNode;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { FC, ReactNode } from 'react';
|
import { FC, ReactNode } from 'react';
|
||||||
|
|
||||||
import { fakeRenderComponent } from '../utils';
|
import { Export, findModuleByExport, findModuleExport } from '../webpack';
|
||||||
import { Export, findModuleExport } from '../webpack';
|
|
||||||
import { FooterLegendProps } from './FooterLegend';
|
import { FooterLegendProps } from './FooterLegend';
|
||||||
|
|
||||||
export const showContextMenu: (children: ReactNode, parent?: EventTarget) => void = findModuleExport(
|
export const showContextMenu: (children: ReactNode, parent?: EventTarget) => void = findModuleExport(
|
||||||
@@ -26,12 +25,8 @@ export interface MenuGroupProps {
|
|||||||
children?: ReactNode;
|
children?: ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MenuGroup: FC<MenuGroupProps> = findModuleExport(
|
const MenuGoupModule = findModuleByExport(e => e?.prototype?.Focus && e?.prototype?.OnOKButton && e?.prototype?.render?.toString().includes?.(`"emphasis"==this.props.tone`));
|
||||||
(e: Export) =>
|
export const MenuGroup: FC<MenuGroupProps> = MenuGoupModule && Object.values(MenuGoupModule).find((e: Export) => typeof e == "function" && e?.toString?.()?.includes("bInGamepadUI:"));
|
||||||
(e?.toString()?.includes?.('bInGamepadUI:') &&
|
|
||||||
fakeRenderComponent(() => e({ overview: { appid: 7 } }), {useContext: () => ({IN_GAMEPADUI: true})})?.type?.prototype?.RenderSubMenu) ||
|
|
||||||
(e?.prototype?.RenderSubMenu && e?.prototype?.ShowSubMenu)
|
|
||||||
);
|
|
||||||
export interface MenuItemProps extends FooterLegendProps {
|
export interface MenuItemProps extends FooterLegendProps {
|
||||||
bInteractableItem?: boolean;
|
bInteractableItem?: boolean;
|
||||||
onClick?(evt: Event): void;
|
onClick?(evt: Event): void;
|
||||||
@@ -47,7 +42,7 @@ export interface MenuItemProps extends FooterLegendProps {
|
|||||||
|
|
||||||
export const MenuItem: FC<MenuItemProps> = findModuleExport(
|
export const MenuItem: FC<MenuItemProps> = findModuleExport(
|
||||||
(e: Export) =>
|
(e: Export) =>
|
||||||
e?.render?.toString()?.includes('bPlayAudio:') || (e?.prototype?.OnOKButton && e?.prototype?.OnMouseEnter),
|
e?.render?.toString?.()?.includes('bPlayAudio:') || (e?.prototype?.OnOKButton && e?.prototype?.OnMouseEnter),
|
||||||
);
|
);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { FC, ReactNode } from 'react';
|
import { FC, ReactNode } from 'react';
|
||||||
|
|
||||||
import { findSP } from '../utils';
|
import { findSP } from '../utils';
|
||||||
import { Export, findModule, findModuleByExport, findModuleExport } from '../webpack';
|
import { Export, findModule, findModuleDetailsByExport, findModuleExport } from '../webpack';
|
||||||
|
|
||||||
// All of the popout options + strTitle are related. Proper usage is not yet known...
|
// All of the popout options + strTitle are related. Proper usage is not yet known...
|
||||||
export interface ShowModalProps {
|
export interface ShowModalProps {
|
||||||
@@ -50,7 +50,7 @@ export const showModal = (
|
|||||||
bHideMainWindowForPopouts: false,
|
bHideMainWindowForPopouts: false,
|
||||||
},
|
},
|
||||||
): ShowModalResult => {
|
): ShowModalResult => {
|
||||||
return showModalRaw(modal, parent || findSP(), props.strTitle, props, undefined, {
|
return showModalRaw(modal, parent || findSP() || window, props.strTitle, props, undefined, {
|
||||||
bHideActions: props.bHideActionIcons,
|
bHideActions: props.bHideActionIcons,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -98,14 +98,14 @@ export const ModalRoot = Object.values(
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}) || {},
|
}) || {},
|
||||||
)?.find((x: any) => x?.type?.toString()?.includes('((function(){')) as FC<ModalRootProps>;
|
)?.find((x: any) => x?.type?.toString?.()?.includes('((function(){')) as FC<ModalRootProps>;
|
||||||
|
|
||||||
interface SimpleModalProps {
|
interface SimpleModalProps {
|
||||||
active?: boolean;
|
active?: boolean;
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ModalModule = findModuleByExport((e: Export) => e?.toString().includes('.ModalPosition,fallback:'), 5);
|
const [ModalModule, _ModalPosition] = findModuleDetailsByExport((e: Export) => e?.toString().includes('.ModalPosition'), 5)
|
||||||
|
|
||||||
const ModalModuleProps = ModalModule ? Object.values(ModalModule) : [];
|
const ModalModuleProps = ModalModule ? Object.values(ModalModule) : [];
|
||||||
|
|
||||||
@@ -114,6 +114,4 @@ export const SimpleModal = ModalModuleProps.find((prop) => {
|
|||||||
return string?.includes('.ShowPortalModal()') && string?.includes('.OnElementReadyCallbacks.Register(');
|
return string?.includes('.ShowPortalModal()') && string?.includes('.OnElementReadyCallbacks.Register(');
|
||||||
}) as FC<SimpleModalProps>;
|
}) as FC<SimpleModalProps>;
|
||||||
|
|
||||||
export const ModalPosition = ModalModuleProps.find((prop) =>
|
export const ModalPosition = _ModalPosition as FC<SimpleModalProps>;
|
||||||
prop?.toString().includes('.ModalPosition,fallback:'),
|
|
||||||
) as FC<SimpleModalProps>;
|
|
||||||
|
|||||||
@@ -22,5 +22,5 @@ export interface PanelSectionRowProps {
|
|||||||
children?: ReactNode;
|
children?: ReactNode;
|
||||||
}
|
}
|
||||||
export const PanelSectionRow = Object.values(mod).filter(
|
export const PanelSectionRow = Object.values(mod).filter(
|
||||||
(exp: any) => !exp?.toString()?.includes('.PanelSection'),
|
(exp: any) => !exp?.toString?.()?.includes('.PanelSection'),
|
||||||
)[0] as FC<PanelSectionRowProps>;
|
)[0] as FC<PanelSectionRowProps>;
|
||||||
|
|||||||
@@ -24,11 +24,11 @@ export interface ProgressBarWithInfoProps extends ProgressBarItemProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const ProgressBar = findModuleExport((e: Export) =>
|
export const ProgressBar = findModuleExport((e: Export) =>
|
||||||
e?.toString()?.includes('.ProgressBar,"standard"=='),
|
e?.toString?.()?.includes('.ProgressBar,"standard"=='),
|
||||||
) as FC<ProgressBarProps>;
|
) as FC<ProgressBarProps>;
|
||||||
|
|
||||||
export const ProgressBarWithInfo = findModuleExport((e: Export) =>
|
export const ProgressBarWithInfo = findModuleExport((e: Export) =>
|
||||||
e?.toString()?.includes('.ProgressBarFieldStatus},'),
|
e?.toString?.()?.includes('.ProgressBarFieldStatus},'),
|
||||||
) as FC<ProgressBarWithInfoProps>;
|
) as FC<ProgressBarWithInfoProps>;
|
||||||
|
|
||||||
const progressBarItemRegex = createPropListRegex(["indeterminate", "nTransitionSec", "nProgress"]);
|
const progressBarItemRegex = createPropListRegex(["indeterminate", "nTransitionSec", "nProgress"]);
|
||||||
|
|||||||
@@ -29,5 +29,6 @@ export interface SliderFieldProps extends ItemProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const SliderField = Object.values(CommonUIModule).find((mod: any) =>
|
export const SliderField = Object.values(CommonUIModule).find((mod: any) =>
|
||||||
mod?.toString()?.includes('SliderField,fallback'),
|
// stable || beta as of oct 2 2024
|
||||||
|
mod?.toString?.()?.includes('SliderField,fallback') || mod?.toString?.()?.includes("SliderField\",")
|
||||||
) as FC<SliderFieldProps>;
|
) as FC<SliderFieldProps>;
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
import { FC, SVGAttributes } from 'react';
|
import { FC, ReactNode, SVGAttributes } from 'react';
|
||||||
|
|
||||||
import { Export, findModuleExport } from '../webpack';
|
import { Export, findModuleExport } from '../webpack';
|
||||||
|
|
||||||
|
interface SteamSpinnerProps {
|
||||||
|
children?: ReactNode;
|
||||||
|
background?: "transparent"; // defaults to black seemingly, but only "transparent" is checked against
|
||||||
|
}
|
||||||
|
|
||||||
export const SteamSpinner = findModuleExport(
|
export const SteamSpinner = findModuleExport(
|
||||||
(e: Export) => e?.toString?.()?.includes('Steam Spinner') && e?.toString?.()?.includes('src'),
|
(e: Export) => e?.toString?.()?.includes('Steam Spinner') && e?.toString?.()?.includes('src'),
|
||||||
) as FC<SVGAttributes<SVGElement>>;
|
) as FC<SVGAttributes<SVGElement> & SteamSpinnerProps>;
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
import { FC, ReactNode, createElement, useEffect, useState } from 'react';
|
import { FC, ReactNode } from 'react';
|
||||||
|
import { findModuleByExport } from '../webpack';
|
||||||
import { fakeRenderComponent, findInReactTree, sleep } from '../utils';
|
|
||||||
import { Export, findModuleByExport } from '../webpack';
|
|
||||||
import { FooterLegendProps } from './FooterLegend';
|
import { FooterLegendProps } from './FooterLegend';
|
||||||
import { SteamSpinner } from './SteamSpinner';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Individual tab objects for the Tabs component
|
* Individual tab objects for the Tabs component
|
||||||
@@ -65,63 +62,9 @@ export interface TabsProps {
|
|||||||
autoFocusContents?: boolean;
|
autoFocusContents?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
let tabsComponent: any;
|
const tabsModule = findModuleByExport(e => e?.toString?.()?.includes(".TabRowTabs") && e?.toString?.()?.includes("activeTab:"));
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tabs component as used in the library and media tabs. See {@link TabsProps}.
|
* 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 ||
|
export const Tabs = tabsModule && Object.values(tabsModule).find((e: any) => e?.type?.toString?.()?.includes("((function()")) as FC<TabsProps>;
|
||||||
((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>;
|
|
||||||
|
|||||||
@@ -10,5 +10,5 @@ export interface ToggleProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const Toggle = Object.values(CommonUIModule).find((mod: any) =>
|
export const Toggle = Object.values(CommonUIModule).find((mod: any) =>
|
||||||
mod?.render?.toString()?.includes('.ToggleOff)'),
|
mod?.render?.toString?.()?.includes('.ToggleOff)'),
|
||||||
) as FC<ToggleProps>;
|
) as FC<ToggleProps>;
|
||||||
|
|||||||
@@ -11,5 +11,6 @@ export interface ToggleFieldProps extends ItemProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const ToggleField = Object.values(CommonUIModule).find((mod: any) =>
|
export const ToggleField = Object.values(CommonUIModule).find((mod: any) =>
|
||||||
mod?.render?.toString()?.includes('ToggleField,fallback'),
|
// stable || beta as of oct 2 2024
|
||||||
|
mod?.render?.toString?.()?.includes('ToggleField,fallback') || mod?.render?.toString?.()?.includes("ToggleField\",")
|
||||||
) as FC<ToggleFieldProps>;
|
) as FC<ToggleFieldProps>;
|
||||||
|
|||||||
@@ -11,12 +11,14 @@ function getQuickAccessWindow(): Window | null {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns state indicating the visibility of quick access menu.
|
* 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.
|
* @returns `true` if quick access menu is visible and `false` otherwise.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* import { FC, useEffect } from "react";
|
* import { FC, useEffect } from "react";
|
||||||
* import { useQuickAccessVisible } from "decky-frontend-lib";
|
* import { useQuickAccessVisible } from "@decky/ui";
|
||||||
*
|
*
|
||||||
* export const PluginPanelView: FC<{}> = ({ }) => {
|
* export const PluginPanelView: FC<{}> = ({ }) => {
|
||||||
* const isVisible = useQuickAccessVisible();
|
* const isVisible = useQuickAccessVisible();
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { WindowRouter } from '../modules/Router';
|
||||||
import { AppDetails, LogoPosition, SteamAppOverview } from './SteamClient';
|
import { AppDetails, LogoPosition, SteamAppOverview } from './SteamClient';
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
@@ -46,5 +47,11 @@ declare global {
|
|||||||
GetCustomLogoPosition: (app: SteamAppOverview) => LogoPosition | null;
|
GetCustomLogoPosition: (app: SteamAppOverview) => LogoPosition | null;
|
||||||
SaveCustomLogoPosition: (app: SteamAppOverview, logoPositions: LogoPosition) => any;
|
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';
|
import { Export, findModuleExport } from '../webpack';
|
||||||
|
|
||||||
export enum SideMenu {
|
export enum SideMenu {
|
||||||
@@ -88,14 +88,23 @@ export interface WindowStore {
|
|||||||
|
|
||||||
export interface Router {
|
export interface Router {
|
||||||
WindowStore?: WindowStore;
|
WindowStore?: WindowStore;
|
||||||
|
/** @deprecated use {@link Navigation} instead */
|
||||||
CloseSideMenus(): void;
|
CloseSideMenus(): void;
|
||||||
|
/** @deprecated use {@link Navigation} instead */
|
||||||
Navigate(path: string): void;
|
Navigate(path: string): void;
|
||||||
|
/** @deprecated use {@link Navigation} instead */
|
||||||
NavigateToAppProperties(): void;
|
NavigateToAppProperties(): void;
|
||||||
|
/** @deprecated use {@link Navigation} instead */
|
||||||
NavigateToExternalWeb(url: string): void;
|
NavigateToExternalWeb(url: string): void;
|
||||||
|
/** @deprecated use {@link Navigation} instead */
|
||||||
NavigateToInvites(): void;
|
NavigateToInvites(): void;
|
||||||
|
/** @deprecated use {@link Navigation} instead */
|
||||||
NavigateToChat(): void;
|
NavigateToChat(): void;
|
||||||
|
/** @deprecated use {@link Navigation} instead */
|
||||||
NavigateToLibraryTab(): void;
|
NavigateToLibraryTab(): void;
|
||||||
|
/** @deprecated use {@link Navigation} instead */
|
||||||
NavigateToLayoutPreview(e: unknown): void;
|
NavigateToLayoutPreview(e: unknown): void;
|
||||||
|
/** @deprecated use {@link Navigation} instead */
|
||||||
OpenPowerMenu(unknown?: any): void;
|
OpenPowerMenu(unknown?: any): void;
|
||||||
get RunningApps(): AppOverview[];
|
get RunningApps(): AppOverview[];
|
||||||
get MainRunningApp(): AppOverview | undefined;
|
get MainRunningApp(): AppOverview | undefined;
|
||||||
@@ -117,58 +126,58 @@ export interface Navigation {
|
|||||||
OpenQuickAccessMenu(quickAccessTab?: QuickAccessTab): void;
|
OpenQuickAccessMenu(quickAccessTab?: QuickAccessTab): void;
|
||||||
OpenMainMenu(): void;
|
OpenMainMenu(): void;
|
||||||
OpenPowerMenu(unknown?: any): void;
|
OpenPowerMenu(unknown?: any): void;
|
||||||
|
/** if calling this to perform navigation, call it after Navigate to prevent a race condition in desktop Big Picture mode that hides the overlay unintentionally */
|
||||||
CloseSideMenus(): void;
|
CloseSideMenus(): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export let Navigation = {} as Navigation;
|
export let Navigation = {} as Navigation;
|
||||||
|
|
||||||
|
const logger = new Logger("Navigation");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
(async () => {
|
function createNavigationFunction(fncName: string, handler?: (win: any) => any) {
|
||||||
let InternalNavigators: any = {};
|
return (...args: any) => {
|
||||||
if (!Router.NavigateToAppProperties || (Router as unknown as any).deckyShim) {
|
let win: WindowRouter | undefined;
|
||||||
function initInternalNavigators() {
|
try {
|
||||||
try {
|
win = window.SteamUIStore.GetFocusedWindowInstance();
|
||||||
InternalNavigators = findModuleExport((e: Export) => e.GetNavigator && e.SetNavigator)?.GetNavigator();
|
} catch (e) {
|
||||||
} catch (e) {
|
logger.warn("Navigation interface failed to call GetFocusedWindowInstance", e);
|
||||||
console.error('[DFL:Router]: Failed to init internal navigators, trying again');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
initInternalNavigators();
|
if (!win) {
|
||||||
while (!InternalNavigators?.AppProperties) {
|
logger.warn("Navigation interface could not find any focused window. Falling back to Main Window Instance");
|
||||||
console.log('[DFL:Router]: Trying to init internal navigators again');
|
win = Router.WindowStore?.GamepadUIMainWindowInstance || Router?.WindowStore?.SteamUIWindows?.[0];
|
||||||
await sleep(2000);
|
}
|
||||||
initInternalNavigators();
|
|
||||||
|
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),
|
const newNavigation = {
|
||||||
NavigateBack: Router.WindowStore?.GamepadUIMainWindowInstance?.NavigateBack?.bind(
|
Navigate: createNavigationFunction("Navigate"),
|
||||||
Router.WindowStore.GamepadUIMainWindowInstance,
|
NavigateBack: createNavigationFunction("NavigateBack"),
|
||||||
),
|
NavigateToAppProperties: createNavigationFunction("AppProperties", win => win.Navigator),
|
||||||
NavigateToAppProperties: InternalNavigators?.AppProperties || Router.NavigateToAppProperties?.bind(Router),
|
NavigateToExternalWeb: createNavigationFunction("ExternalWeb", win => win.Navigator),
|
||||||
NavigateToExternalWeb: InternalNavigators?.ExternalWeb || Router.NavigateToExternalWeb?.bind(Router),
|
NavigateToInvites: createNavigationFunction("Invites", win => win.Navigator),
|
||||||
NavigateToInvites: InternalNavigators?.Invites || Router.NavigateToInvites?.bind(Router),
|
NavigateToChat: createNavigationFunction("Chat", win => win.Navigator),
|
||||||
NavigateToChat: InternalNavigators?.Chat || Router.NavigateToChat?.bind(Router),
|
NavigateToLibraryTab: createNavigationFunction("LibraryTab", win => win.Navigator),
|
||||||
NavigateToLibraryTab: InternalNavigators?.LibraryTab || Router.NavigateToLibraryTab?.bind(Router),
|
NavigateToLayoutPreview: Router.NavigateToLayoutPreview?.bind(Router),
|
||||||
NavigateToLayoutPreview: Router.NavigateToLayoutPreview?.bind(Router),
|
NavigateToSteamWeb: createNavigationFunction("NavigateToSteamWeb"),
|
||||||
NavigateToSteamWeb: Router.WindowStore?.GamepadUIMainWindowInstance?.NavigateToSteamWeb?.bind(
|
OpenSideMenu: createNavigationFunction("OpenSideMenu", win => win.MenuStore),
|
||||||
Router.WindowStore.GamepadUIMainWindowInstance,
|
OpenQuickAccessMenu: createNavigationFunction("OpenQuickAccessMenu", win => win.MenuStore),
|
||||||
),
|
OpenMainMenu: createNavigationFunction("OpenMainMenu", win => win.MenuStore),
|
||||||
OpenSideMenu: Router.WindowStore?.GamepadUIMainWindowInstance?.MenuStore.OpenSideMenu?.bind(
|
CloseSideMenus: createNavigationFunction("CloseSideMenus", win => win.MenuStore),
|
||||||
Router.WindowStore.GamepadUIMainWindowInstance.MenuStore,
|
OpenPowerMenu: Router.OpenPowerMenu?.bind(Router),
|
||||||
),
|
} as Navigation;
|
||||||
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;
|
|
||||||
|
|
||||||
Object.assign(Navigation, newNavigation);
|
Object.assign(Navigation, newNavigation);
|
||||||
})();
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('[DFL:Router]: Error initializing Navigation interface', e);
|
logger.error('Error initializing Navigation interface', e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
export * from './patcher';
|
export * from './patcher';
|
||||||
export * from './react';
|
|
||||||
export * from './static-classes';
|
export * from './static-classes';
|
||||||
|
export * from './react/react';
|
||||||
|
export * from './react/fc';
|
||||||
|
export * from './react/treepatcher';
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
var FocusNavController: any;
|
var FocusNavController: any;
|
||||||
@@ -23,7 +25,7 @@ export function findSP(): Window {
|
|||||||
if (document.title == 'SP') return window;
|
if (document.title == 'SP') return window;
|
||||||
// new (SP as popup)
|
// new (SP as popup)
|
||||||
const navTrees = getGamepadNavigationTrees();
|
const navTrees = getGamepadNavigationTrees();
|
||||||
return navTrees?.find((x: any) => x.m_ID == 'root_1_').Root.Element.ownerDocument.defaultView;
|
return navTrees?.find((x: any) => x.m_ID == 'root_1_')?.Root?.Element?.ownerDocument?.defaultView;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -38,6 +40,6 @@ export function getFocusNavController(): any {
|
|||||||
*/
|
*/
|
||||||
export function getGamepadNavigationTrees(): any {
|
export function getGamepadNavigationTrees(): any {
|
||||||
const focusNav = getFocusNavController();
|
const focusNav = getFocusNavController();
|
||||||
const context = focusNav.m_ActiveContext || focusNav.m_LastActiveContext;
|
const context = focusNav?.m_ActiveContext || focusNav?.m_LastActiveContext;
|
||||||
return context?.m_rgGamepadNavigationTrees;
|
return context?.m_rgGamepadNavigationTrees;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ export interface PatchOptions {
|
|||||||
singleShot?: boolean;
|
singleShot?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
type GenericPatchHandler = (args: any[], ret?: any) => any;
|
export type GenericPatchHandler = (args: any[], ret?: any) => any;
|
||||||
|
|
||||||
export interface Patch {
|
export interface Patch {
|
||||||
original: Function;
|
original: Function;
|
||||||
|
|||||||
139
src/utils/react/fc.ts
Normal file
139
src/utils/react/fc.ts
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
// Utilities for patching function components
|
||||||
|
import { createElement, type FC } from 'react';
|
||||||
|
import { applyHookStubs, removeHookStubs } from './react';
|
||||||
|
import Logger from '../../logger';
|
||||||
|
|
||||||
|
export interface FCTrampoline {
|
||||||
|
component: FC
|
||||||
|
}
|
||||||
|
|
||||||
|
let loggingEnabled = false;
|
||||||
|
|
||||||
|
export function setFCTrampolineLoggingEnabled(value: boolean = true) { loggingEnabled = value };
|
||||||
|
|
||||||
|
let logger = new Logger('FCTrampoline');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Directly hooks a function component from its reference, redirecting it to a user-patchable wrapper in its returned object.
|
||||||
|
* This only works if the original component when called directly returns either nothing, null, or another child element.
|
||||||
|
*
|
||||||
|
* This works by tricking react into thinking it's a class component by cleverly working around its class component checks,
|
||||||
|
* keeping the unmodified function component intact as a mostly working constructor (as it is impossible to direcly modify a function),
|
||||||
|
* stubbing out hooks to prevent errors by detecting setter/getter triggers that occur direcly before/after the class component is instantiated by react,
|
||||||
|
* and creating a fake class component render method to trampoline out into your own handler.
|
||||||
|
*
|
||||||
|
* Due to the nature of this method of hooking a component, please only use this where it is *absolutely necessary.*
|
||||||
|
* Incorrect hook stubs can cause major instability, be careful when writing them. Refer to fakeRenderComponent for the hook stub implementation.
|
||||||
|
* Make sure your hook stubs can handle all the cases they could possibly need to within the component you are injecting into.
|
||||||
|
* You do not need to worry about its children, as they are never called due to the first instance never actually rendering.
|
||||||
|
*/
|
||||||
|
export function injectFCTrampoline(component: FC, customHooks?: any): FCTrampoline {
|
||||||
|
// It needs to be wrapped so React doesn't infinitely call the fake class render method.
|
||||||
|
const newComponent = function (this: any, ...args: any) {
|
||||||
|
loggingEnabled && logger.debug("new component rendering with props", args);
|
||||||
|
return component.apply(this, args);
|
||||||
|
}
|
||||||
|
const userComponent = { component: newComponent };
|
||||||
|
// Create a fake class component render method
|
||||||
|
component.prototype.render = function (...args: any[]) {
|
||||||
|
loggingEnabled && logger.debug("rendering trampoline", args, this);
|
||||||
|
// Pass through rendering via creating the component as a child so React can use function component logic instead of class component logic (setting up the hooks)
|
||||||
|
return createElement(userComponent.component, this.props, this.props.children);
|
||||||
|
};
|
||||||
|
component.prototype.isReactComponent = true;
|
||||||
|
let stubsApplied = false;
|
||||||
|
let oldCreateElement = window.SP_REACT.createElement;
|
||||||
|
|
||||||
|
const applyStubsIfNeeded = () => {
|
||||||
|
if (!stubsApplied) {
|
||||||
|
loggingEnabled && logger.debug("applied stubs");
|
||||||
|
stubsApplied = true;
|
||||||
|
applyHookStubs(customHooks)
|
||||||
|
// we have to redirect this to return an object with component's prototype as a constructor returning a value overrides its prototype
|
||||||
|
window.SP_REACT.createElement = () => {
|
||||||
|
loggingEnabled && logger.debug("createElement hook called");
|
||||||
|
loggingEnabled && console.trace("createElement trace");
|
||||||
|
return Object.create(component.prototype);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const removeStubsIfNeeded = () => {
|
||||||
|
if (stubsApplied) {
|
||||||
|
loggingEnabled && logger.debug("removed stubs");
|
||||||
|
stubsApplied = false;
|
||||||
|
removeHookStubs();
|
||||||
|
window.SP_REACT.createElement = oldCreateElement;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let renderHookStep = 0;
|
||||||
|
|
||||||
|
// Accessed two times, once directly before class instantiation, and again in some extra logic we don't need to worry about that we hanlde below just in case.
|
||||||
|
Object.defineProperty(component, "contextType", {
|
||||||
|
configurable: true,
|
||||||
|
get: function () {
|
||||||
|
loggingEnabled && logger.debug("get contexttype", this, stubsApplied, renderHookStep);
|
||||||
|
loggingEnabled && console.trace("contextType trace");
|
||||||
|
if (renderHookStep == 0) renderHookStep = 1;
|
||||||
|
else if (renderHookStep == 3) renderHookStep = 4;
|
||||||
|
return this._contextType;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this._contextType = value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Always accessed directly after contextType for the path we want to catch.
|
||||||
|
Object.defineProperty(component, "contextTypes", {
|
||||||
|
configurable: true,
|
||||||
|
get: function () {
|
||||||
|
loggingEnabled && logger.debug("get contexttypes", this, stubsApplied, renderHookStep);
|
||||||
|
loggingEnabled && console.trace("contextTypes trace");
|
||||||
|
if (renderHookStep == 1) {
|
||||||
|
renderHookStep = 2;
|
||||||
|
applyStubsIfNeeded();
|
||||||
|
};
|
||||||
|
return this._contextTypes;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this._contextTypes = value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Set directly after class is instantiated
|
||||||
|
Object.defineProperty(component.prototype, "updater", {
|
||||||
|
configurable: true,
|
||||||
|
get: function () {
|
||||||
|
return this._updater;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
loggingEnabled && logger.debug("set updater", this, value, stubsApplied, renderHookStep);
|
||||||
|
loggingEnabled && console.trace("updater trace");
|
||||||
|
if (renderHookStep == 2) {
|
||||||
|
renderHookStep = 0;
|
||||||
|
removeStubsIfNeeded();
|
||||||
|
}
|
||||||
|
return this._updater = value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Prevents the second contextType+contextTypes access from leaving its hooks around
|
||||||
|
Object.defineProperty(component, "getDerivedStateFromProps", {
|
||||||
|
configurable: true,
|
||||||
|
get: function () {
|
||||||
|
loggingEnabled && logger.debug("get getDerivedStateFromProps", this, stubsApplied, renderHookStep);
|
||||||
|
loggingEnabled && console.trace("getDerivedStateFromProps trace");
|
||||||
|
if (renderHookStep == 2) {
|
||||||
|
renderHookStep = 0;
|
||||||
|
removeStubsIfNeeded();
|
||||||
|
}
|
||||||
|
return this._getDerivedStateFromProps;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this._getDerivedStateFromProps = value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return userComponent;
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
import { Ref, useState } from 'react';
|
||||||
|
|
||||||
// this shouldn't need to be redeclared but it does for some reason
|
// this shouldn't need to be redeclared but it does for some reason
|
||||||
|
|
||||||
@@ -30,13 +31,15 @@ export function createPropListRegex(propList: string[], fromStart: boolean = tru
|
|||||||
return new RegExp(regexString);
|
return new RegExp(regexString);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fakeRenderComponent(fun: Function, customHooks: any = {}): any {
|
let oldHooks = {};
|
||||||
|
|
||||||
|
export function applyHookStubs(customHooks: any = {}): any {
|
||||||
const hooks = (window.SP_REACT as any).__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher
|
const hooks = (window.SP_REACT as any).__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher
|
||||||
.current;
|
.current;
|
||||||
|
|
||||||
// TODO: add more hooks
|
// TODO: add more hooks
|
||||||
|
|
||||||
let oldHooks = {
|
oldHooks = {
|
||||||
useContext: hooks.useContext,
|
useContext: hooks.useContext,
|
||||||
useCallback: hooks.useCallback,
|
useCallback: hooks.useCallback,
|
||||||
useLayoutEffect: hooks.useLayoutEffect,
|
useLayoutEffect: hooks.useLayoutEffect,
|
||||||
@@ -60,9 +63,22 @@ export function fakeRenderComponent(fun: Function, customHooks: any = {}): any {
|
|||||||
|
|
||||||
Object.assign(hooks, customHooks);
|
Object.assign(hooks, customHooks);
|
||||||
|
|
||||||
const res = fun(hooks);
|
return hooks;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function removeHookStubs() {
|
||||||
|
const hooks = (window.SP_REACT as any).__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher
|
||||||
|
.current;
|
||||||
Object.assign(hooks, oldHooks);
|
Object.assign(hooks, oldHooks);
|
||||||
|
oldHooks = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function fakeRenderComponent(fun: Function, customHooks?: any): any {
|
||||||
|
const hooks = applyHookStubs(customHooks);
|
||||||
|
|
||||||
|
const res = fun(hooks); // TODO why'd we do this?
|
||||||
|
|
||||||
|
removeHookStubs();
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -89,19 +105,15 @@ export function wrapReactClass(node: any, prop: any = 'type') {
|
|||||||
|
|
||||||
export function getReactRoot(o: HTMLElement | Element | Node) {
|
export function getReactRoot(o: HTMLElement | Element | Node) {
|
||||||
return (
|
return (
|
||||||
// @ts-expect-error 7053
|
(o as any)[Object.keys(o).find((k) => k.startsWith('__reactContainer$')) as string] ||
|
||||||
o[Object.keys(o).find((k) => k.startsWith('__reactContainer$')) as string] ||
|
(o as any)['_reactRootContainer']?._internalRoot?.current
|
||||||
// @ts-expect-error 7053
|
|
||||||
o['_reactRootContainer']?._internalRoot?.current
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getReactInstance(o: HTMLElement | Element | Node) {
|
export function getReactInstance(o: HTMLElement | Element | Node) {
|
||||||
return (
|
return (
|
||||||
// @ts-expect-error 7053
|
(o as any)[Object.keys(o).find((k) => k.startsWith('__reactFiber')) as string] ||
|
||||||
o[Object.keys(o).find((k) => k.startsWith('__reactFiber')) as string] ||
|
(o as any)[Object.keys(o).find((k) => k.startsWith('__reactInternalInstance')) as string]
|
||||||
// @ts-expect-error 7053
|
|
||||||
o[Object.keys(o).find((k) => k.startsWith('__reactInternalInstance')) as string]
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,3 +151,21 @@ export const findInReactTree = (node: any, filter: findInTreeFilter) =>
|
|||||||
// Specialised findInTree for React nodes
|
// Specialised findInTree for React nodes
|
||||||
walkable: ['props', 'children', 'child', 'sibling'],
|
walkable: ['props', 'children', 'child', 'sibling'],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the parent window of a DOM element
|
||||||
|
*/
|
||||||
|
export function getParentWindow<WindowType = Window>(elem: HTMLElement | null): WindowType | null | undefined {
|
||||||
|
return elem?.ownerDocument?.defaultView as any;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* React hook to find the host window of a component
|
||||||
|
* Pass the returned ref into a React element and window will be its host window.
|
||||||
|
* @returns [ref, window]
|
||||||
|
*/
|
||||||
|
export function useWindowRef<RefElementType extends HTMLElement, WindowType = Window>(): [Ref<RefElementType>, WindowType | null | undefined] {
|
||||||
|
const [win, setWin] = useState<WindowType | null | undefined>(null);
|
||||||
|
|
||||||
|
return [(elem) => setWin(getParentWindow<WindowType>(elem)), win];
|
||||||
|
}
|
||||||
100
src/utils/react/treepatcher.ts
Normal file
100
src/utils/react/treepatcher.ts
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
import Logger from '../../logger';
|
||||||
|
import { GenericPatchHandler, afterPatch } from '../patcher';
|
||||||
|
import { wrapReactClass, wrapReactType } from './react';
|
||||||
|
|
||||||
|
// TODO max size limit? could implement as a class extending map perhaps
|
||||||
|
type PatchedComponentCache = Map<any, any>;
|
||||||
|
export type GenericNodeStep = (node: any) => any;
|
||||||
|
// to patch a specific method of a class component other than render. TODO implement
|
||||||
|
// export type ClassNodeStep = [finder: GenericNodeStep, method: string];
|
||||||
|
// export type NodeStep = GenericNodeStep | ClassNodeStep;
|
||||||
|
export type NodeStep = GenericNodeStep;
|
||||||
|
export type ReactPatchHandler = GenericPatchHandler;
|
||||||
|
|
||||||
|
// These will get *very* spammy.
|
||||||
|
let loggingEnabled = false;
|
||||||
|
let perfLoggingEnabled = false;
|
||||||
|
|
||||||
|
export function setReactPatcherLoggingEnabled(value: boolean = true) { loggingEnabled = value };
|
||||||
|
export function setReactPatcherPerformanceLoggingEnabled(value: boolean = true) { perfLoggingEnabled = value };
|
||||||
|
|
||||||
|
function patchComponent(node: any, handler: GenericPatchHandler, steps: NodeStep[], step: number, caches: PatchedComponentCache[], logger: Logger, prop: string = 'type') {
|
||||||
|
loggingEnabled && logger.group('Patching node:', node);
|
||||||
|
// We need to take extra care to not mutate the original node.type
|
||||||
|
switch (typeof node?.[prop]) {
|
||||||
|
case 'function':
|
||||||
|
// Function component
|
||||||
|
const patch = afterPatch(node, prop, steps[step + 1] ? createStepHandler(handler, steps, step + 1, caches, logger) : handler);
|
||||||
|
loggingEnabled && logger.debug('Patched a function component', patch);
|
||||||
|
break;
|
||||||
|
case 'object':
|
||||||
|
if (node[prop]?.prototype?.render) {
|
||||||
|
// Class component
|
||||||
|
// TODO handle patching custom methods
|
||||||
|
wrapReactClass(node);
|
||||||
|
const patch = afterPatch(node[prop].prototype, 'render', steps[step + 1] ? createStepHandler(handler, steps, step + 1, caches, logger) : handler);
|
||||||
|
loggingEnabled && logger.debug('Patched class component', patch);
|
||||||
|
} else {
|
||||||
|
loggingEnabled && logger.debug('Patching forwardref/memo');
|
||||||
|
wrapReactType(node, prop);
|
||||||
|
// Step down the object
|
||||||
|
patchComponent(node[prop], handler, steps, step, caches, logger, node[prop]?.render ? 'render' : 'type');
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
logger.error('Unhandled component type', node);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
loggingEnabled && logger.groupEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleStep(tree: any, handler: GenericPatchHandler, steps: NodeStep[], step: number, caches: PatchedComponentCache[], logger: Logger): any {
|
||||||
|
const startTime = (loggingEnabled || perfLoggingEnabled) ? performance.now() : 0;
|
||||||
|
const stepHandler = steps[step];
|
||||||
|
const cache = caches[step] || (caches[step] = new Map());
|
||||||
|
loggingEnabled && logger.debug(`Patch step ${step} running`, { tree, stepHandler, step, caches });
|
||||||
|
|
||||||
|
const node = stepHandler(tree);
|
||||||
|
if (node && node.type) {
|
||||||
|
loggingEnabled && logger.debug('Found node', node);
|
||||||
|
} else if (node) {
|
||||||
|
loggingEnabled && logger.error('Found node without type. Something is probably wrong.', node);
|
||||||
|
return tree;
|
||||||
|
} else {
|
||||||
|
loggingEnabled && logger.warn('Found no node. Depending on your usecase, this might be fine.', node);
|
||||||
|
return tree;
|
||||||
|
}
|
||||||
|
|
||||||
|
let cachedType;
|
||||||
|
if (cachedType = cache.get(node.type)) {
|
||||||
|
loggingEnabled && logger.debug('Found cached patched component', node);
|
||||||
|
node.type = cachedType;
|
||||||
|
(loggingEnabled || perfLoggingEnabled) && logger.debug(`Patch step ${step} took ${performance.now() - startTime}ms with cache`);
|
||||||
|
return tree;
|
||||||
|
}
|
||||||
|
|
||||||
|
const originalType = node.type;
|
||||||
|
|
||||||
|
patchComponent(node, handler, steps, step, caches, logger);
|
||||||
|
|
||||||
|
cache.set(originalType, node.type);
|
||||||
|
|
||||||
|
(loggingEnabled || perfLoggingEnabled) && logger.debug(`Patch step ${step} took ${performance.now() - startTime}ms`);
|
||||||
|
return tree;
|
||||||
|
};
|
||||||
|
|
||||||
|
function createStepHandler(handler: GenericPatchHandler, steps: NodeStep[], step: number, caches: PatchedComponentCache[], logger: Logger) {
|
||||||
|
loggingEnabled && logger.debug(`Creating handler for step ${step}`);
|
||||||
|
return (_: any, tree: any) => handleStep(tree, handler, steps, step, caches, logger);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO handle createReactTreePatcher inside handler and cache it (or warn)
|
||||||
|
export function createReactTreePatcher(steps: NodeStep[], handler: GenericPatchHandler, debugName: string = 'ReactPatch'): GenericPatchHandler {
|
||||||
|
const caches: PatchedComponentCache[] = [];
|
||||||
|
|
||||||
|
const logger = new Logger(`ReactTreePatcher -> ${debugName}`);
|
||||||
|
|
||||||
|
loggingEnabled && logger.debug('Init with options:', steps, debugName);
|
||||||
|
|
||||||
|
return createStepHandler(handler, steps, 0, caches, logger);
|
||||||
|
}
|
||||||
@@ -9,20 +9,21 @@ declare global {
|
|||||||
const logger = new Logger('Webpack');
|
const logger = new Logger('Webpack');
|
||||||
|
|
||||||
// In most case an object with getters for each property. Look for the first call to r.d in the module, usually near or at the top.
|
// In most case an object with getters for each property. Look for the first call to r.d in the module, usually near or at the top.
|
||||||
|
export type ModuleID = string; // number string
|
||||||
export type Module = any;
|
export type Module = any;
|
||||||
export type Export = any;
|
export type Export = any;
|
||||||
type FilterFn = (module: any) => boolean;
|
type FilterFn = (module: any) => boolean;
|
||||||
type ExportFilterFn = (moduleExport: any, exportName?: any) => boolean;
|
type ExportFilterFn = (moduleExport: any, exportName?: any) => boolean;
|
||||||
type FindFn = (module: any) => any;
|
type FindFn = (module: any) => any;
|
||||||
|
|
||||||
export let modules: any = [];
|
export let modules = new Map<ModuleID, Module>();
|
||||||
|
|
||||||
function initModuleCache() {
|
function initModuleCache() {
|
||||||
const startTime = performance.now();
|
const startTime = performance.now();
|
||||||
logger.group('Webpack Module Init');
|
logger.group('Webpack Module Init');
|
||||||
// Webpack 5, currently on beta
|
// Webpack 5, currently on beta
|
||||||
// Generate a fake module ID
|
// Generate a fake module ID
|
||||||
const id = Math.random(); // really should be an int and not a float but who cares
|
const id = Symbol("@decky/ui");
|
||||||
let webpackRequire!: ((id: any) => Module) & { m: object };
|
let webpackRequire!: ((id: any) => Module) & { m: object };
|
||||||
// Insert our module in a new chunk.
|
// Insert our module in a new chunk.
|
||||||
// The module will then be called with webpack's internal require function as its first argument
|
// The module will then be called with webpack's internal require function as its first argument
|
||||||
@@ -39,14 +40,14 @@ function initModuleCache() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Loop over every module ID
|
// Loop over every module ID
|
||||||
for (let i of Object.keys(webpackRequire.m)) {
|
for (let id of Object.keys(webpackRequire.m)) {
|
||||||
try {
|
try {
|
||||||
const module = webpackRequire(i);
|
const module = webpackRequire(id);
|
||||||
if (module) {
|
if (module) {
|
||||||
modules.push(module);
|
modules.set(id, module);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.debug('Ignoring require error for module', i, e);
|
logger.debug('Ignoring require error for module', id, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +57,7 @@ function initModuleCache() {
|
|||||||
initModuleCache();
|
initModuleCache();
|
||||||
|
|
||||||
export const findModule = (filter: FilterFn) => {
|
export const findModule = (filter: FilterFn) => {
|
||||||
for (const m of modules) {
|
for (const m of modules.values()) {
|
||||||
if (m.default && filter(m.default)) return m.default;
|
if (m.default && filter(m.default)) return m.default;
|
||||||
if (filter(m)) return m;
|
if (filter(m)) return m;
|
||||||
}
|
}
|
||||||
@@ -65,8 +66,8 @@ export const findModule = (filter: FilterFn) => {
|
|||||||
export const findModuleDetailsByExport = (
|
export const findModuleDetailsByExport = (
|
||||||
filter: ExportFilterFn,
|
filter: ExportFilterFn,
|
||||||
minExports?: number,
|
minExports?: number,
|
||||||
): [module: Module | undefined, moduleExport: any, exportName: any] => {
|
): [module: Module | undefined, moduleExport: any, exportName: any, moduleID: string | undefined] => {
|
||||||
for (const m of modules) {
|
for (const [id, m] of modules) {
|
||||||
if (!m) continue;
|
if (!m) continue;
|
||||||
for (const mod of [m.default, m]) {
|
for (const mod of [m.default, m]) {
|
||||||
if (typeof mod !== 'object') continue;
|
if (typeof mod !== 'object') continue;
|
||||||
@@ -75,7 +76,7 @@ export const findModuleDetailsByExport = (
|
|||||||
if (mod?.[exportName]) {
|
if (mod?.[exportName]) {
|
||||||
const filterRes = filter(mod[exportName], exportName);
|
const filterRes = filter(mod[exportName], exportName);
|
||||||
if (filterRes) {
|
if (filterRes) {
|
||||||
return [mod, mod[exportName], exportName];
|
return [mod, mod[exportName], exportName, id];
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -83,7 +84,7 @@ export const findModuleDetailsByExport = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return [undefined, undefined, undefined];
|
return [undefined, undefined, undefined, undefined];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const findModuleByExport = (filter: ExportFilterFn, minExports?: number) => {
|
export const findModuleByExport = (filter: ExportFilterFn, minExports?: number) => {
|
||||||
@@ -98,7 +99,7 @@ export const findModuleExport = (filter: ExportFilterFn, minExports?: number) =>
|
|||||||
* @deprecated use findModuleExport instead
|
* @deprecated use findModuleExport instead
|
||||||
*/
|
*/
|
||||||
export const findModuleChild = (filter: FindFn) => {
|
export const findModuleChild = (filter: FindFn) => {
|
||||||
for (const m of modules) {
|
for (const m of modules.values()) {
|
||||||
for (const mod of [m.default, m]) {
|
for (const mod of [m.default, m]) {
|
||||||
const filterRes = filter(mod);
|
const filterRes = filter(mod);
|
||||||
if (filterRes) {
|
if (filterRes) {
|
||||||
@@ -110,10 +111,13 @@ export const findModuleChild = (filter: FindFn) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated use createModuleMapping instead
|
||||||
|
*/
|
||||||
export const findAllModules = (filter: FilterFn) => {
|
export const findAllModules = (filter: FilterFn) => {
|
||||||
const out = [];
|
const out = [];
|
||||||
|
|
||||||
for (const m of modules) {
|
for (const m of modules.values()) {
|
||||||
if (m.default && filter(m.default)) out.push(m.default);
|
if (m.default && filter(m.default)) out.push(m.default);
|
||||||
if (filter(m)) out.push(m);
|
if (filter(m)) out.push(m);
|
||||||
}
|
}
|
||||||
@@ -121,7 +125,18 @@ export const findAllModules = (filter: FilterFn) => {
|
|||||||
return out;
|
return out;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const CommonUIModule = modules.find((m: Module) => {
|
export const createModuleMapping = (filter: FilterFn) => {
|
||||||
|
const mapping = new Map<ModuleID, Module>();
|
||||||
|
|
||||||
|
for (const [id, m] of modules) {
|
||||||
|
if (m.default && filter(m.default)) mapping.set(id, m.default);
|
||||||
|
if (filter(m)) mapping.set(id, m);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mapping;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const CommonUIModule = findModule((m: Module) => {
|
||||||
if (typeof m !== 'object') return false;
|
if (typeof m !== 'object') return false;
|
||||||
for (let prop in m) {
|
for (let prop in m) {
|
||||||
if (m[prop]?.contextType?._currentValue && Object.keys(m).length > 60) return true;
|
if (m[prop]?.contextType?._currentValue && Object.keys(m).length > 60) return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user