Compare commits

..

10 Commits

Author SHA1 Message Date
Jonas Dellinger
1e92d5c754 0.0.4 2022-05-30 20:51:27 +02:00
AAGaming
668ab618fc add patcher and react utils 2022-05-29 20:19:10 -04:00
AAGaming
5d59bf348c fix react 2022-05-28 21:49:38 -04:00
AAGaming
a5ac702820 fix typescript AGAIN, fix icons, ignore pnpm lock 2022-05-28 20:54:25 -04:00
Jonas Dellinger
f882636be7 0.0.3 2022-05-26 13:29:00 +02:00
Jonas Dellinger
815129d03f Export DialogButton and add icon prop 2022-05-26 13:28:35 +02:00
Jonas Dellinger
ef41d17e43 Add back panels 2022-05-26 10:15:32 +02:00
AAGaming
6d4ca5dc92 Merge branch 'main' of github.com:steamdeckhomebrew/decky-frontend-lib 2022-05-25 20:26:43 -04:00
AAGaming
0303724794 export more stuff, replace button component with actual button and move the old one to ButtonItem 2022-05-25 20:26:30 -04:00
Jonas Dellinger
98c226b8e6 Remove pnpm lock 2022-05-25 21:03:03 +02:00
13 changed files with 145 additions and 2924 deletions

3
.gitignore vendored
View File

@@ -35,3 +35,6 @@ Thumbs.db
dist/
research/
# PNPM lockfile
pnpm-lock.yaml

5
globals.d.ts vendored Normal file
View File

@@ -0,0 +1,5 @@
declare global {
interface Window {
SP_REACT: typeof React;
}
}

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "decky-frontend-lib",
"version": "0.0.1",
"version": "0.0.4",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "decky-frontend-lib",
"version": "0.0.1",
"version": "0.0.4",
"license": "GPL-2.0-or-later",
"devDependencies": {
"@types/jest": "^27.4.1",

View File

@@ -1,6 +1,6 @@
{
"name": "decky-frontend-lib",
"version": "0.0.2",
"version": "0.0.4",
"description": "A library for building decky plugins",
"main": "dist/index.js",
"types": "dist/index.d.ts",

2899
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -3,14 +3,27 @@ import { FC } from 'react';
import { CommonUIModule } from '../webpack';
interface ButtonProps {
label?: string;
description?: string;
layout?: 'below';
onClick?(e: MouseEvent): void;
className?: string;
noFocusRing?: boolean;
disabled?: boolean;
bottomSeparator?: boolean;
onClick?(e: MouseEvent): void;
onPointerDown?(e: PointerEvent): void;
onPointerUp?(e: PointerEvent): void;
onPointerCancel?(e: PointerEvent): void;
onMouseDown?(e: PointerEvent): void;
onMouseUp?(e: MouseEvent): void;
onTouchStart?(e: TouchEvent): void;
onTouchEnd?(e: TouchEvent): void;
onTouchCancel?(e: TouchEvent): void;
onSubmit?(e: SubmitEvent): void;
}
export const Button = Object.values(CommonUIModule).find((mod: any) =>
mod?.render?.toString()?.includes('childrenContainerWidth:"min"'),
) as FC<ButtonProps>;
export const DialogButton = Object.values(CommonUIModule).find(
(mod: any) =>
mod?.render?.toString()?.includes('Object.assign({type:"button"') &&
mod?.render?.toString()?.includes('DialogButton'),
) as any;
// Button isn't exported, so call DialogButton to grab it
export const Button = DialogButton!.render({}).type as FC<ButtonProps>; // its actually a forwarded ref but that doesn't really matter in usage

View File

@@ -0,0 +1,17 @@
import { FC } from 'react';
import { CommonUIModule } from '../webpack';
interface ButtonItemProps {
label?: string;
description?: string;
layout?: 'below';
icon?: JSX.Element;
onClick?(e: MouseEvent): void;
disabled?: boolean;
bottomSeparator?: boolean;
}
export const ButtonItem = Object.values(CommonUIModule).find((mod: any) =>
mod?.render?.toString()?.includes('childrenContainerWidth:"min"'),
) as FC<ButtonItemProps>;

View File

@@ -0,0 +1,23 @@
import { FC } from 'react';
import { findModuleChild } from '../webpack';
interface PanelSectionProps {
title?: string;
spinner?: boolean;
}
const [panelSection, mod] = findModuleChild((mod: any) => {
for (let prop in mod) {
if (mod[prop]?.toString()?.includes('.PanelSection')) {
return [mod[prop], mod];
}
}
return null;
});
export const PanelSection = panelSection as FC<PanelSectionProps>;
export const PanelSectionRow = Object.values(mod).filter(
(exp: any) => !exp?.toString()?.includes('.PanelSection'),
)[0] as FC;

View File

@@ -0,0 +1,16 @@
import { FC } from 'react';
import { IconsModule } from '../webpack';
// interface ButtonProps {
// label?: string;
// description?: string;
// layout?: 'below';
// onClick?(e: MouseEvent): void;
// disabled?: boolean;
// bottomSeparator?: boolean;
// }
export const Spinner = Object.values(IconsModule).find((mod: any) =>
mod?.toString && /Spinner\)}\),.\.createElement\(\"path\",{d:\"M18 /.test(mod.toString())
) as FC<{}>;

