port to @decky/ui

TODO: update package.json to match once @decky/ui is on NPM
This commit is contained in:
AAGaming
2024-05-12 15:47:08 -04:00
parent 43b940e216
commit 0b1c069448
36 changed files with 51 additions and 85 deletions
+1 -2
View File
@@ -1,6 +1,5 @@
{ {
"name": "decky_frontend", "name": "@decky/loader-frontend",
"version": "2.1.1",
"private": true, "private": true,
"license": "GPLV2", "license": "GPLV2",
"scripts": { "scripts": {
+1 -1
View File
@@ -1,4 +1,4 @@
import { ToastData, joinClassNames } from 'decky-frontend-lib'; import { ToastData, joinClassNames } from '@decky/ui';
import { FC, useEffect, useState } from 'react'; import { FC, useEffect, useState } from 'react';
import { ReactElement } from 'react-markdown/lib/react-markdown'; import { ReactElement } from 'react-markdown/lib/react-markdown';
@@ -1,4 +1,4 @@
import { ToastData } from 'decky-frontend-lib'; import { ToastData } from '@decky/ui';
import { FC, createContext, useContext, useEffect, useState } from 'react'; import { FC, createContext, useContext, useEffect, useState } from 'react';
interface PublicDeckyToasterState { interface PublicDeckyToasterState {
+1 -1
View File
@@ -1,4 +1,4 @@
import { Focusable, Navigation } from 'decky-frontend-lib'; import { Focusable, Navigation } from '@decky/ui';
import { FunctionComponent, useRef } from 'react'; import { FunctionComponent, useRef } from 'react';
import ReactMarkdown, { Options as ReactMarkdownOptions } from 'react-markdown'; import ReactMarkdown, { Options as ReactMarkdownOptions } from 'react-markdown';
import remarkGfm from 'remark-gfm'; import remarkGfm from 'remark-gfm';
+1 -1
View File
@@ -1,4 +1,4 @@
import { ButtonItem, Focusable, PanelSection, PanelSectionRow } from 'decky-frontend-lib'; import { ButtonItem, Focusable, PanelSection, PanelSectionRow } from '@decky/ui';
import { VFC, useEffect, useState } from 'react'; import { VFC, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { FaEyeSlash } from 'react-icons/fa'; import { FaEyeSlash } from 'react-icons/fa';
+1 -1
View File
@@ -1,4 +1,4 @@
import { DialogButton, Focusable, Router, staticClasses } from 'decky-frontend-lib'; import { DialogButton, Focusable, Router, staticClasses } from '@decky/ui';
import { CSSProperties, VFC } from 'react'; import { CSSProperties, VFC } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { BsGearFill } from 'react-icons/bs'; import { BsGearFill } from 'react-icons/bs';
+1 -1
View File
@@ -1,4 +1,4 @@
import { ToastData, findModule, joinClassNames } from 'decky-frontend-lib'; import { ToastData, findModule, joinClassNames } from '@decky/ui';
import { FunctionComponent } from 'react'; import { FunctionComponent } from 'react';
interface ToastProps { interface ToastProps {
+1 -1
View File
@@ -1,4 +1,4 @@
import { Focusable, SteamSpinner } from 'decky-frontend-lib'; import { Focusable, SteamSpinner } from '@decky/ui';
import { FunctionComponent, ReactElement, ReactNode, Suspense } from 'react'; import { FunctionComponent, ReactElement, ReactNode, Suspense } from 'react';
interface WithSuspenseProps { interface WithSuspenseProps {
@@ -2,24 +2,21 @@ import {
DialogButton, DialogButton,
DialogCheckbox, DialogCheckbox,
DialogCheckboxProps, DialogCheckboxProps,
Export,
Marquee, Marquee,
Menu, Menu,
MenuItem, MenuItem,
findModuleChild, findModuleExport,
showContextMenu, showContextMenu,
} from 'decky-frontend-lib'; } from '@decky/ui';
import { FC, useCallback, useEffect, useState } from 'react'; import { FC, useCallback, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { FaChevronDown } from 'react-icons/fa'; import { FaChevronDown } from 'react-icons/fa';
const dropDownControlButtonClass = findModuleChild((m) => { // TODO add to dfl
if (typeof m !== 'object') return undefined; const dropDownControlButtonClass = findModuleExport((e: Export) =>
for (const prop in m) { e?.toString()?.includes('gamepaddropdown_DropDownControlButton'),
if (m[prop]?.toString()?.includes('gamepaddropdown_DropDownControlButton')) { );
return m[prop];
}
}
});
const DropdownMultiselectItem: FC< const DropdownMultiselectItem: FC<
{ {
@@ -1,4 +1,4 @@
import { ConfirmModal, Navigation, QuickAccessTab } from 'decky-frontend-lib'; import { ConfirmModal, Navigation, QuickAccessTab } from '@decky/ui';
import { FC, useMemo, useState } from 'react'; import { FC, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
@@ -1,4 +1,4 @@
import { ConfirmModal, Navigation, QuickAccessTab } from 'decky-frontend-lib'; import { ConfirmModal, Navigation, QuickAccessTab } from '@decky/ui';
import { FC, useState } from 'react'; import { FC, useState } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
@@ -1,4 +1,4 @@
import { ConfirmModal } from 'decky-frontend-lib'; import { ConfirmModal } from '@decky/ui';
import { FC } from 'react'; import { FC } from 'react';
import { uninstallPlugin } from '../../plugin'; import { uninstallPlugin } from '../../plugin';
@@ -10,7 +10,7 @@ import {
SteamSpinner, SteamSpinner,
TextField, TextField,
ToggleField, ToggleField,
} from 'decky-frontend-lib'; } from '@decky/ui';
import { filesize } from 'filesize'; import { filesize } from 'filesize';
import { FunctionComponent, useCallback, useEffect, useMemo, useState } from 'react'; import { FunctionComponent, useCallback, useEffect, useMemo, useState } from 'react';
import { DefaultExtensionType, FileIcon, defaultStyles } from 'react-file-icon'; import { DefaultExtensionType, FileIcon, defaultStyles } from 'react-file-icon';
@@ -1,4 +1,4 @@
import { Patch, findModuleChild, replacePatch, sleep } from 'decky-frontend-lib'; import { Export, Patch, findModuleExport, replacePatch, sleep } from '@decky/ui';
import Logger from '../../../../logger'; import Logger from '../../../../logger';
import { FileSelectionType } from '..'; import { FileSelectionType } from '..';
@@ -39,12 +39,7 @@ export default async function libraryPatch() {
let History: any; let History: any;
while (!History) { while (!History) {
History = findModuleChild((m) => { History = findModuleExport((e: Export) => e.m_history)?.m_history;
if (typeof m !== 'object') return undefined;
for (let prop in m) {
if (m[prop]?.m_history) return m[prop].m_history;
}
});
if (!History) { if (!History) {
logger.debug('Waiting 5s for history to become available.'); logger.debug('Waiting 5s for history to become available.');
await sleep(5000); await sleep(5000);
@@ -1,4 +1,4 @@
import { Focusable, updaterFieldClasses } from 'decky-frontend-lib'; import { Focusable, updaterFieldClasses } from '@decky/ui';
import { FunctionComponent, ReactNode } from 'react'; import { FunctionComponent, ReactNode } from 'react';
interface InlinePatchNotesProps { interface InlinePatchNotesProps {
+1 -1
View File
@@ -1,4 +1,4 @@
import { SidebarNavigation } from 'decky-frontend-lib'; import { SidebarNavigation } from '@decky/ui';
import { lazy } from 'react'; import { lazy } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { FaCode, FaFlask, FaPlug } from 'react-icons/fa'; import { FaCode, FaFlask, FaPlug } from 'react-icons/fa';
@@ -7,7 +7,7 @@ import {
Navigation, Navigation,
TextField, TextField,
Toggle, Toggle,
} from 'decky-frontend-lib'; } from '@decky/ui';
import { useRef, useState } from 'react'; import { useRef, useState } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { FaFileArchive, FaLink, FaReact, FaSteamSymbol, FaTerminal } from 'react-icons/fa'; import { FaFileArchive, FaLink, FaReact, FaSteamSymbol, FaTerminal } from 'react-icons/fa';
@@ -1,4 +1,4 @@
import { Dropdown, Field } from 'decky-frontend-lib'; import { Dropdown, Field } from '@decky/ui';
import { FunctionComponent } from 'react'; import { FunctionComponent } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
@@ -1,4 +1,4 @@
import { Field, Toggle } from 'decky-frontend-lib'; import { Field, Toggle } from '@decky/ui';
import { FC } from 'react'; import { FC } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
@@ -1,4 +1,4 @@
import { Field, Toggle } from 'decky-frontend-lib'; import { Field, Toggle } from '@decky/ui';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { FaChrome } from 'react-icons/fa'; import { FaChrome } from 'react-icons/fa';
@@ -1,4 +1,4 @@
import { Dropdown, Field, TextField } from 'decky-frontend-lib'; import { Dropdown, Field, TextField } from '@decky/ui';
import { FunctionComponent } from 'react'; import { FunctionComponent } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { FaShapes } from 'react-icons/fa'; import { FaShapes } from 'react-icons/fa';
@@ -8,7 +8,7 @@ import {
Spinner, Spinner,
findSP, findSP,
showModal, showModal,
} from 'decky-frontend-lib'; } from '@decky/ui';
import { Suspense, lazy, useCallback, useEffect, useState } from 'react'; import { Suspense, lazy, useCallback, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { FaExclamation } from 'react-icons/fa'; import { FaExclamation } from 'react-icons/fa';
@@ -1,4 +1,4 @@
import { DialogBody, DialogControlsSection, DialogControlsSectionHeader, Field, Toggle } from 'decky-frontend-lib'; import { DialogBody, DialogControlsSection, DialogControlsSectionHeader, Field, Toggle } from '@decky/ui';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useDeckyState } from '../../../DeckyState'; import { useDeckyState } from '../../../DeckyState';
@@ -8,7 +8,7 @@ import {
ReorderableEntry, ReorderableEntry,
ReorderableList, ReorderableList,
showContextMenu, showContextMenu,
} from 'decky-frontend-lib'; } from '@decky/ui';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { FaDownload, FaEllipsisH, FaRecycle } from 'react-icons/fa'; import { FaDownload, FaEllipsisH, FaRecycle } from 'react-icons/fa';
@@ -7,7 +7,7 @@ import {
Navigation, Navigation,
ProgressBar, ProgressBar,
SteamSpinner, SteamSpinner,
} from 'decky-frontend-lib'; } from '@decky/ui';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { FaDownload, FaInfo } from 'react-icons/fa'; import { FaDownload, FaInfo } from 'react-icons/fa';
+1 -8
View File
@@ -1,11 +1,4 @@
import { import { ButtonItem, Dropdown, Focusable, PanelSectionRow, SingleDropdownOption, SuspensefulImage } from '@decky/ui';
ButtonItem,
Dropdown,
Focusable,
PanelSectionRow,
SingleDropdownOption,
SuspensefulImage,
} from 'decky-frontend-lib';
import { CSSProperties, FC, useState } from 'react'; import { CSSProperties, FC, useState } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
+1 -1
View File
@@ -7,7 +7,7 @@ import {
Tabs, Tabs,
TextField, TextField,
findModule, findModule,
} from 'decky-frontend-lib'; } from '@decky/ui';
import { Dispatch, FC, SetStateAction, useEffect, useMemo, useState } from 'react'; import { Dispatch, FC, SetStateAction, useEffect, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
+1 -1
View File
@@ -1,4 +1,4 @@
import { sleep } from 'decky-frontend-lib'; import { sleep } from '@decky/ui';
import { FaReact } from 'react-icons/fa'; import { FaReact } from 'react-icons/fa';
import Logger from './logger'; import Logger from './logger';
+2 -2
View File
@@ -1,7 +1,7 @@
// Sets up DFL, then loads start.ts which starts up the loader // Sets up DFL, then loads start.ts which starts up the loader
(async () => { (async () => {
console.debug('Setting up decky-frontend-lib...'); console.debug('Setting up @decky/ui...');
window.DFL = await import('decky-frontend-lib'); window.DFL = await import('@decky/ui');
console.debug('Authenticating with Decky backend...'); console.debug('Authenticating with Decky backend...');
window.deckyAuthToken = await fetch('http://127.0.0.1:1337/auth/token').then((r) => r.text()); window.deckyAuthToken = await fetch('http://127.0.0.1:1337/auth/token').then((r) => r.text());
console.debug('Connecting to Decky backend...'); console.debug('Connecting to Decky backend...');
+1 -1
View File
@@ -8,7 +8,7 @@ import {
quickAccessMenuClasses, quickAccessMenuClasses,
showModal, showModal,
sleep, sleep,
} from 'decky-frontend-lib'; } from '@decky/ui';
import { FC, lazy } from 'react'; import { FC, lazy } from 'react';
import { FaExclamationCircle, FaPlug } from 'react-icons/fa'; import { FaExclamationCircle, FaPlug } from 'react-icons/fa';
+4 -8
View File
@@ -1,4 +1,4 @@
import { Patch, afterPatch, findModuleChild } from 'decky-frontend-lib'; import { Export, Patch, afterPatch, findModuleExport } from '@decky/ui';
import { FC, ReactElement, ReactNode, cloneElement, createElement, memo } from 'react'; import { FC, ReactElement, ReactNode, cloneElement, createElement, memo } from 'react';
import type { Route } from 'react-router'; import type { Route } from 'react-router';
@@ -41,13 +41,9 @@ class RouterHook extends Logger {
window.__ROUTER_HOOK_INSTANCE?.deinit?.(); window.__ROUTER_HOOK_INSTANCE?.deinit?.();
window.__ROUTER_HOOK_INSTANCE = this; window.__ROUTER_HOOK_INSTANCE = this;
this.gamepadWrapper = findModuleChild((m) => { this.gamepadWrapper = findModuleExport((e: Export) =>
if (typeof m !== 'object') return undefined; e?.render?.toString()?.includes('["flow-children","onActivate","onCancel","focusClassName",'),
for (let prop in m) { );
if (m[prop]?.render?.toString()?.includes('["flow-children","onActivate","onCancel","focusClassName",'))
return m[prop];
}
});
let Route: new () => Route; let Route: new () => Route;
// Used to store the new replicated routes we create to allow routes to be unpatched. // Used to store the new replicated routes we create to allow routes to be unpatched.
+1 -1
View File
@@ -1,4 +1,4 @@
import { getFocusNavController, sleep } from 'decky-frontend-lib'; import { getFocusNavController, sleep } from '@decky/ui';
import Logger from '../logger'; import Logger from '../logger';
+2 -7
View File
@@ -1,4 +1,4 @@
import { Patch, findModuleChild, replacePatch, sleep } from 'decky-frontend-lib'; import { Export, Patch, findModuleExport, replacePatch, sleep } from '@decky/ui';
import Logger from '../logger'; import Logger from '../logger';
@@ -18,12 +18,7 @@ export default async function restartFix() {
let History: any; let History: any;
while (!History) { while (!History) {
History = findModuleChild((m) => { History = findModuleExport((e: Export) => e.m_history)?.m_history;
if (typeof m !== 'object') return undefined;
for (let prop in m) {
if (m[prop]?.m_history) return m[prop].m_history;
}
});
if (!History) { if (!History) {
logger.debug('Waiting 5s for history to become available.'); logger.debug('Waiting 5s for history to become available.');
await sleep(5000); await sleep(5000);
+1 -1
View File
@@ -1,5 +1,5 @@
// TabsHook for versions after the Desktop merge // TabsHook for versions after the Desktop merge
import { Patch, QuickAccessTab, afterPatch, findInReactTree, getReactRoot, sleep } from 'decky-frontend-lib'; import { Patch, QuickAccessTab, afterPatch, findInReactTree, getReactRoot, sleep } from '@decky/ui';
import { QuickAccessVisibleStateProvider } from './components/QuickAccessVisibleState'; import { QuickAccessVisibleStateProvider } from './components/QuickAccessVisibleState';
import Logger from './logger'; import Logger from './logger';
+4 -13
View File
@@ -1,14 +1,14 @@
import { import {
Module, Export,
Patch, Patch,
ToastData, ToastData,
afterPatch, afterPatch,
findClass, findClass,
findInReactTree, findInReactTree,
findModuleChild, findModuleExport,
getReactRoot, getReactRoot,
sleep, sleep,
} from 'decky-frontend-lib'; } from '@decky/ui';
import { ReactNode } from 'react'; import { ReactNode } from 'react';
import Toast from './components/Toast'; import Toast from './components/Toast';
@@ -150,16 +150,7 @@ class Toaster extends Logger {
this.rNode.stateNode.forceUpdate(); this.rNode.stateNode.forceUpdate();
delete this.rNode.stateNode.shouldComponentUpdate; delete this.rNode.stateNode.shouldComponentUpdate;
this.audioModule = findModuleChild((m: Module) => { this.audioModule = findModuleExport((e: Export) => e.PlayNavSound && e.RegisterCallbackOnPlaySound);
if (typeof m !== 'object') return undefined;
for (let prop in m) {
try {
if (m[prop].PlayNavSound && m[prop].RegisterCallbackOnPlaySound) return m[prop];
} catch {
return undefined;
}
}
});
this.log('Initialized'); this.log('Initialized');
this.finishStartup?.(); this.finishStartup?.();
+1 -1
View File
@@ -1,4 +1,4 @@
import { sleep } from 'decky-frontend-lib'; import { sleep } from '@decky/ui';
import Logger from './logger'; import Logger from './logger';