mirror of
https://github.com/samuelthomas2774/nxapi.git
synced 2026-07-07 21:04:14 -05:00
Use show error alerts preference for SplatNet 3 presence monitoring
This commit is contained in:
parent
05b254e69c
commit
7a2fe3d35c
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -148,5 +148,6 @@ export interface ExternalMonitor<T = unknown> extends EmbeddedLoop {
|
|||
export enum ErrorResult {
|
||||
STOP,
|
||||
RETRY,
|
||||
DEFER,
|
||||
IGNORE,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user