Skip to content

Commit

Permalink
合并分支
Browse files Browse the repository at this point in the history
  • Loading branch information
aoliaoaoaojiao committed Sep 4, 2022
2 parents 518d520 + bd4aff8 commit 8cf3414
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 17 deletions.
4 changes: 2 additions & 2 deletions cmd/afc.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (

var afcCmd = &cobra.Command{
Use: "afc",
Short: "manipulate device files through afc commands",
Long: "manipulate device files through afc commands",
Short: "Manipulate device files through afc commands",
Long: "Manipulate device files through afc commands",
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
Expand Down
4 changes: 2 additions & 2 deletions cmd/webinspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

var webInspectorCmd = &cobra.Command{
Use: "webinspector",
Short: "manipulate device files through afc commands",
Long: "manipulate device files through afc commands",
Short: "Enable iOS webinspector communication service",
Long: "Enable iOS webinspector communication service",
Run: func(cmd *cobra.Command, args []string) {
done := make(chan os.Signal, 1)
signal.Notify(done)
Expand Down
10 changes: 8 additions & 2 deletions src/webinspector/webkitDebugProxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,16 @@ func PageDebugHandle(c *gin.Context) {
}
}()
//// 确保初始化完成
webDebug.ReceiveProtocolData()
err = webDebug.ReceiveProtocolData()
if err != nil {
fmt.Println(err)
}
go func() {
for {
webDebug.ReceiveProtocolData()
err = webDebug.ReceiveProtocolData()
if err != nil {
return
}
}
}()

Expand Down
44 changes: 33 additions & 11 deletions src/webinspector/webkitDebugService.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type WebkitDebugService struct {
senderID string
ctx context.Context
wsConn *websocket.Conn
closeSendWS context.Context
}

var isProtocolDebug = false
Expand All @@ -34,7 +35,6 @@ func NewWebkitDebugService(device *giDevice.Device, ctx context.Context) *Webkit
return &WebkitDebugService{
device: device,
connectID: strings.ToUpper(uuid.New().String()),
senderID: strings.ToUpper(uuid.New().String()),
ctx: ctx,
}
}
Expand Down Expand Up @@ -93,6 +93,19 @@ func (w *WebkitDebugService) Close() {

func (w *WebkitDebugService) StartCDP(appID *string, pageID *int, conn *websocket.Conn) error {
w.wsConn = conn
senderID := strings.ToUpper(uuid.New().String())
w.senderID = senderID
var closeSendProtocol context.CancelFunc
w.closeSendWS, closeSendProtocol = context.WithCancel(w.ctx)

w.wsConn.SetCloseHandler(func(code int, text string) error {
log.Println("try close ws")
// 用于保证页面刷新
w.wsConn = nil
closeSendProtocol()
return w.rpcService.SendForwardDidClose(&w.connectID, appID, *pageID, &senderID)
})
//w.connectID = strings.ToUpper(uuid.New().String())
return w.rpcService.SendForwardSocketSetup(&w.connectID, appID, *pageID, &w.senderID, false)
}

Expand Down Expand Up @@ -153,22 +166,31 @@ func (w *WebkitDebugService) SendProtocolCommand(applicationID *string, pageID *
}
}

func (w *WebkitDebugService) ReceiveProtocolData() {
select {
case message, ok := <-w.rpcService.WirEvent:
if ok {
if isProtocolDebug {
log.Println(fmt.Sprintf("protocol receive command:%s\n", string(message)))
func (w *WebkitDebugService) ReceiveProtocolData() error {
if w.rpcService.WirEvent != nil {
select {
case message, ok := <-w.rpcService.WirEvent:
if ok {
if isProtocolDebug {
log.Println(fmt.Sprintf("protocol receive command:%s\n", string(message)))
}
w.SendMessageTool(message)
}
w.SendMessageTool(message)
case <-w.closeSendWS.Done():
return fmt.Errorf("close send protocol")
}
}
return nil
}

func (w *WebkitDebugService) SendMessageTool(rawMessage []byte) {
err := w.wsConn.WriteMessage(websocket.TextMessage, rawMessage)
if err != nil {
log.Fatal(err)
if w.wsConn != nil {
err := w.wsConn.WriteMessage(websocket.TextMessage, rawMessage)
if err != nil {
log.Fatal(err)
}
} else {
return
}
}

Expand Down

0 comments on commit 8cf3414

Please sign in to comment.