handle crashloops and disable decky for the user

This commit is contained in:
AAGaming
2024-08-07 16:14:18 -04:00
parent 166c7ea8a7
commit 65b6883dcc
8 changed files with 269 additions and 53 deletions
+30 -1
View File
@@ -172,11 +172,32 @@ class PluginLoader extends Logger {
.then(() => this.log('Initialized'));
}
private checkForSP(): boolean {
try {
return !!findSP();
} catch (e) {
this.warn('Error checking for SP tab', e);
return false;
}
}
private async runCrashChecker() {
const spExists = this.checkForSP();
await sleep(5000);
if (spExists && !this.checkForSP()) {
// SP died after plugin loaded. Give up and let the loader's crash loop detection handle it.
this.error('SP died during startup. Restarting webhelper.');
await this.restartWebhelper();
}
}
private getPluginsFromBackend = DeckyBackend.callable<
[],
{ name: string; version: string; load_type: PluginLoadType }[]
>('loader/get_plugins');
private restartWebhelper = DeckyBackend.callable<[], void>('utilities/restart_webhelper');
private async loadPlugins() {
let registration: any;
const uiMode = await new Promise(
@@ -192,6 +213,7 @@ class PluginLoader extends Logger {
await sleep(100);
}
}
this.runCrashChecker();
const plugins = await this.getPluginsFromBackend();
const pluginLoadPromises = [];
const loadStart = performance.now();
@@ -395,6 +417,7 @@ class PluginLoader extends Logger {
version?: string,
loadType: PluginLoadType = PluginLoadType.ESMODULE_V1,
) {
let spExists = this.checkForSP();
try {
switch (loadType) {
case PluginLoadType.ESMODULE_V1:
@@ -442,7 +465,7 @@ class PluginLoader extends Logger {
</PanelSectionRow>
<PanelSectionRow>
<pre style={{ overflowX: 'scroll' }}>
<code>{e instanceof Error ? e.stack : JSON.stringify(e)}</code>
<code>{e instanceof Error ? '' + e.stack : JSON.stringify(e)}</code>
</pre>
</PanelSectionRow>
<PanelSectionRow>
@@ -474,6 +497,12 @@ class PluginLoader extends Logger {
icon: <FaExclamationCircle />,
});
}
if (spExists && !this.checkForSP()) {
// SP died after plugin loaded. Give up and let the loader's crash loop detection handle it.
this.error('SP died after loading plugin. Restarting webhelper.');
await this.restartWebhelper();
}
}
async callServerMethod(methodName: string, args = {}) {