LookinDefines.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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.2.8";
  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. #pragma mark - Connection
  28. /// LookinServer 在真机上会依次尝试监听 47175 ~ 47179 这几个端口
  29. static const int LookinUSBDeviceIPv4PortNumberStart = 47175;
  30. static const int LookinUSBDeviceIPv4PortNumberEnd = 47179;
  31. /// LookinServer 在模拟器中会依次尝试监听 47164 ~ 47169 这几个端口
  32. static const int LookinSimulatorIPv4PortNumberStart = 47164;
  33. static const int LookinSimulatorIPv4PortNumberEnd = 47169;
  34. enum {
  35. /// 确认两端是否可以响应通讯
  36. LookinRequestTypePing = 200,
  37. /// 请求 App 的截图、设备型号等信息
  38. LookinRequestTypeApp = 201,
  39. /// 请求 Hierarchy 信息
  40. LookinRequestTypeHierarchy = 202,
  41. /// 请求 screenshots 和 attrGroups 信息
  42. LookinRequestTypeHierarchyDetails = 203,
  43. /// 请求修改某个内置的 Attribute 的值
  44. LookinRequestTypeInbuiltAttrModification = 204,
  45. /// 修改某个 attr 后,请求一系列最新的 Screenshots、属性值等信息
  46. LookinRequestTypeAttrModificationPatch = 205,
  47. /// 执行某个方法
  48. LookinRequestTypeInvokeMethod = 206,
  49. /**
  50. @request: @{@"oid":}
  51. @response: LookinObject *
  52. */
  53. LookinRequestTypeFetchObject = 207,
  54. LookinRequestTypeFetchImageViewImage = 208,
  55. LookinRequestTypeModifyRecognizerEnable = 209,
  56. /// 请求 attribute group list
  57. LookinRequestTypeAllAttrGroups = 210,
  58. /// 请求 iOS App 里某个 class 的所有 selector 名字列表(包括 superclass)
  59. LookinRequestTypeAllSelectorNames = 213,
  60. /// 请求修改某个自定义 Attribute 的值
  61. LookinRequestTypeCustomAttrModification = 214,
  62. /// 从 LookinServer 1.2.7 & Lookin 1.0.7 开始,该属性被废弃、不再使用
  63. LookinPush_BringForwardScreenshotTask = 303,
  64. // 用户在 Lookin 客户端取消了之前 HierarchyDetails 的拉取
  65. LookinPush_CanceHierarchyDetails = 304,
  66. };
  67. static NSString * const LookinParam_ViewLayerTag = @"tag";
  68. static NSString * const LookinParam_SelectorName = @"sn";
  69. static NSString * const LookinParam_MethodType = @"mt";
  70. static NSString * const LookinParam_SelectorClassName = @"scn";
  71. static NSString * const LookinStringFlag_VoidReturn = @"LOOKIN_TAG_RETURN_VALUE_VOID";
  72. #pragma mark - Error
  73. static NSString * const LookinErrorDomain = @"LookinError";
  74. enum {
  75. LookinErrCode_Default = -400,
  76. /// Lookin 内部业务逻辑错误
  77. LookinErrCode_Inner = -401,
  78. /// PeerTalk 内部错误
  79. LookinErrCode_PeerTalk = -402,
  80. /// 连接不存在或已断开
  81. LookinErrCode_NoConnect = -403,
  82. /// ping 失败了,原因是 ping 请求超时
  83. LookinErrCode_PingFailForTimeout = -404,
  84. /// 请求超时未返回
  85. LookinErrCode_Timeout = -405,
  86. /// 有相同 Type 的新请求被发出,因此旧请求被丢弃
  87. LookinErrCode_Discard = -406,
  88. /// ping 失败了,原因是 app 主动报告自身正处于后台模式
  89. LookinErrCode_PingFailForBackgroundState = -407,
  90. /// 没有找到对应的对象,可能已被释放
  91. LookinErrCode_ObjectNotFound = -500,
  92. /// 不支持修改当前类型的 LookinCodingValueType
  93. LookinErrCode_ModifyValueTypeInvalid = -501,
  94. LookinErrCode_Exception = -502,
  95. // LookinServer 版本过高,要升级 client
  96. LookinErrCode_ServerVersionTooHigh = -600,
  97. // LookinServer 版本过低,要升级 server
  98. LookinErrCode_ServerVersionTooLow = -601,
  99. // 不支持的文件类型
  100. LookinErrCode_UnsupportedFileType = -700,
  101. };
  102. #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)}]
  103. #define LookinErr_NoConnect [NSError errorWithDomain:LookinErrorDomain code:LookinErrCode_NoConnect userInfo:@{NSLocalizedDescriptionKey:NSLocalizedString(@"The operation failed due to disconnection with the iOS app.", nil)}]
  104. #define LookinErr_Inner [NSError errorWithDomain:LookinErrorDomain code:LookinErrCode_Inner userInfo:@{NSLocalizedDescriptionKey:NSLocalizedString(@"The operation failed due to an inner error.", nil)}]
  105. #define LookinErrorMake(errorTitle, errorDetail) [NSError errorWithDomain:LookinErrorDomain code:LookinErrCode_Default userInfo:@{NSLocalizedDescriptionKey:errorTitle, NSLocalizedRecoverySuggestionErrorKey:errorDetail}]
  106. #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)
  107. #pragma mark - Colors
  108. #if TARGET_OS_IPHONE
  109. #define LookinColor UIColor
  110. #define LookinInsets UIEdgeInsets
  111. #define LookinImage UIImage
  112. #elif TARGET_OS_MAC
  113. #define LookinColor NSColor
  114. #define LookinInsets NSEdgeInsets
  115. #define LookinImage NSImage
  116. #endif
  117. #define LookinColorRGBAMake(r, g, b, a) [LookinColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
  118. #define LookinColorMake(r, g, b) [LookinColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1]
  119. #pragma mark - Preview
  120. /// SCNNode 所允许的图片的最大的长和宽,单位是 px,这个值是 Scenekit 自身指定的
  121. /// Max pixel size of a SCNNode object. It is designated by SceneKit.
  122. static const double LookinNodeImageMaxLengthInPx = 16384;
  123. typedef NS_OPTIONS(NSUInteger, LookinPreviewBitMask) {
  124. LookinPreviewBitMask_None = 0,
  125. LookinPreviewBitMask_Selectable = 1 << 1,
  126. LookinPreviewBitMask_Unselectable = 1 << 2,
  127. LookinPreviewBitMask_HasLight = 1 << 3,
  128. LookinPreviewBitMask_NoLight = 1 << 4
  129. };
  130. #endif /* SHOULD_COMPILE_LOOKIN_SERVER */