From 94a86b93ad6296524a005b942eb424654f245255 Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Fri, 12 Feb 2021 02:16:09 -0500 Subject: [PATCH] Better tracking of loginRunning/Cancelled --- puppet/src/puppet.js | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/puppet/src/puppet.js b/puppet/src/puppet.js index 0570477..b62c4ac 100644 --- a/puppet/src/puppet.js +++ b/puppet/src/puppet.js @@ -126,7 +126,6 @@ export default class MessagesPuppeteer { return } this.loginRunning = true - this.loginCancelled = false const loginContentArea = await this.page.waitForSelector("#login_content") @@ -226,17 +225,21 @@ export default class MessagesPuppeteer { } this.log("Waiting for sync") - await this.page.waitForFunction( - messageSyncElement => { - const text = messageSyncElement.innerText - return text == 'Syncing messages... 100%' - }, - {}, - result) + try { + await this.page.waitForFunction( + messageSyncElement => { + const text = messageSyncElement.innerText + return text == 'Syncing messages... 100%' + }, + {}, + result) - await this.startObserving() - this.loginRunning = false - this.log("Login complete") + this.loginRunning = false + await this.startObserving() + this.log("Login complete") + } catch (err) { + this._sendLoginFailure(`Failed to sync: ${err}`) + } } /** @@ -244,6 +247,7 @@ export default class MessagesPuppeteer { */ async cancelLogin() { if (this.loginRunning) { + this.loginRunning = false this.loginCancelled = true await this._preparePage(false) } @@ -252,6 +256,7 @@ export default class MessagesPuppeteer { _waitForLoginCancel() { return new Promise((resolve, reject) => { if (this.loginCancelled) { + this.loginCancelled = false resolve() } else { reject() @@ -523,6 +528,7 @@ export default class MessagesPuppeteer { } _sendLoginFailure(reason) { + this.loginRunning = false this.error(`Login failure: ${reason ? reason : 'cancelled'}`) if (this.client) { this.client.sendFailure(reason).catch(err =>