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

support(switch account): try to click the button if found (#636)

上级 2aa39eb5
......@@ -583,10 +583,6 @@ export class Bridge {
})
}
public async clickSwitchAccount(): Promise<boolean> {
log.verbose('PuppetWebBridge', 'clickSwitchAccount()')
return this.puppet.browser.clickSwitchAccount()
}
}
/* tslint:disable:jsdoc-format */
......
......@@ -103,11 +103,11 @@ export class PuppetWeb extends Puppet {
await this.initServer()
log.verbose('PuppetWeb', 'initServer() done')
await this.initBrowser()
this.browser = await this.initBrowser()
log.verbose('PuppetWeb', 'initBrowser() done')
try {
await this.initBridge()
this.bridge = await this.initBridge()
} catch (e) {
const blockedMessage = await this.bridge.blockedMessageBody()
|| await this.bridge.blockedMessageAlert()
......@@ -119,7 +119,7 @@ export class PuppetWeb extends Puppet {
}
log.verbose('PuppetWeb', 'initBridge() done')
const clicked = await this.bridge.clickSwitchAccount()
const clicked = await this.browser.clickSwitchAccount()
if (clicked) {
log.verbose('PuppetWeb', 'init() bridge.clickSwitchAccount() clicked')
}
......@@ -230,15 +230,15 @@ export class PuppetWeb extends Puppet {
}
}
public async initBrowser(): Promise<void> {
public async initBrowser(): Promise<Browser> {
log.verbose('PuppetWeb', 'initBrowser()')
this.browser = new Browser({
const browser = new Browser({
head: <HeadName>this.setting.head,
sessionFile: this.setting.profile,
})
this.browser.on('dead', Event.onBrowserDead.bind(this))
browser.on('dead', Event.onBrowserDead.bind(this))
if (this.state.target() === 'dead') {
const e = new Error('found state.target()) != live, no init anymore')
......@@ -247,19 +247,19 @@ export class PuppetWeb extends Puppet {
}
try {
await this.browser.init()
await browser.init()
} catch (e) {
log.error('PuppetWeb', 'initBrowser() exception: %s', e.message)
Raven.captureException(e)
throw e
}
return
return browser
}
public async initBridge(): Promise<void> {
public async initBridge(): Promise<Bridge> {
log.verbose('PuppetWeb', 'initBridge()')
this.bridge = new Bridge(
const bridge = new Bridge(
this, // use puppet instead of browser, is because browser might change(die) duaring run time,
this.port,
)
......@@ -271,7 +271,7 @@ export class PuppetWeb extends Puppet {
}
try {
await this.bridge.init()
await bridge.init()
} catch (e) {
Raven.captureException(e)
if (!this.browser) {
......@@ -284,7 +284,7 @@ export class PuppetWeb extends Puppet {
throw e
}
}
return
return bridge
}
private async initServer(): Promise<void> {
......
......@@ -41,7 +41,10 @@ import {
*/
test.serial('login/logout events', async t => {
const STUB_INIT_BROWSER = stub(PuppetWeb.prototype, 'initBrowser')
STUB_INIT_BROWSER.resolves()
STUB_INIT_BROWSER.resolves({
clickSwitchAccount: () => false,
})
const STUB_BRIDGE_INIT = stub(PuppetWebBridge.prototype, 'init')
STUB_BRIDGE_INIT.resolves()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册