LookinDefines.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. #ifdef SHOULD_COMPILE_LOOKIN_SERVER
  2. //
  3. // LookinMessageProtocol.h
  4. // Lookin
  5. //
  6. // Created by Li Kai on 2018/8/6.
  7. // https://lookin.work
  8. //
  9. #import "TargetConditionals.h"
  10. #if TARGET_OS_IPHONE
  11. #import <UIKit/UIKit.h>
  12. #elif TARGET_OS_MAC
  13. #import <Appkit/Appkit.h>
  14. #endif
  15. #include <stdint.h>
  16. #pragma mark - Version
  17. /// current connection protocol version of LookinServer
  18. static const int LOOKIN_SERVER_VERSION = 7;
  19. /// current release version of LookinServer
  20. static NSString * const LOOKIN_SERVER_READABLE_VERSION = @"1.1.5";
  21. /// current connection protocol version of LookinClient
  22. static const int LOOKIN_CLIENT_VERSION = 7;
  23. /// the minimum connection protocol version supported by current LookinClient
  24. static const int LOOKIN_SUPPORTED_SERVER_MIN = 7;
  25. /// the maximum connection protocol version supported by current LookinClient
  26. static const int LOOKIN_SUPPORTED_SERVER_MAX = 7;
  27. /// Legacy code. No effect actually.
  28. static BOOL LOOKIN_SERVER_IS_EXPERIMENTAL = NO;
  29. static BOOL LOOKIN_CLIENT_IS_EXPERIMENTAL = NO;
  30. static const int LOOKIN_SERVER_SETUP_TYPE = 1;
  31. static NSString * const LOOKIN_SERVER_FRAMEWORK_URL = @"https://lookin.work/download/framework/LookinServer-1-0-0.zip";
  32. #pragma mark - Connection
  33. /// LookinServer 在真机上会依次尝试监听 47175 ~ 47179 这几个端口
  34. static const int LookinUSBDeviceIPv4PortNumberStart = 47175;
  35. static const int LookinUSBDeviceIPv4PortNumberEnd = 47179;
  36. /// LookinServer 在模拟器中会依次尝试监听 47164 ~ 47169 这几个端口
  37. static const int LookinSimulatorIPv4PortNumberStart = 47164;
  38. static const int LookinSimulatorIPv4PortNumberEnd = 47169;
  39. enum {
  40. /// 确认两端是否可以响应通讯
  41. LookinRequestTypePing = 200,
  42. /// 请求 App 的截图、设备型号等信息
  43. LookinRequestTypeApp = 201,
  44. /// 请求 Hierarchy 信息
  45. LookinRequestTypeHierarchy = 202,
  46. /// 请求 screenshots 和 attrGroups 信息
  47. LookinRequestTypeHierarchyDetails = 203,
  48. /// 请求修改某个 Attribute 的值
  49. LookinRequestTypeModification = 204,
  50. /// 修改某个 attr 后,请求一系列最新的 Screenshots、属性值等信息
  51. LookinRequestTypeAttrModificationPatch = 205,
  52. /// 执行某个方法
  53. LookinRequestTypeInvokeMethod = 206,
  54. /**
  55. @request: @{@"oid":}
  56. @response: LookinObject *
  57. */
  58. LookinRequestTypeFetchObject = 207,
  59. LookinRequestTypeFetchImageViewImage = 208,
  60. LookinRequestTypeModifyRecognizerEnable = 209,
  61. /// 请求 attribute group list
  62. LookinRequestTypeAllAttrGroups = 210,
  63. /// 请求 iOS App 里所有的 class 名字列表和监听中的方法列表
  64. LookinRequestTypeClassesAndMethodTraceLit = 212,
  65. /// 请求 iOS App 里某个 class 的所有 selector 名字列表(包括 superclass)
  66. LookinRequestTypeAllSelectorNames = 213,
  67. // 增加 methodTrace
  68. LookinRequestTypeAddMethodTrace = 214,
  69. // 删除 methodTrace
  70. LookinRequestTypeDeleteMethodTrace = 215,
  71. LookinPush_BringForwardScreenshotTask = 303,
  72. // 用户在 Lookin 客户端取消了之前 HierarchyDetails 的拉取
  73. LookinPush_CanceHierarchyDetails = 304,
  74. /// iOS 端推送 method trace 信息
  75. LookinPush_MethodTraceRecord = 403
  76. };
  77. static NSString * const LookinParam_ViewLayerTag = @"tag";
  78. static NSString * const LookinParam_SelectorName = @"sn";
  79. static NSString * const LookinParam_MethodType = @"mt";
  80. static NSString * const LookinParam_SelectorClassName = @"scn";
  81. static NSString * const LookinStringFlag_VoidReturn = @"LOOKIN_TAG_RETURN_VALUE_VOID";
  82. #pragma mark - Error
  83. static NSString * const LookinErrorDomain = @"LookinError";
  84. enum {
  85. LookinErrCode_Default = -400,
  86. /// Lookin 内部业务逻辑错误
  87. LookinErrCode_Inner = -401,
  88. /// PeerTalk 内部错误
  89. LookinErrCode_PeerTalk = -402,
  90. /// 连接不存在或已断开
  91. LookinErrCode_NoConnect = -403,
  92. /// ping 失败了,原因是 ping 请求超时
  93. LookinErrCode_PingFailForTimeout = -404,
  94. /// 请求超时未返回
  95. LookinErrCode_Timeout = -405,
  96. /// 有相同 Type 的新请求被发出,因此旧请求被丢弃
  97. LookinErrCode_Discard = -406,
  98. /// ping 失败了,原因是 app 主动报告自身正处于后台模式
  99. LookinErrCode_PingFailForBackgroundState = -407,
  100. /// 没有找到对应的对象,可能已被释放
  101. LookinErrCode_ObjectNotFound = -500,
  102. /// 不支持修改当前类型的 LookinCodingValueType
  103. LookinErrCode_ModifyValueTypeInvalid = -501,
  104. LookinErrCode_Exception = -502,
  105. // LookinServer 版本过高,要升级 client
  106. LookinErrCode_ServerVersionTooHigh = -600,
  107. // LookinServer 版本过低,要升级 server
  108. LookinErrCode_ServerVersionTooLow = -601,
  109. // LookinServer 是私有版本,但 client 是现网版本
  110. LookinErrCode_ServerIsPrivate = -602,
  111. // LookinServer 是现网版本,但 client 是私有版本
  112. LookinErrCode_ClientIsPrivate = - 603,
  113. // 不支持的文件类型
  114. LookinErrCode_UnsupportedFileType = -700,
  115. };
  116. #define LookinErr_ObjNotFound [NSError errorWithDomain:LookinErrorDomain code:LookinErrCode_ObjectNotFound userInfo:@{NSLocalizedDescriptionKey:NSLocalizedString(@"Failed to get target object in iOS app", nil), NSLocalizedRecoverySuggestionErrorKey:NSLocalizedString(@"Perhaps the related object was deallocated. You can reload Lookin to get newest data.", nil)}]
  117. #define LookinErr_NoConnect [NSError errorWithDomain:LookinErrorDomain code:LookinErrCode_NoConnect userInfo:@{NSLocalizedDescriptionKey:NSLocalizedString(@"The operation failed due to disconnection with the iOS app.", nil)}]
  118. #define LookinErr_Inner [NSError errorWithDomain:LookinErrorDomain code:LookinErrCode_Inner userInfo:@{NSLocalizedDescriptionKey:NSLocalizedString(@"The operation failed due to an inner error.", nil)}]
  119. #define LookinErrorMake(errorTitle, errorDetail) [NSError errorWithDomain:LookinErrorDomain code:LookinErrCode_Default userInfo:@{NSLocalizedDescriptionKey:errorTitle, NSLocalizedRecoverySuggestionErrorKey:errorDetail}]
  120. #define LookinErrorText_Timeout NSLocalizedString(@"Perhaps your iOS app is paused with breakpoint in Xcode, blocked by other tasks in main thread, or moved to background state.", nil)
  121. #pragma mark - Colors
  122. #if TARGET_OS_IPHONE
  123. #define LookinColor UIColor
  124. #define LookinInsets UIEdgeInsets
  125. #define LookinImage UIImage
  126. #elif TARGET_OS_MAC
  127. #define LookinColor NSColor
  128. #define LookinInsets NSEdgeInsets
  129. #define LookinImage NSImage
  130. #endif
  131. #define LookinColorRGBAMake(r, g, b, a) [LookinColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
  132. #define LookinColorMake(r, g, b) [LookinColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1]
  133. #pragma mark - Preview
  134. /// SCNNode 所允许的图片的最大的长和宽,单位是 px,这个值是 Scenekit 自身指定的
  135. /// Max pixel size of a SCNNode object. It is designated by SceneKit.
  136. static const double LookinNodeImageMaxLengthInPx = 16384;
  137. typedef NS_OPTIONS(NSUInteger, LookinPreviewBitMask) {
  138. LookinPreviewBitMask_None = 0,
  139. LookinPreviewBitMask_Selectable = 1 << 1,
  140. LookinPreviewBitMask_Unselectable = 1 << 2,
  141. LookinPreviewBitMask_HasLight = 1 << 3,
  142. LookinPreviewBitMask_NoLight = 1 << 4
  143. };
  144. #endif /* SHOULD_COMPILE_LOOKIN_SERVER */