From c4d6731401d3b6dc111a74d086df28704473070d Mon Sep 17 00:00:00 2001 From: AAGaming Date: Sat, 17 Sep 2022 23:23:51 -0400 Subject: fix updater for new installs, fix file picker patch, fix scrolling on patch notes, fix tasks dir --- frontend/src/components/Markdown.tsx | 39 ++++++++++++++++++++-- frontend/src/components/WithSuspense.tsx | 16 ++++++--- .../src/components/modals/filepicker/index.tsx | 5 +-- .../modals/filepicker/patches/library.ts | 35 +++++++++++++------ .../components/settings/pages/general/Updater.tsx | 15 ++++----- frontend/src/plugin-loader.tsx | 14 ++++++-- 6 files changed, 92 insertions(+), 32 deletions(-) (limited to 'frontend/src') diff --git a/frontend/src/components/Markdown.tsx b/frontend/src/components/Markdown.tsx index 7b187f14..cefced91 100644 --- a/frontend/src/components/Markdown.tsx +++ b/frontend/src/components/Markdown.tsx @@ -1,9 +1,42 @@ -import { FunctionComponent } from 'react'; +import { Focusable } from 'decky-frontend-lib'; +import { FunctionComponent, useRef } from 'react'; import ReactMarkdown, { Options as ReactMarkdownOptions } from 'react-markdown'; import remarkGfm from 'remark-gfm'; -const Markdown: FunctionComponent = (props) => { - return ; +interface MarkdownProps extends ReactMarkdownOptions { + onDismiss?: () => void; +} + +const Markdown: FunctionComponent = (props) => { + return ( + + {nodeProps.children}, + a: (nodeProps) => { + console.log(nodeProps.node, nodeProps); + const aRef = useRef(null); + return ( + // TODO fix focus ring + {}} + onOKButton={() => { + aRef?.current?.click(); + props.onDismiss?.(); + }} + > + + {nodeProps.children} + + + ); + }, + }} + {...props} + /> + + ); }; export default Markdown; diff --git a/frontend/src/components/WithSuspense.tsx b/frontend/src/components/WithSuspense.tsx index 7460aa3d..402f5e5b 100644 --- a/frontend/src/components/WithSuspense.tsx +++ b/frontend/src/components/WithSuspense.tsx @@ -1,8 +1,9 @@ -import { SteamSpinner } from 'decky-frontend-lib'; +import { Focusable, SteamSpinner } from 'decky-frontend-lib'; import { FunctionComponent, ReactElement, ReactNode, Suspense } from 'react'; interface WithSuspenseProps { children: ReactNode; + route?: boolean; } // Nice little wrapper around Suspense so we don't have to duplicate the styles and code for the loading spinner @@ -13,15 +14,20 @@ const WithSuspense: FunctionComponent = (props) => { return ( {}} style={{ - marginTop: '40px', - height: 'calc( 100% - 40px )', overflowY: 'scroll', + backgroundColor: 'transparent', + ...(props.route && { + marginTop: '40px', + height: 'calc( 100% - 40px )', + }), }} > - + } > {props.children} diff --git a/frontend/src/components/modals/filepicker/index.tsx b/frontend/src/components/modals/filepicker/index.tsx index 0847bd14..dcf179a3 100644 --- a/frontend/src/components/modals/filepicker/index.tsx +++ b/frontend/src/components/modals/filepicker/index.tsx @@ -86,7 +86,8 @@ const FilePicker: FunctionComponent = ({ onClick={() => { const newPathArr = path.split('/'); newPathArr.pop(); - const newPath = newPathArr.join('/'); + let newPath = newPathArr.join('/'); + if (newPath == '') newPath = '/'; setPath(newPath); }} > @@ -113,7 +114,7 @@ const FilePicker: FunctionComponent = ({ { - const fullPath = `${path}/${file.name}`; + const fullPath = `${path}${path.endsWith('/') ? '' : '/'}${file.name}`; if (file.isdir) setPath(fullPath); else { onSubmit({ path: fullPath, realpath: file.realpath }); diff --git a/frontend/src/components/modals/filepicker/patches/library.ts b/frontend/src/components/modals/filepicker/patches/library.ts index 7ba977a5..c9c7d53c 100644 --- a/frontend/src/components/modals/filepicker/patches/library.ts +++ b/frontend/src/components/modals/filepicker/patches/library.ts @@ -1,4 +1,4 @@ -import { Patch, replacePatch, sleep } from 'decky-frontend-lib'; +import { Patch, findModuleChild, replacePatch } from 'decky-frontend-lib'; declare global { interface Window { @@ -10,8 +10,7 @@ declare global { let patch: Patch; function rePatch() { - // If you patch anything on SteamClient within the first few seconds of the client having loaded it will get redefined for some reason, so repatch any of these changes that occur within the first minute of the client loading - patch?.unpatch(); + // If you patch anything on SteamClient within the first few seconds of the client having loaded it will get redefined for some reason, so repatch any of these changes that occur within the first 20s of the last patch patch = replacePatch(window.SteamClient.Apps, 'PromptToChangeShortcut', async ([appid]: number[]) => { try { const details = window.appDetailsStore.GetAppDetails(appid); @@ -30,13 +29,29 @@ function rePatch() { }); } +// TODO type and add to frontend-lib +const History = findModuleChild((m) => { + if (typeof m !== 'object') return undefined; + for (let prop in m) { + if (m[prop]?.m_history) return m[prop].m_history; + } +}); + export default async function libraryPatch() { - await sleep(10000); - rePatch(); - await sleep(10000); - rePatch(); + try { + rePatch(); + const unlisten = History.listen(() => { + if (window.SteamClient.Apps.PromptToChangeShortcut !== patch.patchedFunction) { + rePatch(); + } + }); - return () => { - patch.unpatch(); - }; + return () => { + patch.unpatch(); + unlisten(); + }; + } catch (e) { + console.error('Error patching library file picker', e); + } + return () => {}; } diff --git a/frontend/src/components/settings/pages/general/Updater.tsx b/frontend/src/components/settings/pages/general/Updater.tsx index 7056ed13..ce859de7 100644 --- a/frontend/src/components/settings/pages/general/Updater.tsx +++ b/frontend/src/components/settings/pages/general/Updater.tsx @@ -7,19 +7,16 @@ import { FaArrowDown } from 'react-icons/fa'; import { VerInfo, callUpdaterMethod, finishUpdate } from '../../../../updater'; import { useDeckyState } from '../../../DeckyState'; import InlinePatchNotes from '../../../patchnotes/InlinePatchNotes'; +import WithSuspense from '../../../WithSuspense'; const MarkdownRenderer = lazy(() => import('../../../Markdown')); -// import ReactMarkdown from 'react-markdown' -// import remarkGfm from 'remark-gfm' - function PatchNotesModal({ versionInfo, closeModal }: { versionInfo: VerInfo | null; closeModal?: () => {} }) { return ( ( {}} style={{ marginTop: '40px', height: 'calc( 100% - 40px )', @@ -32,9 +29,9 @@ function PatchNotesModal({ versionInfo, closeModal }: { versionInfo: VerInfo | n

{versionInfo?.all?.[id]?.name}

{versionInfo?.all?.[id]?.body ? ( - }> - {versionInfo.all[id].body} - + + {versionInfo.all[id].body} + ) : ( 'no patch notes for this version' )} @@ -43,8 +40,8 @@ function PatchNotesModal({ versionInfo, closeModal }: { versionInfo: VerInfo | n )} fnGetId={(id) => id} nNumItems={versionInfo?.all?.length} - nHeight={window.innerHeight - 150} - nItemHeight={window.innerHeight - 200} + nHeight={window.innerHeight - 40} + nItemHeight={window.innerHeight - 40} nItemMarginX={0} initialColumn={0} autoFocus={true} diff --git a/frontend/src/plugin-loader.tsx b/frontend/src/plugin-loader.tsx index 493e5935..a17969a7 100644 --- a/frontend/src/plugin-loader.tsx +++ b/frontend/src/plugin-loader.tsx @@ -66,14 +66,14 @@ class PluginLoader extends Logger { }); this.routerHook.addRoute('/decky/store', () => ( - + )); this.routerHook.addRoute('/decky/settings', () => { return ( - + @@ -81,11 +81,19 @@ class PluginLoader extends Logger { }); initFilepickerPatches(); + + this.updateVersion(); } - public async notifyUpdates() { + public async updateVersion() { const versionInfo = (await callUpdaterMethod('get_version')).result as VerInfo; this.deckyState.setVersionInfo(versionInfo); + + return versionInfo; + } + + public async notifyUpdates() { + const versionInfo = await this.updateVersion(); if (versionInfo?.remote && versionInfo?.remote?.tag_name != versionInfo?.current) { this.toaster.toast({ title: 'Decky', -- cgit v1.2.3