From d99f332523c1e70df8ed1f0d024cc6dd77607433 Mon Sep 17 00:00:00 2001 From: AAGaming Date: Fri, 12 May 2023 02:02:04 +0000 Subject: [PATCH] Initial implementation of global DFL instance (#451) --- frontend/rollup.config.js | 2 +- frontend/src/developer.tsx | 46 +-------------------------- frontend/src/index.ts | 6 ++++ frontend/src/{index.tsx => start.tsx} | 18 ----------- 4 files changed, 8 insertions(+), 64 deletions(-) create mode 100644 frontend/src/index.ts rename frontend/src/{index.tsx => start.tsx} (75%) diff --git a/frontend/rollup.config.js b/frontend/rollup.config.js index 360aa1428..2573b8a02 100644 --- a/frontend/rollup.config.js +++ b/frontend/rollup.config.js @@ -11,7 +11,7 @@ import externalGlobals from 'rollup-plugin-external-globals'; const hiddenWarnings = ['THIS_IS_UNDEFINED', 'EVAL']; export default defineConfig({ - input: 'src/index.tsx', + input: 'src/index.ts', plugins: [ del({ targets: '../backend/static/*', force: true }), commonjs(), diff --git a/frontend/src/developer.tsx b/frontend/src/developer.tsx index 56d28fbfb..30b8cf916 100644 --- a/frontend/src/developer.tsx +++ b/frontend/src/developer.tsx @@ -1,23 +1,4 @@ -import { - Navigation, - ReactRouter, - Router, - fakeRenderComponent, - findInReactTree, - findInTree, - findModule, - findModuleChild, - gamepadDialogClasses, - gamepadSliderClasses, - playSectionClasses, - quickAccessControlsClasses, - quickAccessMenuClasses, - scrollClasses, - scrollPanelClasses, - sleep, - staticClasses, - updaterFieldClasses, -} from 'decky-frontend-lib'; +import { findModuleChild, sleep } from 'decky-frontend-lib'; import { useTranslation } from 'react-i18next'; import { FaReact } from 'react-icons/fa'; @@ -80,29 +61,4 @@ export async function startup() { if ((isRDTEnabled && !window.deckyHasConnectedRDT) || (!isRDTEnabled && window.deckyHasConnectedRDT)) setShouldConnectToReactDevTools(isRDTEnabled); - - logger.log('Exposing decky-frontend-lib APIs as DFL'); - window.DFL = { - findModuleChild, - findModule, - Navigation, - Router, - ReactRouter, - ReactUtils: { - fakeRenderComponent, - findInReactTree, - findInTree, - }, - classes: { - scrollClasses, - staticClasses, - playSectionClasses, - scrollPanelClasses, - updaterFieldClasses, - gamepadDialogClasses, - gamepadSliderClasses, - quickAccessMenuClasses, - quickAccessControlsClasses, - }, - }; } diff --git a/frontend/src/index.ts b/frontend/src/index.ts new file mode 100644 index 000000000..6588cb5c1 --- /dev/null +++ b/frontend/src/index.ts @@ -0,0 +1,6 @@ +// Sets up DFL, then loads start.ts which starts up the loader +(async () => { + console.debug('Setting up decky-frontend-lib...'); + window.DFL = await import('decky-frontend-lib'); + await import('./start'); +})(); diff --git a/frontend/src/index.tsx b/frontend/src/start.tsx similarity index 75% rename from frontend/src/index.tsx rename to frontend/src/start.tsx index b9edc0b1e..94b22ffe0 100644 --- a/frontend/src/index.tsx +++ b/frontend/src/start.tsx @@ -1,4 +1,3 @@ -import { Navigation, Router, sleep } from 'decky-frontend-lib'; import i18n from 'i18next'; import Backend from 'i18next-http-backend'; import { initReactI18next } from 'react-i18next'; @@ -19,23 +18,6 @@ declare global { } } -(async () => { - try { - if (!Router.NavigateToAppProperties || !Router.NavigateToLibraryTab || !Router.NavigateToInvites) { - while (!Navigation.NavigateToAppProperties) await sleep(100); - const shims = { - NavigateToAppProperties: Navigation.NavigateToAppProperties, - NavigateToInvites: Navigation.NavigateToInvites, - NavigateToLibraryTab: Navigation.NavigateToLibraryTab, - }; - (Router as unknown as any).deckyShim = true; - Object.assign(Router, shims); - } - } catch (e) { - console.error('[DECKY]: Error initializing Navigation interface shims', e); - } -})(); - (async () => { window.deckyAuthToken = await fetch('http://127.0.0.1:1337/auth/token').then((r) => r.text());