summaryrefslogtreecommitdiff
path: root/frontend/src/components
diff options
context:
space:
mode:
authorAAGaming <aa@mail.catvibers.me>2022-12-29 23:46:47 -0500
committerAAGaming <aa@mail.catvibers.me>2022-12-29 23:46:47 -0500
commit81fbd0f83f11d5074bb945f0f6d7b6508e9d32d7 (patch)
tree903c9af9311afd82690ecf5b7577c9591cacc3cf /frontend/src/components
parent8810a014f3e1783c9b6c1ac2d1b83a0f5c38af10 (diff)
downloaddecky-loader-81fbd0f83f11d5074bb945f0f6d7b6508e9d32d7.tar.gz
decky-loader-81fbd0f83f11d5074bb945f0f6d7b6508e9d32d7.zip
Fix reloading UI on updates and restarting steam
Diffstat (limited to 'frontend/src/components')
-rw-r--r--frontend/src/components/modals/filepicker/patches/library.ts42
1 files changed, 27 insertions, 15 deletions
diff --git a/frontend/src/components/modals/filepicker/patches/library.ts b/frontend/src/components/modals/filepicker/patches/library.ts
index c9c7d53c..3abf824b 100644
--- a/frontend/src/components/modals/filepicker/patches/library.ts
+++ b/frontend/src/components/modals/filepicker/patches/library.ts
@@ -1,4 +1,8 @@
-import { Patch, findModuleChild, replacePatch } from 'decky-frontend-lib';
+import { Patch, findModuleChild, replacePatch, sleep } from 'decky-frontend-lib';
+
+import Logger from '../../../../logger';
+
+const logger = new Logger('LibraryPatch');
declare global {
interface Window {
@@ -10,36 +14,44 @@ 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 20s of the last patch
+ // 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 with History.listen or an interval
patch = replacePatch(window.SteamClient.Apps, 'PromptToChangeShortcut', async ([appid]: number[]) => {
try {
const details = window.appDetailsStore.GetAppDetails(appid);
- console.log(details);
+ logger.debug('game details', details);
// strShortcutStartDir
const file = await window.DeckyPluginLoader.openFilePicker(details.strShortcutStartDir.replaceAll('"', ''));
- console.log('user selected', file);
+ logger.debug('user selected', file);
window.SteamClient.Apps.SetShortcutExe(appid, JSON.stringify(file.path));
const pathArr = file.path.split('/');
pathArr.pop();
const folder = pathArr.join('/');
window.SteamClient.Apps.SetShortcutStartDir(appid, JSON.stringify(folder));
} catch (e) {
- console.error(e);
+ logger.error(e);
}
});
}
-// 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() {
try {
rePatch();
+ // TODO type and add to frontend-lib
+ let History: any;
+
+ while (!History) {
+ History = findModuleChild((m) => {
+ if (typeof m !== 'object') return undefined;
+ for (let prop in m) {
+ if (m[prop]?.m_history) return m[prop].m_history;
+ }
+ });
+ if (!History) {
+ logger.debug('Waiting 5s for history to become available.');
+ await sleep(5000);
+ }
+ }
+
const unlisten = History.listen(() => {
if (window.SteamClient.Apps.PromptToChangeShortcut !== patch.patchedFunction) {
rePatch();
@@ -47,11 +59,11 @@ export default async function libraryPatch() {
});
return () => {
- patch.unpatch();
unlisten();
+ patch.unpatch();
};
} catch (e) {
- console.error('Error patching library file picker', e);
+ logger.error('Error patching library file picker', e);
}
return () => {};
}