Try to fix some errors caused by bad ordering

This commit is contained in:
Andrew Ferrazzutti 2021-07-14 03:17:07 -04:00
parent 70c21e528f
commit 81553df1c4
1 changed files with 15 additions and 7 deletions

View File

@ -273,13 +273,17 @@ export default class MessagesPuppeteer {
() => this._waitForLoginCancel(), () => this._waitForLoginCancel(),
].map(promiseFn => cancelableResolve(promiseFn))) ].map(promiseFn => cancelableResolve(promiseFn)))
this.log("Removing observers") if (!this.loginCancelled) {
// TODO __mautrixController is undefined when cancelling, why? this.log("Removing observers")
await this.page.evaluate(ownID => window.__mautrixController.setOwnID(ownID), this.ownID) // TODO __mautrixController is undefined when cancelling, why?
await this.page.evaluate(() => window.__mautrixController.removeQRChangeObserver()) await this.page.evaluate(ownID => window.__mautrixController.setOwnID(ownID), this.ownID)
await this.page.evaluate(() => window.__mautrixController.removeQRAppearObserver()) await this.page.evaluate(() => window.__mautrixController.removeQRChangeObserver())
await this.page.evaluate(() => window.__mautrixController.removeEmailAppearObserver()) await this.page.evaluate(() => window.__mautrixController.removeQRAppearObserver())
await this.page.evaluate(() => window.__mautrixController.removePINAppearObserver()) await this.page.evaluate(() => window.__mautrixController.removeEmailAppearObserver())
await this.page.evaluate(() => window.__mautrixController.removePINAppearObserver())
} else {
this.loginCancelled = false
}
delete this.login_email delete this.login_email
delete this.login_password delete this.login_password
@ -340,6 +344,7 @@ export default class MessagesPuppeteer {
* Close the browser. * Close the browser.
*/ */
async stop() { async stop() {
this.stopObserving()
this.taskQueue.stop() this.taskQueue.stop()
if (this.page) { if (this.page) {
await this.page.close() await this.page.close()
@ -356,6 +361,9 @@ export default class MessagesPuppeteer {
* @return {Promise<boolean>} - Whether or not the session is logged in. * @return {Promise<boolean>} - Whether or not the session is logged in.
*/ */
async isLoggedIn() { async isLoggedIn() {
if (!this.page) {
return false
}
const selectors = [ const selectors = [
"#mainApp:not(.MdNonDisp)", "#mainApp:not(.MdNonDisp)",
"#wrap_message_sync", "#wrap_message_sync",