Fix game callbacks not activating correctly, fix UI not updating correctly when new config loaded
This commit is contained in:
parent
310af1b3ae
commit
9e1f7c0620
1 changed files with 40 additions and 11 deletions
|
@ -77,6 +77,8 @@ var startHook: any = null;
|
||||||
var endHook: any = null;
|
var endHook: any = null;
|
||||||
var usdplReady = false;
|
var usdplReady = false;
|
||||||
|
|
||||||
|
var tryNotifyProfileChange = function() {};
|
||||||
|
|
||||||
type MinMax = {
|
type MinMax = {
|
||||||
min: number | null;
|
min: number | null;
|
||||||
max: number | null;
|
max: number | null;
|
||||||
|
@ -170,7 +172,7 @@ const clearHooks = function() {
|
||||||
startHook?.unregister();
|
startHook?.unregister();
|
||||||
endHook?.unregister();
|
endHook?.unregister();
|
||||||
|
|
||||||
backend.log(backend.LogLevel.Debug, "Unregistered PowerTools callbacks, so long and thanks for all the fish.");
|
backend.log(backend.LogLevel.Info, "Unregistered PowerTools callbacks, so long and thanks for all the fish.");
|
||||||
};
|
};
|
||||||
|
|
||||||
const registerCallbacks = function(autoclear: boolean) {
|
const registerCallbacks = function(autoclear: boolean) {
|
||||||
|
@ -185,9 +187,14 @@ const registerCallbacks = function(autoclear: boolean) {
|
||||||
//backend.log(backend.LogLevel.Debug, "AppID " + update.unAppID.toString() + " is now running");
|
//backend.log(backend.LogLevel.Debug, "AppID " + update.unAppID.toString() + " is now running");
|
||||||
} else {
|
} else {
|
||||||
//backend.log(backend.LogLevel.Debug, "AppID " + update.unAppID.toString() + " is no longer running");
|
//backend.log(backend.LogLevel.Debug, "AppID " + update.unAppID.toString() + " is no longer running");
|
||||||
backend.resolve(
|
backend.resolve(backend.loadGeneralDefaultSettings(), (ok: boolean) => {
|
||||||
backend.loadGeneralDefaultSettings(),
|
backend.log(backend.LogLevel.Debug, "Loading default settings ok? " + ok);
|
||||||
(ok: boolean) => {backend.log(backend.LogLevel.Debug, "Loading default settings ok? " + ok)}
|
reload();
|
||||||
|
backend.resolve(backend.waitForComplete(), (_) => {
|
||||||
|
backend.log(backend.LogLevel.Debug, "Trying to tell UI to re-render due to game exit");
|
||||||
|
tryNotifyProfileChange();
|
||||||
|
});
|
||||||
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -200,12 +207,26 @@ const registerCallbacks = function(autoclear: boolean) {
|
||||||
// don't use gameInfo.appid, haha
|
// don't use gameInfo.appid, haha
|
||||||
backend.resolve(
|
backend.resolve(
|
||||||
backend.loadGeneralSettings(id.toString(), gameInfo.display_name, 0, undefined),
|
backend.loadGeneralSettings(id.toString(), gameInfo.display_name, 0, undefined),
|
||||||
(ok: boolean) => {backend.log(backend.LogLevel.Debug, "Loading settings ok? " + ok)}
|
(ok: boolean) => {
|
||||||
|
backend.log(backend.LogLevel.Debug, "Loading settings ok? " + ok);
|
||||||
|
reload();
|
||||||
|
backend.resolve(backend.waitForComplete(), (_) => {
|
||||||
|
backend.log(backend.LogLevel.Debug, "Trying to tell UI to re-render due to new game launch");
|
||||||
|
tryNotifyProfileChange();
|
||||||
|
});
|
||||||
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// this fires immediately, so let's ignore that callback
|
||||||
|
let hasFiredImmediately = false;
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
endHook = SteamClient.Apps.RegisterForGameActionEnd((actionType) => {
|
endHook = SteamClient.Apps.RegisterForGameActionEnd((actionType) => {
|
||||||
|
if (!hasFiredImmediately) {
|
||||||
|
hasFiredImmediately = true;
|
||||||
|
backend.log(backend.LogLevel.Debug, "RegisterForGameActionEnd immediately fired callback(" + actionType + ")");
|
||||||
|
return;
|
||||||
|
}
|
||||||
backend.log(backend.LogLevel.Info, "RegisterForGameActionEnd callback(" + actionType + ")");
|
backend.log(backend.LogLevel.Info, "RegisterForGameActionEnd callback(" + actionType + ")");
|
||||||
setTimeout(() => backend.forceApplySettings(), AUTOMATIC_REAPPLY_WAIT);
|
setTimeout(() => backend.forceApplySettings(), AUTOMATIC_REAPPLY_WAIT);
|
||||||
});
|
});
|
||||||
|
@ -233,16 +254,13 @@ const periodicals = function() {
|
||||||
const oldValue = get_value(PATH_GEN);
|
const oldValue = get_value(PATH_GEN);
|
||||||
set_value(PATH_GEN, path);
|
set_value(PATH_GEN, path);
|
||||||
if (path != oldValue) {
|
if (path != oldValue) {
|
||||||
backend.log(backend.LogLevel.Info, "Frontend values reload triggered by path change: " + oldValue + " -> " + path);
|
backend.log(backend.LogLevel.Debug, "Frontend values reload triggered by path change: " + oldValue + " -> " + path);
|
||||||
reload();
|
reload();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
const Content: VFC<{ serverAPI: ServerAPI }> = ({}) => {
|
const periodicalsSetup = function(reloadGUI: (s: string) => void) {
|
||||||
|
|
||||||
const [idc, reloadGUI] = useState<any>("/shrug");
|
|
||||||
|
|
||||||
if (periodicHook != null) {
|
if (periodicHook != null) {
|
||||||
clearInterval(periodicHook);
|
clearInterval(periodicHook);
|
||||||
periodicHook = null;
|
periodicHook = null;
|
||||||
|
@ -252,6 +270,14 @@ const Content: VFC<{ serverAPI: ServerAPI }> = ({}) => {
|
||||||
periodicals();
|
periodicals();
|
||||||
reloadGUI("periodic" + (new Date()).getTime().toString());
|
reloadGUI("periodic" + (new Date()).getTime().toString());
|
||||||
}, PERIODICAL_BACKEND_PERIOD);
|
}, PERIODICAL_BACKEND_PERIOD);
|
||||||
|
};
|
||||||
|
|
||||||
|
const Content: VFC<{ serverAPI: ServerAPI }> = ({}) => {
|
||||||
|
|
||||||
|
const [idc, reloadGUI] = useState<any>("/shrug");
|
||||||
|
tryNotifyProfileChange = function() { reloadGUI("ProfileChangeByNotification") };
|
||||||
|
|
||||||
|
periodicalsSetup(reloadGUI);
|
||||||
|
|
||||||
if (!usdplReady || !get_value(LIMITS_INFO)) {
|
if (!usdplReady || !get_value(LIMITS_INFO)) {
|
||||||
// Not translated on purpose (to avoid USDPL issues)
|
// Not translated on purpose (to avoid USDPL issues)
|
||||||
|
@ -263,6 +289,8 @@ const Content: VFC<{ serverAPI: ServerAPI }> = ({}) => {
|
||||||
onClick={(_: MouseEvent) => {
|
onClick={(_: MouseEvent) => {
|
||||||
console.log("POWERTOOLS: manual reload after startup failure");
|
console.log("POWERTOOLS: manual reload after startup failure");
|
||||||
reload();
|
reload();
|
||||||
|
// try to reload GUI too
|
||||||
|
backend.resolve(backend.waitForComplete(), (_) => {reloadGUI("LoadSystemDefaults")});
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Reload
|
Reload
|
||||||
|
@ -351,7 +379,7 @@ export default definePlugin((serverApi: ServerAPI) => {
|
||||||
if (now.getDate() == 1 && now.getMonth() == 3) {
|
if (now.getDate() == 1 && now.getMonth() == 3) {
|
||||||
ico = <span><GiDynamite /><GiTimeTrap /><GiTimeBomb /></span>;
|
ico = <span><GiDynamite /><GiTimeTrap /><GiTimeBomb /></span>;
|
||||||
}
|
}
|
||||||
registerCallbacks(false);
|
//registerCallbacks(false);
|
||||||
return {
|
return {
|
||||||
title: <div className={staticClasses.Title}>PowerTools</div>,
|
title: <div className={staticClasses.Title}>PowerTools</div>,
|
||||||
content: <Content serverAPI={serverApi} />,
|
content: <Content serverAPI={serverApi} />,
|
||||||
|
@ -359,6 +387,7 @@ export default definePlugin((serverApi: ServerAPI) => {
|
||||||
onDismount() {
|
onDismount() {
|
||||||
backend.log(backend.LogLevel.Debug, "PowerTools shutting down");
|
backend.log(backend.LogLevel.Debug, "PowerTools shutting down");
|
||||||
clearHooks();
|
clearHooks();
|
||||||
|
tryNotifyProfileChange = function() {};
|
||||||
//serverApi.routerHook.removeRoute("/decky-plugin-test");
|
//serverApi.routerHook.removeRoute("/decky-plugin-test");
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue