Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.www.
wechaty
提交
da88dfcf
W
wechaty
项目概览
.www.
/
wechaty
与 Fork 源项目一致
Fork自
wechaty / wechaty
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
wechaty
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
da88dfcf
编写于
9月 06, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add more targetState() check
上级
cbadd23b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
36 addition
and
8 deletion
+36
-8
src/puppet-web/browser.js
src/puppet-web/browser.js
+18
-7
src/puppet-web/puppet-web.js
src/puppet-web/puppet-web.js
+18
-1
未找到文件。
src/puppet-web/browser.js
浏览文件 @
da88dfcf
...
...
@@ -26,7 +26,7 @@ class Browser extends EventEmitter {
head
=
process
.
env
.
WECHATY_HEAD
||
Config
.
DEFAULT_HEAD
,
sessionFile
}
=
{})
{
log
.
verbose
(
'
Browser
'
,
'
constructor() with head(%s) sessionFile(%s)
'
,
head
,
sessionFile
)
log
.
verbose
(
'
PuppetWeb
Browser
'
,
'
constructor() with head(%s) sessionFile(%s)
'
,
head
,
sessionFile
)
super
()
log
.
verbose
(
'
PuppetWebBrowser
'
,
'
constructor()
'
)
this
.
head
=
head
...
...
@@ -41,7 +41,7 @@ class Browser extends EventEmitter {
// targetState : 'open' | 'close'
targetState
(
newState
)
{
if
(
newState
)
{
log
.
verbose
(
'
Browser
'
,
'
targetState(%s)
'
,
newState
)
log
.
verbose
(
'
PuppetWeb
Browser
'
,
'
targetState(%s)
'
,
newState
)
this
.
_targetState
=
newState
}
return
this
.
_targetState
...
...
@@ -50,7 +50,7 @@ class Browser extends EventEmitter {
// currentState : 'opening' | 'open' | 'closing' | 'close'
currentState
(
newState
)
{
if
(
newState
)
{
log
.
verbose
(
'
Browser
'
,
'
currentState(%s)
'
,
newState
)
log
.
verbose
(
'
PuppetWeb
Browser
'
,
'
currentState(%s)
'
,
newState
)
this
.
_currentState
=
newState
}
return
this
.
_currentState
...
...
@@ -77,8 +77,19 @@ class Browser extends EventEmitter {
})
yield
this
.
open
()
this
.
currentState
(
'
open
'
)
return
this
/**
* XXX
*
* when open url, there could happen a quit() call.
* should check here: if we are in `close` target state, we should clean up
*/
if
(
this
.
targetState
()
===
'
open
'
)
{
this
.
currentState
(
'
open
'
)
return
this
}
else
{
log
.
warn
(
'
PuppetWebBrowser
'
,
'
init() finished but found targetState() is close. quit().
'
)
return
this
.
quit
()
}
})
.
catch
(
e
=>
{
// XXX: must has a `.catch` here, or promise will hang! 2016/6/7
...
...
@@ -323,7 +334,7 @@ this.onResourceRequested = function(request, net) {
}
getBrowserPids
()
{
log
.
silly
(
'
Browser
'
,
'
getBrowserPids()
'
)
log
.
silly
(
'
PuppetWeb
Browser
'
,
'
getBrowserPids()
'
)
return
new
Promise
((
resolve
,
reject
)
=>
{
require
(
'
ps-tree
'
)(
process
.
pid
,
(
err
,
children
)
=>
{
...
...
@@ -352,7 +363,7 @@ this.onResourceRequested = function(request, net) {
let
matchRegex
=
new
RegExp
(
browserRe
,
'
i
'
)
const
pids
=
children
.
filter
(
child
=>
{
log
.
silly
(
'
Browser
'
,
'
getBrowserPids() child: %s
'
,
JSON
.
stringify
(
child
))
log
.
silly
(
'
PuppetWeb
Browser
'
,
'
getBrowserPids() child: %s
'
,
JSON
.
stringify
(
child
))
// https://github.com/indexzero/ps-tree/issues/18
return
matchRegex
.
test
(
''
+
child
.
COMMAND
+
child
.
COMM
)
}).
map
(
child
=>
child
.
PID
)
...
...
src/puppet-web/puppet-web.js
浏览文件 @
da88dfcf
...
...
@@ -175,6 +175,11 @@ class PuppetWeb extends Puppet {
this
.
browser
=
browser
if
(
this
.
targetState
()
!==
'
live
'
)
{
log
.
warn
(
'
PuppetWeb
'
,
'
initBrowser() found targetState != live, no init anymore
'
)
return
Promise
.
resolve
(
'
skipped
'
)
}
return
co
.
call
(
this
,
function
*
()
{
yield
browser
.
init
()
return
browser
// follow func name meaning
...
...
@@ -193,9 +198,16 @@ class PuppetWeb extends Puppet {
this
.
bridge
=
bridge
if
(
this
.
targetState
()
!==
'
live
'
)
{
log
.
warn
(
'
PuppetWeb
'
,
'
initBridge() found targetState != live, no init anymore
'
)
return
Promise
.
resolve
(
'
skipped
'
)
}
return
bridge
.
init
()
.
catch
(
e
=>
{
if
(
this
.
browser
.
dead
())
{
if
(
!
this
.
browser
){
log
.
warn
(
'
PuppetWeb
'
,
'
initBridge() without browser?
'
)
}
else
if
(
this
.
browser
.
dead
())
{
log
.
warn
(
'
PuppetWeb
'
,
'
initBridge() found browser dead, wait it to restore
'
)
}
else
{
log
.
error
(
'
PuppetWeb
'
,
'
initBridge() exception: %s
'
,
e
.
message
)
...
...
@@ -227,6 +239,11 @@ class PuppetWeb extends Puppet {
this
.
server
=
server
if
(
this
.
targetState
()
!==
'
live
'
)
{
log
.
warn
(
'
PuppetWeb
'
,
'
initServer() found targetState != live, no init anymore
'
)
return
Promise
.
resolve
(
'
skipped
'
)
}
return
server
.
init
()
.
catch
(
e
=>
{
log
.
error
(
'
PuppetWeb
'
,
'
initServer() exception: %s
'
,
e
.
message
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录