Skip to content

Commit

Permalink
Initial implementation of global DFL instance (#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
AAGaming00 authored May 12, 2023
1 parent 0c83c9a commit d99f332
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 64 deletions.
2 changes: 1 addition & 1 deletion frontend/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
46 changes: 1 addition & 45 deletions frontend/src/developer.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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,
},
};
}
6 changes: 6 additions & 0 deletions frontend/src/index.ts
Original file line number Diff line number Diff line change
@@ -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');
})();
18 changes: 0 additions & 18 deletions frontend/src/index.tsx → frontend/src/start.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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());

Expand Down

0 comments on commit d99f332

Please sign in to comment.