Skip to content

Commit

Permalink
code clean
Browse files Browse the repository at this point in the history
  • Loading branch information
huan committed Nov 13, 2016
1 parent 8f44b94 commit d97e750
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 22 deletions.
1 change: 1 addition & 0 deletions bin/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ npm run lint
# must run this after the above `test` ([ -z ...]),
# or will whow a error: error: failed to push some refs to 'git@github.com:wechaty/wechaty.git'
echo "PRE-PUSH HOOK PASSED"
echo

6 changes: 5 additions & 1 deletion src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,13 @@ export class Message implements Sayable {
return null
}

public content(content?: string): string {
public content(): string
public content(content: string): void

public content(content?: string): string|void {
if (content) {
this.obj.content = content
return
}
return this.obj.content
}
Expand Down
35 changes: 19 additions & 16 deletions src/puppet-web/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,9 @@ export class Bridge {
// }
try {
let ret
/**
* Async functions name is start with `Async` in WechatyBro
*/
if (/Async$/.test(wechatyFunc)) {
ret = await this.executeAsync(wechatyScript)
} else {
Expand All @@ -422,38 +425,38 @@ export class Bridge {
/**
* call REAL browser excute for other methods
*/
public execute(script, ...args): Promise<any> {
public async execute(script, ...args): Promise<any> {
log.verbose('PuppetWebBridge', 'execute()')

if (!this.puppet || !this.puppet.browser) {
return Promise.reject(new Error('execute(): no puppet or no puppet.browser in bridge'))
throw new Error('execute(): no puppet or no puppet.browser in bridge')
}
return this.puppet.browser.execute(script, ...args)
.catch(e => {
log.warn('PuppetWebBridge', 'execute() exception: %s', e.message)
throw e
})
.catch(e => {
log.warn('PuppetWebBridge', 'execute() exception: %s', e.message)
throw e
})
}

private executeAsync(script, ...args): Promise<any> {
private async executeAsync(script, ...args): Promise<any> {
if (!this.puppet || !this.puppet.browser) {
return Promise.reject(new Error('execute(): no puppet or no puppet.browser in bridge'))
throw new Error('execute(): no puppet or no puppet.browser in bridge')
}
return this.puppet.browser.executeAsync(script, ...args)
.catch(e => {
log.warn('PuppetWebBridge', 'executeAsync() exception: %s', e.message)
throw e
})
.catch(e => {
log.warn('PuppetWebBridge', 'executeAsync() exception: %s', e.message)
throw e
})
}

public ding(data): Promise<any> {
log.verbose('PuppetWebBridge', 'ding(%s)', data)

return this.proxyWechaty('ding', data)
.catch(e => {
log.error('PuppetWebBridge', 'ding(%s) exception: %s', data, e.message)
throw e
})
.catch(e => {
log.error('PuppetWebBridge', 'ding(%s) exception: %s', data, e.message)
throw e
})
}
}

Expand Down
16 changes: 11 additions & 5 deletions src/puppet-web/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,15 +362,20 @@ export class Browser extends EventEmitter {
// too noisy!
// log.silly('PuppetWebBrowser', 'dead() checking ... ')

if ( this.state.target() === 'close'
|| this.state.current() === 'close'
|| this.state.inprocess()
) {
log.verbose('PuppetWebBrowser', 'dead() browser is in dead state')
return true
}

let msg
let dead = false

if (forceReason) {
dead = true
msg = forceReason
} else if (this.state.target() !== 'open') {
dead = true
msg = 'state.target() not open'
} else if (!this.driver) { // FIXME: this.driver is BrowserDriver, should add a method to check if availble 201610
dead = true
msg = 'no driver or session'
Expand Down Expand Up @@ -400,8 +405,9 @@ export class Browser extends EventEmitter {
return dead
}

public addCookie(cookies: CookieType[]): Promise<void>
public addCookie(cookie: CookieType): Promise<void>
public addCookie(cookies: CookieType[]): Promise<void>
public addCookie(cookie: CookieType): Promise<void>

public addCookie(cookie: CookieType|CookieType[]): Promise<void> {
return this.cookie.add(cookie)
}
Expand Down

0 comments on commit d97e750

Please sign in to comment.