@@ -8,17 +8,21 @@ import (
88
99 "github.com/iosRealRun-cli/iOSRealRun-cli/internal/config"
1010 "github.com/iosRealRun-cli/iOSRealRun-cli/internal/device"
11+ "github.com/iosRealRun-cli/iOSRealRun-cli/internal/logger"
1112 "github.com/iosRealRun-cli/iOSRealRun-cli/internal/parseRoute"
1213 "github.com/iosRealRun-cli/iOSRealRun-cli/internal/utils"
1314)
1415
16+ var myLogger = logger .NewMyLogger ("log.log" , config .Config .LogLevel )
17+
1518func Connect () {
1619 conf := config .Config
1720 OS := utils .GetOS ()
1821
1922 if OS != "win" {
2023 utils .Cmd ([]string {"chmod" , "-R" , "+rx" , conf .LibimobiledeviceDir }, false )
2124 if OS == "linux" {
25+ // check if usbmuxd is installed
2226 path := strings .Split (os .Getenv ("PATH" ), ":" )
2327 check := false
2428 for _ , i := range path {
@@ -33,35 +37,47 @@ func Connect() {
3337 fmt .Scanln ()
3438 }
3539 } else {
40+ // check if libimobiledevice is quarantined
3641 quarantine := strings .Contains (utils .Cmd ([]string {"xattr" , "libimobiledevice/darwin/ideviceinfo" }), "quarantine" )
42+ myLogger .Debugln ("quarantine:" , quarantine )
3743 if quarantine {
3844 utils .Cmd ([]string {"sudo" , "xattr" , "-d" , "-r" , "com.apple.quarantine" , "." }, false )
3945 }
4046 }
4147 }
4248
49+ myLogger .Infoln ("Start connecting to device ..." )
4350 fmt .Println ("请解锁手机或iPad,然后按回车键继续" )
4451 fmt .Scanln ()
4552 status := device .Pair ()
53+ myLogger .Debugln ("status:" , status )
4654 for status == 1 {
55+ myLogger .Warnln ("No device connected to computer" )
4756 fmt .Println ("无设备连接,Windows需要安装iTunes,也可尝试解锁手机并插拔数据线,如果还是不行Mac和Windows请打开iTunes并在跑完前不要关闭" )
4857 fmt .Println ("确定连接后按回车键继续" )
4958 fmt .Scanln ()
5059 status = device .Pair ()
60+ myLogger .Debugln ("status:" , status )
5161 }
5262 if status == - 1 {
53- fmt .Println ("遇到了位置的问题" )
63+ myLogger .Error ("Connect to device failed" )
64+ fmt .Println ("遇到了未知的问题" )
5465 fmt .Println ("按回车退出" )
55- os . Exit ( 1 )
66+ panic ( "未知错误" )
5667 }
68+ myLogger .Infoln ("Connected to device" )
5769
5870 deviceName , version := device .GetDeviceInfo ()
71+ myLogger .Debugln ("deviceName:" , deviceName )
72+ myLogger .Debugln ("version:" , version )
5973 fmt .Printf ("已连接到: %s\n " , deviceName )
6074 fmt .Printf ("系统版本:%s\n " , version )
6175
6276 majorVersion , _ := strconv .ParseInt (strings .Split (version , "." )[0 ], 10 , 64 )
77+ myLogger .Debugln ("majorVersion:" , majorVersion )
6378 if majorVersion >= 16 {
6479 developerMode := ! strings .Contains (utils .Cmd ([]string {"idevicedevmodectl" , "list" }), "disabled" )
80+ myLogger .Debugln ("developerMode:" , developerMode )
6581 if ! developerMode {
6682 utils .Cmd ([]string {"idevicedevmodectl" , "reveal" })
6783 fmt .Println ("请在系统设置-隐私与安全性-开发者模式中打开开发者模式" )
@@ -72,6 +88,7 @@ func Connect() {
7288 os .Exit (0 )
7389 }
7490
91+ myLogger .Infoln ("Start importing DeveloperDiskImage ..." )
7592 imageStatus := utils .FileExists (fmt .Sprintf ("%s/%s/DeveloperDiskImage.dmg" , conf .ImageDir , version )) &&
7693 utils .FileExists (fmt .Sprintf ("%s/%s/DeveloperDiskImage.dmg.signature" , conf .ImageDir , version ))
7794 if ! imageStatus {
@@ -81,25 +98,29 @@ func Connect() {
8198 }
8299
83100 if ! imageStatus {
101+ myLogger .Warnln ("DeveloperDiskImage.dmg not found" )
84102 fmt .Printf ("没有在 %s 下找到 %s 版本的开发者镜像\n " , conf .ImageDir , version )
85103 fmt .Println ("请添加完后再次运行本脚本" )
86104 fmt .Println ("现在按回车退出" )
87105 fmt .Scanln ()
88106 os .Exit (0 )
89107 }
90108
109+ myLogger .Infoln ("Verifying the signature of the DeveloperDiskImage.dmg ..." )
91110 imageCMD := []string {
92111 "ideviceimagemounter" ,
93112 fmt .Sprintf ("%s/%s/DeveloperDiskImage.dmg" , conf .ImageDir , version ),
94113 fmt .Sprintf ("%s/%s/DeveloperDiskImage.dmg.signature" , conf .ImageDir , version ),
95114 }
96115 if strings .Contains (utils .Cmd (imageCMD ), "-3" ) {
116+ myLogger .Errorln ("DeveloperDiskImage.dmg signature verification failed" )
97117 fmt .Println ("开发者镜像签名验证失败,你要重新下一遍" )
98118 fmt .Println ("完成后再次运行本脚本" )
99119 fmt .Println ("现在按回车退出" )
100120 fmt .Scanln ()
101121 os .Exit (0 )
102122 }
123+ myLogger .Infoln ("Import DeveloperDiskImage successfully" )
103124 }
104125}
105126
@@ -110,5 +131,5 @@ func Init() []map[string]float64 {
110131 if err != nil {
111132 panic (err )
112133 }
113- return parseRoute .Split (content )
134+ return parseRoute .ParseRoute (content )
114135}
0 commit comments