blob: 93fc08f70ea9aa3f93e07fc02b95d61fcbde9082 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
import { Patch, findModuleChild, replacePatch, sleep } from 'decky-frontend-lib';
import Logger from '../logger';
const logger = new Logger('RestartSteamFix');
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 with History.listen or an interval
patch = replacePatch(window.SteamClient.User, 'StartRestart', () => SteamClient.User.StartShutdown(false));
}
export default async function restartFix() {
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);
}
}
function repatchIfNeeded() {
if (window.SteamClient.User.StartRestart !== patch.patchedFunction) {
rePatch();
}
}
const unlisten = History.listen(repatchIfNeeded);
// Just in case
setTimeout(repatchIfNeeded, 5000);
setTimeout(repatchIfNeeded, 10000);
return () => {
unlisten();
patch.unpatch();
};
} catch (e) {
logger.error('Error patching StartRestart', e);
}
return () => {};
}
|