提交 89e0916b 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

fix(race condition): fire login event before bridge inited (#772)

上级 7b75f395
......@@ -501,6 +501,11 @@ export class Browser extends EventEmitter {
log.verbose('PuppetWebBrowser', 'clickSwitchAccount()')
try {
// TODO
// Promise.race([
// english
// chinese
// ])
const button = await this.driver.driver.findElement(By.linkText('Switch Account'))
button.click()
log.silly('PuppetWebBrowser', 'clickSwitchAccount() clicked!')
......
......@@ -240,6 +240,15 @@ function onServerLog(data) {
async function onServerLogin(this: PuppetWeb, data, attempt = 0): Promise<void> {
log.verbose('PuppetWebEvent', 'onServerLogin(%s, %d)', data, attempt)
// issue #772
// if `login` event fired before this.bridge inited, we delay the event for 1 second.
if (!this.bridge) {
setTimeout(() => {
onServerLogin.apply(this, arguments)
}, 1000)
return
}
this.scan = null
if (this.userId) {
......@@ -248,6 +257,8 @@ async function onServerLogin(this: PuppetWeb, data, attempt = 0): Promise<void>
try {
/**
* save login user id to this.userId
*
* issue #772: this.bridge might not inited if the 'login' event fired too fast(because of auto login)
*/
this.userId = await this.bridge.getUserName()
......
......@@ -51,9 +51,9 @@ import * as bl from 'bl'
type MediaType = 'pic' | 'video' | 'doc'
const enum UploadMediaType {
IMAGE = 1,
VIDEO = 2,
AUDIO = 3,
IMAGE = 1,
VIDEO = 2,
AUDIO = 3,
ATTACHMENT = 4,
}
export interface PuppetWebSetting {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册