From 00e9515e8a40db3d946cf90f6154950ee839f0c2 Mon Sep 17 00:00:00 2001 From: mila2999 Date: Wed, 9 Oct 2024 21:49:24 +0300 Subject: [PATCH 1/3] Added a Prefix to the watchdog #490 --- src/commands.ts | 12 ++++++------ src/peerbook.ts | 2 +- src/shell.ts | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/commands.ts b/src/commands.ts index f66027be..eff0e2d0 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -241,7 +241,7 @@ async function connectCMD(shell:Shell, args: string[]) { const firstGate = (await Preferences.get({key: "first_gate"})).value const timeout = (firstGate == "nope") ? undefined : 10000 - shell.startWatchdog(timeout).catch(e => gate.handleFailure(e)) + shell.startWatchdog({ timeout }).catch(e => gate.handleFailure(e)) if (terminal7.activeG && !terminal7.isActive(gate)) { terminal7.activeG.stopBoarding() terminal7.activeG.blur() @@ -638,7 +638,7 @@ async function subscribeCMD(shell: Shell) { return if (choice == "Restore Purchases") { shell.t.writeln("Restoring purchases") - shell.startWatchdog(10000).catch(e => { + shell.startWatchdog({ timeout: 10000 }).catch(e => { shell.t.writeln("Sorry, restore command timed out") shell.t.writeln("Please try again or `support`") throw e @@ -661,7 +661,7 @@ async function subscribeCMD(shell: Shell) { } else { const p = packages.find(p => p.prompt == choice) shell.t.writeln("Thank you ๐Ÿ™ directing you to the store") - shell.startWatchdog(120000).catch(e => { + shell.startWatchdog({ timeout : 120000 }).catch(e => { shell.t.writeln("Sorry, subscribe command timed out") shell.t.writeln("Please try again or `support`") throw e @@ -939,7 +939,7 @@ export async function installCMD(shell: Shell, args: string[]) { if (done) { // wait for the gate to get an fp let timedOut = false - shell.startWatchdog(terminal7.conf.net.timeout) + shell.startWatchdog({ timeout: terminal7.conf.net.timeout }) .catch(() => timedOut = true) while (!gate.fp && ! timedOut) await (new Promise(r => setTimeout(r, 100))) @@ -1002,7 +1002,7 @@ async function supportCMD(shell: Shell) { let description = await shell.askValue("Please explain how to recreate the issue: \n") description += `\n\nOn: ${navigator.userAgent}\n` shell.t.writeln("Sending...") - shell.startWatchdog(5000).catch(() => sendFailed()) + shell.startWatchdog({ timeout: 5000 }).catch(() => sendFailed()) const res = await fetch(`${schema}://${terminal7.conf.net.peerbook}/support`, { method: "POST", body: JSON.stringify({ @@ -1081,7 +1081,7 @@ async function loginCMD(shell: Shell) { } shell.t.writeln(`PeerBook response: ${await res.text()}`) let timedOut = false - shell.startWatchdog(180000).catch(() => timedOut = true) + shell.startWatchdog({ timeout: 180000 }).catch(() => timedOut = true) while (!terminal7.pb.uid && !timedOut) { await new Promise(r => setTimeout(r, 2000)) try { diff --git a/src/peerbook.ts b/src/peerbook.ts index 550313cd..024b5745 100644 --- a/src/peerbook.ts +++ b/src/peerbook.ts @@ -171,7 +171,7 @@ export class PeerbookConnection { this.echo("and use it to generate a One Time Password") // verify ourselves - it's the first time and we were approved thanks // to the revenuecat's user id - this.shell.startWatchdog(3000).catch(() => { + this.shell.startWatchdog({ timeout: 3000 }).catch(() => { this.shell.t.writeln("Timed out waiting for OTP") this.shell.printPrompt() }) diff --git a/src/shell.ts b/src/shell.ts index 69706dd9..2fdc812a 100644 --- a/src/shell.ts +++ b/src/shell.ts @@ -306,7 +306,7 @@ export class Shell { /* * Starts a watchdog that will reject if not stopped within the given time */ - startWatchdog(timeout? : number): Promise { + startWatchdog({ timeout, prefix = 'Waiting' }: { timeout?: number; prefix?: string } = {} ): Promise { if (!timeout) timeout = terminal7.conf.net.timeout // only one watchdog, the last one @@ -316,7 +316,7 @@ export class Shell { this.watchdogResolve = resolve this.startHourglass(timeout) this.watchdog = terminal7.run(() => { - terminal7.log("shell watchdog timeout") + terminal7.log(`${prefix} shell watchdog timeout`) this.stopWatchdog() reject(Failure.TimedOut) }, timeout) From 248ef7e65a59c1911d2c8439cf32eca25eb4d336 Mon Sep 17 00:00:00 2001 From: mila2999 Date: Thu, 24 Oct 2024 19:41:12 +0300 Subject: [PATCH 2/3] added prefix to the startHourglass --- src/shell.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/shell.ts b/src/shell.ts index 2fdc812a..6d3ead29 100644 --- a/src/shell.ts +++ b/src/shell.ts @@ -314,9 +314,9 @@ export class Shell { this.stopWatchdog() return new Promise((resolve, reject) => { this.watchdogResolve = resolve - this.startHourglass(timeout) + this.startHourglass({timeout , prefix}) this.watchdog = terminal7.run(() => { - terminal7.log(`${prefix} shell watchdog timeout`) + terminal7.log(`shell watchdog timeout`) this.stopWatchdog() reject(Failure.TimedOut) }, timeout) @@ -336,7 +336,7 @@ export class Shell { this.printPrompt() } - startHourglass(timeout: number) { + startHourglass({ timeout, prefix = 'Waiting' } : { timeout: number; prefix?: string } ) { if (this.timer) return this.map.showLog(true) const len = 20, @@ -344,7 +344,7 @@ export class Shell { let i = 0 this.timer = window.setInterval(() => { const dots = Math.max(0, len - i) // i should never be > len, but just in case - this.t.write(`\r\x1B[K${" ".repeat(i)}แ—ง${"ยท".repeat(dots)}๐Ÿ’\x1B[?25l`) + this.t.write(`\r\x1B[K${prefix}${" ".repeat(i)}แ—ง${"ยท".repeat(dots)}๐Ÿ’\x1B[?25l`) i++ }, interval) } From 4c72df545305fa66c494c72b4b51afb2aa2cf82e Mon Sep 17 00:00:00 2001 From: mila2999 Date: Thu, 24 Oct 2024 19:47:13 +0300 Subject: [PATCH 3/3] changed timeout to optional --- src/shell.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shell.ts b/src/shell.ts index 6d3ead29..b734cf79 100644 --- a/src/shell.ts +++ b/src/shell.ts @@ -336,7 +336,7 @@ export class Shell { this.printPrompt() } - startHourglass({ timeout, prefix = 'Waiting' } : { timeout: number; prefix?: string } ) { + startHourglass({ timeout, prefix = 'Waiting' } : { timeout?: number; prefix?: string } ) { if (this.timer) return this.map.showLog(true) const len = 20,