Dismiss error dialog for getting disconnected
If the connection to LINE is lost, when it comes back, and error dialog appears. Detect that dialog and click it automatically. The same detection works for any error dialog.
This commit is contained in:
parent
94788a21dd
commit
6583815301
@ -90,7 +90,6 @@ class MautrixController {
|
||||
this.qrAppearObserver = null
|
||||
this.emailAppearObserver = null
|
||||
this.pinAppearObserver = null
|
||||
this.expiryObserver = null
|
||||
this.ownID = null
|
||||
|
||||
this.ownMsgPromise = Promise.resolve(-1)
|
||||
@ -968,26 +967,25 @@ class MautrixController {
|
||||
}
|
||||
}
|
||||
|
||||
addExpiryObserver(element) {
|
||||
this.removeExpiryObserver()
|
||||
const button = element.querySelector("dialog button")
|
||||
this.expiryObserver = new MutationObserver(changes => {
|
||||
if (changes.length == 1 && !changes[0].target.classList.contains("MdNonDisp")) {
|
||||
window.__mautrixExpiry(button)
|
||||
}
|
||||
})
|
||||
this.expiryObserver.observe(element, {
|
||||
attributes: true,
|
||||
attributeFilter: ["class"],
|
||||
})
|
||||
}
|
||||
|
||||
removeExpiryObserver() {
|
||||
if (this.expiryObserver !== null) {
|
||||
this.expiryObserver.disconnect()
|
||||
this.expiryObserver = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.__mautrixController = new MautrixController()
|
||||
|
||||
/**
|
||||
* Watch for an error dialog / PIN expiry dialog to appear, and click its "OK" button.
|
||||
* Must watch for both its parent appearing & it being added to its parent in the first place.
|
||||
*/
|
||||
const layer = document.querySelector("#layer_contents")
|
||||
new MutationObserver(() => {
|
||||
if (!layer.classList.contains("MdNonDisp")) {
|
||||
const button = layer.querySelector("dialog button")
|
||||
if (button) {
|
||||
console.log("Something expired, clicking OK button to continue")
|
||||
button.click()
|
||||
}
|
||||
}
|
||||
}).observe(layer, {
|
||||
attributes: true,
|
||||
attributeFilter: ["class"],
|
||||
childList: true,
|
||||
})
|
||||
|
@ -97,7 +97,6 @@ export default class MessagesPuppeteer {
|
||||
await this.page.exposeFunction("__mautrixReceiveQR", this._receiveQRChange.bind(this))
|
||||
await this.page.exposeFunction("__mautrixSendEmailCredentials", this._sendEmailCredentials.bind(this))
|
||||
await this.page.exposeFunction("__mautrixReceivePIN", this._receivePIN.bind(this))
|
||||
await this.page.exposeFunction("__mautrixExpiry", this._receiveExpiry.bind(this))
|
||||
await this.page.exposeFunction("__mautrixReceiveMessageID",
|
||||
id => this.sentMessageIDs.add(id))
|
||||
await this.page.exposeFunction("__mautrixReceiveChanges",
|
||||
@ -183,8 +182,6 @@ export default class MessagesPuppeteer {
|
||||
|
||||
await this.page.evaluate(
|
||||
element => window.__mautrixController.addPINAppearObserver(element), loginContentArea)
|
||||
await this.page.$eval("#layer_contents",
|
||||
element => window.__mautrixController.addExpiryObserver(element))
|
||||
|
||||
this.log("Waiting for login response")
|
||||
let doneWaiting = false
|
||||
@ -226,7 +223,6 @@ export default class MessagesPuppeteer {
|
||||
await this.page.evaluate(() => window.__mautrixController.removeQRAppearObserver())
|
||||
await this.page.evaluate(() => window.__mautrixController.removeEmailAppearObserver())
|
||||
await this.page.evaluate(() => window.__mautrixController.removePINAppearObserver())
|
||||
await this.page.evaluate(() => window.__mautrixController.removeExpiryObserver())
|
||||
delete this.login_email
|
||||
delete this.login_password
|
||||
|
||||
@ -739,10 +735,4 @@ export default class MessagesPuppeteer {
|
||||
this.log("No client connected, not sending failure reason")
|
||||
}
|
||||
}
|
||||
|
||||
async _receiveExpiry(button) {
|
||||
this.log("Something expired, clicking OK button to continue")
|
||||
this.page.click(button).catch(err =>
|
||||
this.error("Failed to dismiss expiry dialog:", err))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user