Compare commits

..

24 Commits

Author SHA1 Message Date
semantic-release-bot
15e672afef chore(release): 0.2.0 [CI SKIP] 2022-06-04 08:54:45 +00:00
Jonas Dellinger
bf0c2b17bf feat(router): expose GetQuickAccessTab and rename QuickAccessTabs to QuickAccessTab 2022-06-04 10:54:01 +02:00
Jonas Dellinger
0625dc385a chore(release): add NPM releaser 2022-06-04 10:49:30 +02:00
semantic-release-bot
b04992d29c chore(release): 0.1.0 [CI SKIP] 2022-06-04 08:44:52 +00:00
Jonas Dellinger
228fe1f22c chore(release): fix release script by installing commitlint cli 2022-06-04 10:44:01 +02:00
Jonas Dellinger
5d4214176e chore(release): try to fix commit message when releasing 2022-06-04 10:37:09 +02:00
Jonas Dellinger
62bf0eaffa feat(router): types for steam router 2022-06-04 10:33:59 +02:00
Jonas Dellinger
43b04b267e chore(release): disable jest for now 2022-06-04 10:19:04 +02:00
Jonas Dellinger
58595d54ea chore(release): fix branch selector 2022-06-04 10:17:17 +02:00
Jonas Dellinger
aec27a18a7 chore(release): introduce release pipeline 2022-06-04 10:14:59 +02:00
Jonas Dellinger
f101e23c1c 0.0.6 2022-06-02 17:58:18 +02:00
Jonas Dellinger
5b3ea8f63f 0.0.5 2022-06-02 17:57:48 +02:00
AAGaming
07ccceb990 add modal support, showModal->showContextMenu and new showModal 2022-06-01 17:51:17 -04:00
Jonas Dellinger
536269b1b7 Expose routerhook 2022-05-30 21:00:38 +02:00
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
23 changed files with 12637 additions and 3016 deletions

3
.commitlintrc.json Normal file
View File

@@ -0,0 +1,3 @@
{
"extends": ["@commitlint/config-conventional"]
}

29
.github/workflows/release.yaml vendored Normal file
View File

@@ -0,0 +1,29 @@
name: Release
on:
push:
branches:
- main
jobs:
release:
name: Release
runs-on: ubuntu-22.04
steps:
- name: Setup | Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup | Node.js
uses: actions/setup-node@v3
with:
node-version: 16
- name: Setup | Dependencies
run: npm ci
- name: Test
run: npm test
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm exec semantic-release

3
.gitignore vendored
View File

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

4
.husky/commit-msg Executable file
View File

@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npx --no -- commitlint --edit "${1}"

17
.releaserc.json Normal file
View File

@@ -0,0 +1,17 @@
{
"branches": ["main", "dev"],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
"@semantic-release/npm",
"@semantic-release/github",
[
"@semantic-release/git",
{
"assets": ["CHANGELOG.md", "package.json"],
"message": "chore(release): ${nextRelease.version} [CI SKIP]"
}
]
]
}

13
CHANGELOG.md Normal file
View File

