Fix some more login problems

This commit is contained in:
Andrew Ferrazzutti 2021-02-11 00:04:25 -05:00
parent 6e94edfcb5
commit 758fb216d3
2 changed files with 16 additions and 13 deletions

View File

@ -413,8 +413,8 @@ class MautrixController {
this.emailAppearObserver = new MutationObserver(changes => { this.emailAppearObserver = new MutationObserver(changes => {
for (const change of changes) { for (const change of changes) {
for (const node of change.addedNodes) { for (const node of change.addedNodes) {
const emailElement = node.querySelector("#login_email_btn") const emailArea = node.querySelector("#login_email_area")
if (emailElement) { if (emailArea && !emailArea.getAttribute("class").includes("MdNonDisp")) {
window.__mautrixSendEmailCredentials() window.__mautrixSendEmailCredentials()
return return
} }

View File

@ -157,10 +157,10 @@ export default class MessagesPuppeteer {
const emailButton = await this.page.waitForSelector("#login_email_btn") const emailButton = await this.page.waitForSelector("#login_email_btn")
await emailButton.click() await emailButton.click()
const emailArea = await this.page.waitForSelector("#login_email_area", {visible: true}) await this.page.waitForSelector("#login_email_area", {visible: true})
this.login_email = login_data["email"] this.login_email = login_data["email"]
this.login_password = login_data["password"] this.login_password = login_data["password"]
this._sendEmailCredentials() await this._sendEmailCredentials()
await this.page.evaluate( await this.page.evaluate(
element => window.__mautrixController.addEmailAppearObserver(element), loginContentArea) element => window.__mautrixController.addEmailAppearObserver(element), loginContentArea)
@ -202,12 +202,12 @@ export default class MessagesPuppeteer {
const result = await Promise.race([ const result = await Promise.race([
() => this.page.waitForSelector("#wrap_message_sync", {timeout: 2000}) () => this.page.waitForSelector("#wrap_message_sync", {timeout: 2000})
.then(element => { .then(value => {
loginSuccess = true loginSuccess = true
return element return value
}), }),
() => this.page.waitForSelector("#login_incorrect", {visible: true, timeout: 2000}) () => this.page.waitForSelector("#login_incorrect", {visible: true, timeout: 2000})
.then(element => element.innerText), .then(value => this.page.evaluate(element => element.innerText, value)),
() => this._waitForLoginCancel(), () => this._waitForLoginCancel(),
].map(promiseFn => cancelableResolve(promiseFn))) ].map(promiseFn => cancelableResolve(promiseFn)))
@ -490,13 +490,16 @@ export default class MessagesPuppeteer {
async _sendEmailCredentials() { async _sendEmailCredentials() {
this.log("Inputting login credentials") this.log("Inputting login credentials")
// Triple-click email input field to select all existing text and replace it on type // Triple-click input fields to select all existing text and replace it on type
const emailInput = await this.page.$("#line_login_email") let input
await emailInput.click({clickCount: 3})
await emailInput.type(this.login_email)
// Password input field always starts empty, so no need to select its text first input = await this.page.$("#line_login_email")
await this.page.type("#line_login_pwd", this.login_password) await input.click({clickCount: 3})
await input.type(this.login_email)
input = await this.page.$("#line_login_pwd")
await input.click({clickCount: 3})
await input.type(this.login_password)
await this.page.click("button#login_btn") await this.page.click("button#login_btn")
} }