View File

@@ -1,6 +1,9 @@
export * from './Button';
export * from './ButtonItem';
export * from './Menu';
export * from './Modal';
export * from './Panel';
export * from './Slider';
export * from './Spinner';
export * from './static-classes';
export * from './Toggle';

View File

@@ -1,35 +1,41 @@
export function sleep(ms: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, ms));
}
import * as React from "react";
// this shouldn't need to be redeclared but it does for some reason
declare global {
interface Window {
SP_REACT: any;
SP_REACT: typeof React;
}
}
export function fakeRenderComponent(fun: Function): any {
const hooks = window.SP_REACT.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher.current;
const hooks = (window.SP_REACT as any).__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher.current;
// TODO: add more hooks
let oldHooks = {
useContext: hooks.useContext,
useCallback: hooks.useCallback,
useLayoutEffect: hooks.useLayoutEffect,
useEffect: hooks.useEffect,
useMemo: hooks.useMemo,
useRef: hooks.useRef,
useState: hooks.useState,
}
hooks.useCallback = (cb: Function) => cb;
hooks.useContext = (cb: Function) => cb;
hooks.useEffect = (cb: Function) => cb();
hooks.useContext = (cb: any) => cb._currentValue;
hooks.useLayoutEffect = (_: Function) => {}//cb();
hooks.useMemo = (cb: Function, _: any[]) => cb;
hooks.useEffect = (_: Function) => {}//cb();
hooks.useRef = (val: any) => ({current: val || {}});
hooks.useState = (v: any) => {
let val = v;
return [val, (n: any) => val = n];
};
const res = fun();
const res = fun(hooks);
Object.assign(hooks, oldHooks);
@@ -50,8 +56,8 @@ export function beforePatch(obj: any, name: string, fnc: Function): void {
export function afterPatch(obj: any, name: string, fnc: Function): void {
const orig = obj[name];
obj[name] = function (...args: any[]) {
let ret = orig.apply(...args);
ret = fnc(ret);
let ret = orig.call(this, ...args);
ret = fnc.call(this, args, ret);
return ret;
}
Object.assign(obj[name], orig);
@@ -59,7 +65,23 @@ export function afterPatch(obj: any, name: string, fnc: Function): void {
obj[name].__deckyOrig = orig;
}
export function replacePatch(obj: any, name: string, fnc: Function): void {
const orig = obj[name];
obj[name] = function (...args: any[]) {
const ret = fnc.call(this, args);
if (ret == 'CALL_ORIGINAL') return orig.call(this, ...args);
return ret;
};
Object.assign(obj[name], orig);
obj[name].toString = () => orig.toString();
obj[name].__deckyOrig = orig;
}
// TODO allow one method to be patched and unpatched multiple times independently using IDs in a Map or something
export function unpatch(obj: any, name: any): void {
obj[name] = obj[name].__deckyOrig;
}
}
export function getReactInstance(o: HTMLElement | Element | Node) {
return o[Object.keys(o).find(k => k.startsWith('__reactInternalInstance')) as string]
}

View File

@@ -58,7 +58,24 @@ export const CommonUIModule = allModules.find((m: Module) => {
return false;
});
export const IconsModule = findModule((m: Module) => {
if (typeof m !== "object") return false;
for (let prop in m) {
if (m[prop]?.toString && /Spinner\)}\),.\.createElement\(\"path\",{d:\"M18 /.test(m[prop].toString())) return true;
}
return false;
})
export const Router = findModuleChild((m: Module) => {
if (typeof m !== "object") return undefined;
for (let prop in m) { if (m[prop]?.Navigate && m[prop]?.NavigationManager) return m[prop]}
for (let prop in m) {
if (m[prop]?.Navigate && m[prop]?.NavigationManager) return m[prop]
}
})
export const ReactRouter = allModules.find((m: Module) => {
if (typeof m !== "object") return undefined;
for (let prop in m) {
if (m[prop]?.computeRootMatch) return true
}
return false;
})

View File

@@ -3,7 +3,8 @@
"outDir": "dist",
"module": "ESNext",
"target": "ES2020",
"jsx": "react-jsx",
"jsx": "react",
"jsxFactory": "window.SP_REACT.createElement",
"declaration": true,
"moduleResolution": "node",
"noUnusedLocals": true,
@@ -17,6 +18,6 @@
"allowSyntheticDefaultImports": true,
"skipLibCheck": true
},
"include": ["src"],
"include": ["src", "globals.d.ts"],
"exclude": ["node_modules"]
}