Skip to content

Commit

Permalink
fix: Adjust tabs and toaster hooks to work on react 18, also half-fix…
Browse files Browse the repository at this point in the history
… Valve Internal
  • Loading branch information
AAGaming00 committed Dec 13, 2023
1 parent 91186da commit 80a00a0
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 35 deletions.
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
}
},
"dependencies": {
"decky-frontend-lib": "3.23.1",
"decky-frontend-lib": "3.24.1",
"filesize": "^10.0.7",
"i18next": "^23.2.1",
"i18next-http-backend": "^2.2.1",
Expand Down
8 changes: 4 additions & 4 deletions frontend/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 28 additions & 20 deletions frontend/src/developer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,40 @@ const logger = new Logger('DeveloperMode');

let removeSettingsObserver: () => void = () => {};

export async function setShowValveInternal(show: boolean) {
let settingsMod: any;
while (!settingsMod) {
settingsMod = findModuleChild((m) => {
if (typeof m !== 'object') return undefined;
for (let prop in m) {
if (typeof m[prop]?.settings?.bIsValveEmail !== 'undefined') return m[prop];
}
});
if (!settingsMod) {
logger.debug('[ValveInternal] waiting for settingsMod');
await sleep(1000);
}
declare global {
interface Window {
settingsStore: any;
}
}

export async function setShowValveInternal(show: boolean) {
if (show) {
removeSettingsObserver = settingsMod[
Object.getOwnPropertySymbols(settingsMod).find((x) => x.toString() == 'Symbol(mobx administration)') as any
].observe((e: any) => {
e.newValue.bIsValveEmail = true;
});
settingsMod.m_Settings.bIsValveEmail = true;
const mobx =
window.settingsStore[
Object.getOwnPropertySymbols(window.settingsStore).find(
(x) => x.toString() == 'Symbol(mobx administration)',
) as any
];

if (mobx.observe_) {
// New style, currently broken
logger.log('Valve internal not yet supported on this build.');
// removeSettingsObserver = mobx.observe_(mobx, [(e: any) => {
// console.log("got e", e)
// e.newValue.bIsValveEmail = true;
// }]);
} else if (mobx.observe) {
// Old style
removeSettingsObserver = mobx.observe((e: any) => {
e.newValue.bIsValveEmail = true;
});
}

window.settingsStore.m_Settings.bIsValveEmail = true;
logger.log('Enabled Valve Internal menu');
} else {
removeSettingsObserver();
settingsMod.m_Settings.bIsValveEmail = false;
window.settingsStore.m_Settings.bIsValveEmail = false;
logger.log('Disabled Valve Internal menu');
}
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/tabs-hook.old.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// TabsHook for versions before the Desktop merge
import { Patch, afterPatch, sleep } from 'decky-frontend-lib';
import { Patch, afterPatch, getReactRoot, sleep } from 'decky-frontend-lib';
import { memo } from 'react';

import NewTabsHook from './tabs-hook';
Expand Down Expand Up @@ -35,7 +35,7 @@ class TabsHook extends NewTabsHook {

init() {
const self = this;
const tree = (document.getElementById('root') as any)._reactRootContainer._internalRoot.current;
const tree = getReactRoot(document.getElementById('root') as any);
let scrollRoot: any;
async function findScrollRoot(currentNode: any, iters: number): Promise<any> {
if (iters >= 30) {
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/tabs-hook.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// TabsHook for versions after the Desktop merge
import { Patch, QuickAccessTab, afterPatch, findInReactTree, sleep } from 'decky-frontend-lib';
import { Patch, QuickAccessTab, afterPatch, findInReactTree, getReactRoot, sleep } from 'decky-frontend-lib';

import { QuickAccessVisibleStateProvider } from './components/QuickAccessVisibleState';
import Logger from './logger';
Expand Down Expand Up @@ -32,11 +32,11 @@ class TabsHook extends Logger {
}

init() {
const tree = (document.getElementById('root') as any)._reactRootContainer._internalRoot.current;
const tree = getReactRoot(document.getElementById('root') as any);
let qAMRoot: any;
const findQAMRoot = (currentNode: any, iters: number): any => {
if (iters >= 65) {
// currently 45
if (iters >= 80) {
// currently 67
return null;
}
if (
Expand Down
17 changes: 13 additions & 4 deletions frontend/src/toaster.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { Module, Patch, ToastData, afterPatch, findInReactTree, findModuleChild, sleep } from 'decky-frontend-lib';
import {
Module,
Patch,
ToastData,
afterPatch,
findInReactTree,
findModuleChild,
getReactRoot,
sleep,
} from 'decky-frontend-lib';
import { ReactNode } from 'react';

import Toast from './components/Toast';
Expand Down Expand Up @@ -38,10 +47,10 @@ class Toaster extends Logger {
// </DeckyToasterStateContextProvider>
// ));
let instance: any;
const tree = (document.getElementById('root') as any)._reactRootContainer._internalRoot.current;
const tree = getReactRoot(document.getElementById('root') as any);
const findToasterRoot = (currentNode: any, iters: number): any => {
if (iters >= 65) {
// currently 65
if (iters >= 80) {
// currently 66
return null;
}
if (
Expand Down

0 comments on commit 80a00a0

Please sign in to comment.