Better tracking of loginRunning/Cancelled
This commit is contained in:
parent
3a666a3fd4
commit
94a86b93ad
|
@ -126,7 +126,6 @@ export default class MessagesPuppeteer {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.loginRunning = true
|
this.loginRunning = true
|
||||||
this.loginCancelled = false
|
|
||||||
|
|
||||||
const loginContentArea = await this.page.waitForSelector("#login_content")
|
const loginContentArea = await this.page.waitForSelector("#login_content")
|
||||||
|
|
||||||
|
@ -226,17 +225,21 @@ export default class MessagesPuppeteer {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.log("Waiting for sync")
|
this.log("Waiting for sync")
|
||||||
await this.page.waitForFunction(
|
try {
|
||||||
messageSyncElement => {
|
await this.page.waitForFunction(
|
||||||
const text = messageSyncElement.innerText
|
messageSyncElement => {
|
||||||
return text == 'Syncing messages... 100%'
|
const text = messageSyncElement.innerText
|
||||||
},
|
return text == 'Syncing messages... 100%'
|
||||||
{},
|
},
|
||||||
result)
|
{},
|
||||||
|
result)
|
||||||
|
|
||||||
await this.startObserving()
|
this.loginRunning = false
|
||||||
this.loginRunning = false
|
await this.startObserving()
|
||||||
this.log("Login complete")
|
this.log("Login complete")
|
||||||
|
} catch (err) {
|
||||||
|
this._sendLoginFailure(`Failed to sync: ${err}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -244,6 +247,7 @@ export default class MessagesPuppeteer {
|
||||||
*/
|
*/
|
||||||
async cancelLogin() {
|
async cancelLogin() {
|
||||||
if (this.loginRunning) {
|
if (this.loginRunning) {
|
||||||
|
this.loginRunning = false
|
||||||
this.loginCancelled = true
|
this.loginCancelled = true
|
||||||
await this._preparePage(false)
|
await this._preparePage(false)
|
||||||
}
|
}
|
||||||
|
@ -252,6 +256,7 @@ export default class MessagesPuppeteer {
|
||||||
_waitForLoginCancel() {
|
_waitForLoginCancel() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (this.loginCancelled) {
|
if (this.loginCancelled) {
|
||||||
|
this.loginCancelled = false
|
||||||
resolve()
|
resolve()
|
||||||
} else {
|
} else {
|
||||||
reject()
|
reject()
|
||||||
|
@ -523,6 +528,7 @@ export default class MessagesPuppeteer {
|
||||||
}
|
}
|
||||||
|
|
||||||
_sendLoginFailure(reason) {
|
_sendLoginFailure(reason) {
|
||||||
|
this.loginRunning = false
|
||||||
this.error(`Login failure: ${reason ? reason : 'cancelled'}`)
|
this.error(`Login failure: ${reason ? reason : 'cancelled'}`)
|
||||||
if (this.client) {
|
if (this.client) {
|
||||||
this.client.sendFailure(reason).catch(err =>
|
this.client.sendFailure(reason).catch(err =>
|
||||||
|
|
Loading…
Reference in New Issue