Use show error alerts preference for SplatNet 3 presence monitoring

This commit is contained in:
Samuel Elliott 2025-08-17 21:41:11 +01:00
parent 05b254e69c
commit 7a2fe3d35c
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
4 changed files with 15 additions and 8 deletions

View File

@ -67,9 +67,11 @@ export class PresenceMonitorManager {
error: err,
buttons: ['OK', 'Retry', 'Stop'],
defaultId: 0,
app: this.app,
});
const show_error_alerts: boolean = await this.app.store.storage.getItem('ShowErrorAlertsPreference') ?? false;
if (!show_error_alerts) return ErrorResult.DEFER;
if (response === 1) {
return ErrorResult.RETRY;
}

View File

@ -91,6 +91,7 @@ export default class SplatNet3Monitor extends EmbeddedLoop {
debug('Error authenticating to SplatNet 3', err);
const result = await this.discord_presence.handleError(err as Error);
if (result === ErrorResult.RETRY) return this.init();
if (result === ErrorResult.DEFER) return this.errors++, LoopResult.DEFER_NEXT_UPDATE;
if (result === ErrorResult.STOP) return LoopResult.STOP;
}
@ -168,6 +169,7 @@ export default class SplatNet3Monitor extends EmbeddedLoop {
async handleError(err: Error) {
const result = await this.discord_presence.handleError(err as Error);
if (result === ErrorResult.RETRY) return LoopResult.OK_SKIP_INTERVAL;
if (result === ErrorResult.DEFER) return LoopResult.DEFER_NEXT_UPDATE;
this.friend = null;
this.discord_presence.refreshPresence();

View File

@ -148,5 +148,6 @@ export interface ExternalMonitor<T = unknown> extends EmbeddedLoop {
export enum ErrorResult {
STOP,
RETRY,
DEFER,
IGNORE,
}

View File

@ -52,6 +52,7 @@ export default abstract class Loop {
} else {
await new Promise(rs => setTimeout(this.timeout_resolve = rs, this.next_update_interval * 1000));
}
return LoopResult.DEFER_NEXT_UPDATE;
}
if (result === LoopResult.STOP) {
return LoopResult.STOP;
@ -109,25 +110,26 @@ export abstract class EmbeddedLoop extends Loop {
private async _run() {
this._running++;
const i = this._running;
let init = true;
try {
const result = await this.loop(true);
if (result === LoopResult.STOP) return;
while (i === this._running) {
const result = await this.loop();
const result = await this.loop(init);
if (init && result !== LoopResult.DEFER_NEXT_UPDATE) {
init = false;
}
if (result === LoopResult.STOP) {
await this.onStop?.();
if (!init) await this.onStop?.();
return;
}
}
if (this._running === 0 && !this.onStop) {
if (this._running === 0 && !init && !this.onStop) {
// Run one more time after the loop ends
const result = await this.loopRun();
}
} finally {
this._running = 0;
}