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

use WECHATY_HEAD env var to control headless

上级 37c0fd72
......@@ -87,6 +87,7 @@ export type PuppetName = 'web'
export interface ConfigSetting {
DEFAULT_HEAD: number
DEFAULT_PUPPET: PuppetName
DEFAULT_APIHOST: string
DEFAULT_PROFILE: string
......@@ -97,6 +98,7 @@ export interface ConfigSetting {
token: string
debug: boolean
head: boolean
puppet: PuppetName
apihost: string
......@@ -123,9 +125,9 @@ export const config: ConfigSetting = require('../package.json').wechaty
* 1. ENVIRONMENT VARIABLES + PACKAGES.JSON (default)
*/
Object.assign(config, {
apihost: process.env['WECHATY_APIHOST'] || config.DEFAULT_APIHOST,
// head: process.env['WECHATY_HEAD'] || config.DEFAULT_HEAD,
puppet: process.env['WECHATY_PUPPET'] || config.DEFAULT_PUPPET,
apihost: process.env['WECHATY_APIHOST'] || config.DEFAULT_APIHOST,
head: ('WECHATY_HEAD' in process.env) ? (!!process.env['WECHATY_HEAD']) : (!!(config.DEFAULT_HEAD)),
puppet: process.env['WECHATY_PUPPET'] || config.DEFAULT_PUPPET,
validApiHost,
})
......
......@@ -96,6 +96,8 @@ export class Bridge extends EventEmitter {
}
public async initPage(browser: Browser): Promise<Page> {
log.verbose('PuppetWebBridge', 'initPage()')
const page = await browser.newPage()
const cookieList = this.options.profile.get('cookies') as Cookie[]
......@@ -106,6 +108,7 @@ export class Bridge extends EventEmitter {
if (cookieList && cookieList.length) {
await page.setCookie(...cookieList)
log.silly('PuppetWebBridge', 'initPage() page.setCookie() %s cookies set back', cookieList.length)
}
await page.exposeFunction('emit', this.emit.bind(this))
......
......@@ -17,6 +17,7 @@
*
*/
import {
config,
log,
Raven,
} from '../config'
......@@ -91,13 +92,6 @@ export class PuppetWeb extends Puppet {
await this.initWatchdogForPuppet()
await this.initWatchdogForScan()
const throttleQueue = new RxQueue('throttle', 5 * 60 * 1000)
this.on('heartbeat', data => throttleQueue.emit('i', data))
throttleQueue.on('o', async () => {
log.verbose('Wechaty', 'init() throttleQueue.on(o)')
await this.saveCookie()
})
this.bridge = await this.initBridge(this.options.profile)
log.verbose('PuppetWeb', 'initBridge() done')
......@@ -118,6 +112,13 @@ export class PuppetWeb extends Puppet {
}
this.emit('watchdog', food)
const throttleQueue = new RxQueue('throttle', 5 * 60 * 1000)
this.on('heartbeat', data => throttleQueue.emit('i', data))
throttleQueue.on('o', async () => {
log.verbose('Wechaty', 'init() throttleQueue.on(o)')
await this.saveCookie()
})
log.verbose('PuppetWeb', 'init() done')
return
......@@ -238,7 +239,7 @@ export class PuppetWeb extends Puppet {
throw e
}
const head = false
const head = config.head
// we have to set this.bridge right now,
// because the Event.onXXX might arrive while we are initializing.
this.bridge = new Bridge({
......
......@@ -186,7 +186,7 @@
}
function checkScan() {
log('checkScan()')
// log('checkScan()')
if (isLogin()) {
log('checkScan() - already login, no more check, and return(only)') //but I will emit a login event')
// login('checkScan found already login')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册