@@ -0,0 +1,13 @@
# [0.2.0](https://github.com/SteamDeckHomebrew/decky-frontend-lib/compare/v0.1.0...v0.2.0) (2022-06-04)
### Features
* **router:** expose GetQuickAccessTab and rename QuickAccessTabs to QuickAccessTab ([bf0c2b1](https://github.com/SteamDeckHomebrew/decky-frontend-lib/commit/bf0c2b17bfc4e67a8aa90cfee6a91bd1482720d4))
# [0.1.0](https://github.com/SteamDeckHomebrew/decky-frontend-lib/compare/v0.0.6...v0.1.0) (2022-06-04)
### Features
* **router:** types for steam router ([62bf0ea](https://github.com/SteamDeckHomebrew/decky-frontend-lib/commit/62bf0eaffa83d85245a038ffe3819315bd02f045))

5
globals.d.ts vendored Normal file
View File

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

12418
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "decky-frontend-lib",
"version": "0.0.2",
"version": "0.2.0",
"description": "A library for building decky plugins",
"main": "dist/index.js",
"types": "dist/index.d.ts",
@@ -9,7 +9,9 @@
"build": "shx rm -rf dist && tsc -b",
"dev": "tsc -b -w",
"prepack": "npm run build",
"test": "jest"
"test": "echo 'No tests for now!'",
"postinstall": "husky install",
"commit": "git-cz"
},
"files": [
"/lib",
@@ -32,12 +34,26 @@
"url": "https://github.com/SteamDeckHomebrew/decky-frontend-lib/issues"
},
"homepage": "https://github.com/SteamDeckHomebrew/decky-frontend-lib#readme",
"config": {
"commitizen": {
"path": "@commitlint/cz-commitlint"
}
},
"devDependencies": {
"@commitlint/cli": "^17.0.2",
"@commitlint/config-conventional": "^17.0.2",
"@commitlint/cz-commitlint": "^17.0.0",
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/git": "^10.0.1",
"@types/jest": "^27.4.1",
"@types/react": "16.14.0",
"@types/react-router": "5.1.18",
"commitizen": "^4.2.4",
"husky": "^8.0.1",
"import-sort-style-module": "^6.0.0",
"jest": "^27.5.1",
"prettier-plugin-import-sort": "^0.0.7",
"semantic-release": "^19.0.2",
"shx": "^0.3.4",
"ts-jest": "^27.1.4",
"typescript": "^4.6.3"

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>;

11
src/deck-components/Menu.tsx Normal file → Executable file
View File

@@ -1,7 +1,16 @@
import { FC } from 'react';
import { FC, ReactNode } from 'react';
import { findModuleChild } from '../webpack';
export const showContextMenu: (children: ReactNode, parent?: EventTarget) => void = findModuleChild((m) => {
if (typeof m !== 'object') return undefined;
for (let prop in m) {
if (typeof m[prop] === 'function' && m[prop].toString().includes('stopPropagation))')) {
return m[prop];
}
}
});
interface MenuProps {
label: string;
onCancel?(): void;

24
src/deck-components/Modal.tsx Normal file → Executable file
View File

@@ -1,12 +1,28 @@
import { ReactNode } from 'react';
import { FC, ReactNode } from 'react';
import { findModuleChild } from '../webpack';
export const showModal: (children: ReactNode, parent: EventTarget) => void = findModuleChild((m) => {
// TODO: there is another argument, figure out what it does
export const showModal: (children: ReactNode, parent?: EventTarget) => void = findModuleChild((m) => {
if (typeof m !== 'object') return undefined;
for (let prop in m) {
if (typeof m[prop] === 'function' && m[prop].toString().includes('stopPropagation))')) {
if (typeof m[prop] === 'function' && m[prop].toString().includes('bHideMainWindowForPopouts:!0')) {
return m[prop];
}
}
});
interface ModalRootProps {
onMiddleButton?(): void,
onCancel?(): void;
onOK?(): void;
bAllowFullSize?: boolean;
}
export const ModalRoot = findModuleChild(m => {
if (typeof m !== "object") return undefined;
for (let prop in m) {
if (!m[prop]?.prototype?.OK && m[prop]?.prototype?.Cancel && m[prop]?.prototype?.render) {
return m[prop];
}
}
}) as FC<ModalRootProps>;

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,37 @@
import { Module, findModuleChild } from '../webpack';
export enum SideMenu {
None,
Main,
QuickAccess,
}
export enum QuickAccessTab {
Notifications,
RemotePlayTogetherControls,
VoiceChat,
Friends,
Settings,
Perf,
Help,
Decky,
}
interface Router {
CloseSideMenus(): void;
OpenQuickAccessMenu(quickAccessTab: QuickAccessTab): void;
GetQuickAccessTab(): QuickAccessTab;
NavigateToExternalWeb(url: string): void;
ToggleSideMenu(sideMenu: SideMenu): void;
CloseSideMenus(): void;
OpenSideMenu(sideMenu: SideMenu): void;
OpenPowerMenu(unknown?: any): void;
get RunningApps(): any;
}
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];
}
}) as Router;

View File

@@ -0,0 +1,8 @@
import { FC } from 'react';
import { IconsModule } from '../webpack';
// TODO type this and other icons?
export const Spinner = Object.values(IconsModule).find((mod: any) =>
mod?.toString && /Spinner\)}\),.\.createElement\(\"path\",{d:\"M18 /.test(mod.toString())
) as FC<{}>;

View File

@@ -0,0 +1,9 @@
import { FC } from 'react';
import { findModuleChild } from '../webpack';
export const SteamSpinner = findModuleChild((m) => {
if (typeof m !== "object") return undefined;
for (let prop in m) {
if (m[prop]?.toString()?.includes("Steam Spinner") && m[prop].toString().includes("PreloadThrobber")) return m[prop]
}
}) as FC<{}>;

5
src/deck-components/index.ts Normal file → Executable file
View File

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

View File

@@ -1,3 +1,6 @@
import type { ComponentType } from 'react';
import { RouteProps } from 'react-router';
export interface Plugin {
title: JSX.Element;
icon: JSX.Element;
@@ -17,7 +20,13 @@ interface ServerResponseError {
type ServerResponse<TRes> = ServerResponseSuccess<TRes> | ServerResponseError;
interface RouterHook {
addRoute(path: string, component: ComponentType, props?: Omit<RouteProps, 'path' | 'children'>): void;
removeRoute(path: string): void;
}
export interface ServerAPI {
routerHook: RouterHook;
callPluginMethod<TArgs = {}, TRes = {}>(methodName: string, args: TArgs): Promise<ServerResponse<TRes>>;
callServerMethod<TArgs = {}, TRes = {}>(methodName: string, args: TArgs): Promise<ServerResponse<TRes>>;
fetchNoCors<TRes = {}>(url: string, request: RequestInfo): Promise<ServerResponse<TRes>>;

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

@@ -5,7 +5,7 @@ declare global {
}
// TODO
type Module = any;
export type Module = any;
type FilterFn = (module: any) => boolean;
type FindFn = (module: any) => any;
@@ -58,7 +58,18 @@ export const CommonUIModule = allModules.find((m: Module) => {
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]}
})
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 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"]
}