Update decky-frontend-lib and refactor patches

This commit is contained in:
AAGaming
2022-09-04 13:33:42 -04:00
parent eb439574be
commit acaf6c72e4
5 changed files with 21 additions and 18 deletions
+1 -1
View File
@@ -39,7 +39,7 @@
} }
}, },
"dependencies": { "dependencies": {
"decky-frontend-lib": "^1.8.2", "decky-frontend-lib": "^2.0.0",
"react-icons": "^4.4.0", "react-icons": "^4.4.0",
"react-markdown": "^8.0.3", "react-markdown": "^8.0.3",
"remark-gfm": "^3.0.1" "remark-gfm": "^3.0.1"
+4 -4
View File
@@ -9,7 +9,7 @@ specifiers:
'@types/react': 16.14.0 '@types/react': 16.14.0
'@types/react-router': 5.1.18 '@types/react-router': 5.1.18
'@types/webpack': ^5.28.0 '@types/webpack': ^5.28.0
decky-frontend-lib: ^1.8.2 decky-frontend-lib: ^2.0.0
husky: ^8.0.1 husky: ^8.0.1
import-sort-style-module: ^6.0.0 import-sort-style-module: ^6.0.0
inquirer: ^8.2.4 inquirer: ^8.2.4
@@ -27,7 +27,7 @@ specifiers:
typescript: ^4.7.4 typescript: ^4.7.4
dependencies: dependencies:
decky-frontend-lib: 1.8.2 decky-frontend-lib: 2.0.0
react-icons: 4.4.0_react@16.14.0 react-icons: 4.4.0_react@16.14.0
react-markdown: 8.0.3_vshvapmxg47tngu7tvrsqpq55u react-markdown: 8.0.3_vshvapmxg47tngu7tvrsqpq55u
remark-gfm: 3.0.1 remark-gfm: 3.0.1
@@ -875,8 +875,8 @@ packages:
dependencies: dependencies:
ms: 2.1.2 ms: 2.1.2
/decky-frontend-lib/1.8.2: /decky-frontend-lib/2.0.0:
resolution: {integrity: sha512-SwGoUBpKd8OM3kovItW+oCpevDiDXFu0UaUh1vyD4BYG0s+4uQBdeevWLhyJHk0402pAUDrOL8022jpana5dnA==} resolution: {integrity: sha512-H7+JpKHlClECVpo+MCEwej7R9wDWk9M2uMSyTvuhTfLZe3RThsxWCiqY640Cjh/zIW2A7GyVRd4SjLtn6Isdeg==}
dependencies: dependencies:
minimist: 1.2.6 minimist: 1.2.6
dev: false dev: false
+7 -5
View File
@@ -1,4 +1,4 @@
import { afterPatch, findModuleChild, unpatch } from 'decky-frontend-lib'; import { Patch, afterPatch, findModuleChild } from 'decky-frontend-lib';
import { ReactElement, ReactNode, cloneElement, createElement, memo } from 'react'; import { ReactElement, ReactNode, cloneElement, createElement, memo } from 'react';
import type { Route } from 'react-router'; import type { Route } from 'react-router';
@@ -22,6 +22,8 @@ class RouterHook extends Logger {
private memoizedRouter: any; private memoizedRouter: any;
private gamepadWrapper: any; private gamepadWrapper: any;
private routerState: DeckyRouterState = new DeckyRouterState(); private routerState: DeckyRouterState = new DeckyRouterState();
private wrapperPatch: Patch;
private routerPatch?: Patch;
constructor() { constructor() {
super('RouterHook'); super('RouterHook');
@@ -87,7 +89,7 @@ class RouterHook extends Logger {
return children; return children;
}; };
afterPatch(this.gamepadWrapper, 'render', (_: any, ret: any) => { this.wrapperPatch = afterPatch(this.gamepadWrapper, 'render', (_: any, ret: any) => {
if (ret?.props?.children?.props?.children?.length == 5) { if (ret?.props?.children?.props?.children?.length == 5) {
if ( if (
ret.props.children.props.children[2]?.props?.children?.[0]?.type?.type ret.props.children.props.children[2]?.props?.children?.[0]?.type?.type
@@ -96,7 +98,7 @@ class RouterHook extends Logger {
) { ) {
if (!this.router) { if (!this.router) {
this.router = ret.props.children.props.children[2]?.props?.children?.[0]?.type; this.router = ret.props.children.props.children[2]?.props?.children?.[0]?.type;
afterPatch(this.router, 'type', (_: any, ret: any) => { this.routerPatch = afterPatch(this.router, 'type', (_: any, ret: any) => {
if (!Route) if (!Route)
Route = ret.props.children[0].props.children.find((x: any) => x.props.path == '/createaccount').type; Route = ret.props.children[0].props.children.find((x: any) => x.props.path == '/createaccount').type;
const returnVal = ( const returnVal = (
@@ -133,8 +135,8 @@ class RouterHook extends Logger {
} }
deinit() { deinit() {
unpatch(this.gamepadWrapper, 'render'); this.wrapperPatch.unpatch();
this.router && unpatch(this.router, 'type'); this.routerPatch?.unpatch();
} }
} }
+5 -3
View File
@@ -1,4 +1,4 @@
import { QuickAccessTab, afterPatch, sleep, unpatch } from 'decky-frontend-lib'; import { Patch, QuickAccessTab, afterPatch, sleep } from 'decky-frontend-lib';
import { memo } from 'react'; import { memo } from 'react';
import Logger from './logger'; import Logger from './logger';
@@ -35,6 +35,8 @@ class TabsHook extends Logger {
private qAPTree: any; private qAPTree: any;
private rendererTree: any; private rendererTree: any;
private cNodePatch?: Patch;
constructor() { constructor() {
super('TabsHook'); super('TabsHook');
@@ -60,7 +62,7 @@ class TabsHook extends Logger {
} }
let newQA: any; let newQA: any;
let newQATabRenderer: any; let newQATabRenderer: any;
afterPatch(scrollRoot.stateNode, 'render', (_: any, ret: any) => { this.cNodePatch = afterPatch(scrollRoot.stateNode, 'render', (_: any, ret: any) => {
if (!this.quickAccess && ret.props.children.props.children[4]) { if (!this.quickAccess && ret.props.children.props.children[4]) {
this.quickAccess = ret?.props?.children?.props?.children[4].type; this.quickAccess = ret?.props?.children?.props?.children[4].type;
newQA = (...args: any) => { newQA = (...args: any) => {
@@ -103,7 +105,7 @@ class TabsHook extends Logger {
} }
deinit() { deinit() {
if (this.cNode) unpatch(this.cNode.stateNode, 'render'); this.cNodePatch?.unpatch();
if (this.qAPTree) this.qAPTree.type = this.quickAccess; if (this.qAPTree) this.qAPTree.type = this.quickAccess;
if (this.rendererTree) this.rendererTree.type = this.tabRenderer; if (this.rendererTree) this.rendererTree.type = this.tabRenderer;
if (this.cNode) this.cNode.stateNode.forceUpdate(); if (this.cNode) this.cNode.stateNode.forceUpdate();
+4 -5
View File
@@ -1,4 +1,4 @@
import { ToastData, afterPatch, findInReactTree, findModuleChild, sleep, unpatch } from 'decky-frontend-lib'; import { Patch, ToastData, afterPatch, findInReactTree, findModuleChild, sleep } from 'decky-frontend-lib';
import Toast from './components/Toast'; import Toast from './components/Toast';
import Logger from './logger'; import Logger from './logger';
@@ -11,7 +11,7 @@ declare global {
} }
class Toaster extends Logger { class Toaster extends Logger {
private instanceRet: any; private instanceRetPatch?: Patch;
private node: any; private node: any;
private settingsModule: any; private settingsModule: any;
@@ -46,8 +46,7 @@ class Toaster extends Logger {
this.node.stateNode.render = (...args: any[]) => { this.node.stateNode.render = (...args: any[]) => {
const ret = this.node.stateNode.__proto__.render.call(this.node.stateNode, ...args); const ret = this.node.stateNode.__proto__.render.call(this.node.stateNode, ...args);
if (ret) { if (ret) {
this.instanceRet = ret; this.instanceRetPatch = afterPatch(ret, 'type', (_: any, ret: any) => {
afterPatch(ret, 'type', (_: any, ret: any) => {
if (ret?.props?.children[1]?.children?.props?.notification?.decky) { if (ret?.props?.children[1]?.children?.props?.notification?.decky) {
const toast = ret.props.children[1].children.props.notification; const toast = ret.props.children[1].children.props.notification;
ret.props.children[1].children.type = () => <Toast toast={toast} />; ret.props.children[1].children.type = () => <Toast toast={toast} />;
@@ -84,7 +83,7 @@ class Toaster extends Logger {
} }
deinit() { deinit() {
this.instanceRet && unpatch(this.instanceRet, 'type'); this.instanceRetPatch?.unpatch();
this.node && delete this.node.stateNode.render; this.node && delete this.node.stateNode.render;
this.node && this.node.stateNode.forceUpdate(); this.node && this.node.stateNode.forceUpdate();
} }