Skip to content

Commit

Permalink
Merge pull request #47 from FrogTheFrog/main
Browse files Browse the repository at this point in the history
Add sanity check when patching route
  • Loading branch information
OMGDuke authored Feb 18, 2023
2 parents 748f3d6 + 5a90523 commit 9a10d12
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 29 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"typescript": "^4.8.4"
},
"dependencies": {
"decky-frontend-lib": "^3.6.1",
"decky-frontend-lib": "^3.18.10",
"localforage": "^1.10.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
11 changes: 5 additions & 6 deletions pnpm-lock.yaml

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

4 changes: 2 additions & 2 deletions src/components/protonMedal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Router, ServerAPI } from 'decky-frontend-lib'
import { Navigation, ServerAPI } from 'decky-frontend-lib'
import { ReactElement, FC, CSSProperties, ReactNode } from 'react'
import { FaReact } from 'react-icons/fa'
import { IoLogoTux } from 'react-icons/io'
Expand Down Expand Up @@ -60,7 +60,7 @@ export default function ProtonMedal({
type="button"
onClick={async () => {
refresh()
Router.NavigateToExternalWeb(`https://www.protondb.com/app/${appId}`)
Navigation.NavigateToExternalWeb(`https://www.protondb.com/app/${appId}`)
}}
style={{
...positonSettings[state.position]
Expand Down
59 changes: 39 additions & 20 deletions src/lib/patchLibraryApp.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,58 @@
import { afterPatch, ServerAPI, wrapReactType } from 'decky-frontend-lib'
import {
afterPatch,
ServerAPI,
wrapReactType,
findInReactTree,
appDetailsClasses
} from 'decky-frontend-lib'
import { ReactElement } from 'react'
import ProtonMedal from '../components/protonMedal'
import { SettingsProvider } from '../context/settingsContext'

function patchLibraryApp(serverAPI: ServerAPI) {
return serverAPI.routerHook.addPatch(
'/library/app/:appid',
(props: { path: string; children: ReactElement }) => {
(props?: { path?: string; children?: ReactElement }) => {
if (!props?.children?.props?.renderFunc) {
return props
}

afterPatch(
props.children.props,
'renderFunc',
(_: Record<string, unknown>[], ret: ReactElement) => {
(_: Record<string, unknown>[], ret?: ReactElement) => {
if (!ret?.props?.children?.type?.type) {
return ret
}

wrapReactType(ret.props.children)
afterPatch(
ret.props.children.type,
'type',
(_2: Record<string, unknown>[], ret2: ReactElement) => {
const alreadySpliced = Boolean(
ret2.props?.children?.[1]?.props.children.props.children.find(
(child: ReactElement) =>
child?.props?.className === 'protondb-decky-indicator'
)
(_2: Record<string, unknown>[], ret2?: ReactElement) => {
const container = findInReactTree(
ret2,
(x: any) =>
Array.isArray(x?.props?.children) &&
x?.props?.className?.includes(
appDetailsClasses.InnerContainer
)
)
if (!alreadySpliced) {
ret2.props.children?.[1]?.props.children.props.children.splice(
1,
0,
<SettingsProvider>
<ProtonMedal
serverAPI={serverAPI}
className="protondb-decky-indicator"
/>
</SettingsProvider>
)
if (typeof container !== 'object') {
return ret2
}

container.props.children.splice(
1,
0,
<SettingsProvider>
<ProtonMedal
serverAPI={serverAPI}
className="protondb-decky-indicator"
/>
</SettingsProvider>
)

return ret2
}
)
Expand Down

0 comments on commit 9a10d12

Please sign in to comment.