Skip to content

Commit

Permalink
refactor(ios): add delegate method for remote debugging
Browse files Browse the repository at this point in the history
update hippy demo
  • Loading branch information
wwwcg committed Nov 4, 2024
1 parent 6373ae5 commit 6ac9a5d
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 31 deletions.
50 changes: 25 additions & 25 deletions framework/examples/ios-demo/HippyDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -126,24 +126,12 @@
0632A691275B124491E38EA7 /* HippyDemo */ = {
isa = PBXGroup;
children = (
EF558AABDC113B410B8ED69C /* AppDelegate.h */,
6094F1F80FD70F9F9853EE15 /* AppDelegate.m */,
427F60D1B98DA953328F4E71 /* DemoBaseViewController.h */,
4708C41E8571123282E2B806 /* DemoBaseViewController.m */,
80D715362B1A0B0DCEAA813D /* DemoNavigationViewController.h */,
16348E2DEBFF10ADD6FCF7A9 /* DemoNavigationViewController.m */,
6045C301C6CFDC6C2E87AA66 /* IconUtils.h */,
17AB7FB6346FE861C9D953F5 /* IconUtils.m */,
177A9E8373F2682A9A831991 /* Info.plist */,
D2EE3455BE6DD7D2ADA20093 /* main.m */,
DDD052D2760E830B1E0095EA /* UIViewController+Title.h */,
C412B5D210F1E3359523628C /* UIViewController+Title.m */,
4CF6648308C60D57DD274D30 /* HomePage */,
DE44248AB3BFFAAE044EAB9E /* myview */,
73EF815F203E15B86205DFC3 /* PageManager */,
57D9249C5EA211061816F73B /* RenderPage */,
09FA8898DDD429EC19584446 /* SettingsPage */,
529ECDFF8342B9C9D950B1FA /* turbomodule */,
71EA01A72CD87C0500ED4D29 /* Others */,
DE44248AB3BFFAAE044EAB9E /* MyViewDemo */,
28C2DA6A96B596294158B364 /* HippyDemoViewController.h */,
9EB0CD5FCC3F38E3C7DC5E00 /* HippyDemoViewController.m */,
529ECDFF8342B9C9D950B1FA /* TurboModuleDemo */,
);
path = HippyDemo;
sourceTree = "<group>";
Expand Down Expand Up @@ -193,24 +181,36 @@
path = HomePage;
sourceTree = "<group>";
};
529ECDFF8342B9C9D950B1FA /* turbomodule */ = {
529ECDFF8342B9C9D950B1FA /* TurboModuleDemo */ = {
isa = PBXGroup;
children = (
C629FDE26F7B6DBC976FB63A /* TurboBaseModule.h */,
CC8AEAE8BF116954FB41BDF9 /* TurboBaseModule.mm */,
041D598BDAC3735B5A06ECE7 /* TurboConfig.h */,
46034630F6D4A25199673157 /* TurboConfig.m */,
);
path = turbomodule;
path = TurboModuleDemo;
sourceTree = "<group>";
};
57D9249C5EA211061816F73B /* RenderPage */ = {
71EA01A72CD87C0500ED4D29 /* Others */ = {
isa = PBXGroup;
children = (
28C2DA6A96B596294158B364 /* HippyDemoViewController.h */,
9EB0CD5FCC3F38E3C7DC5E00 /* HippyDemoViewController.m */,
D2EE3455BE6DD7D2ADA20093 /* main.m */,
EF558AABDC113B410B8ED69C /* AppDelegate.h */,
6094F1F80FD70F9F9853EE15 /* AppDelegate.m */,
09FA8898DDD429EC19584446 /* SettingsPage */,
73EF815F203E15B86205DFC3 /* PageManager */,
4CF6648308C60D57DD274D30 /* HomePage */,
6045C301C6CFDC6C2E87AA66 /* IconUtils.h */,
17AB7FB6346FE861C9D953F5 /* IconUtils.m */,
427F60D1B98DA953328F4E71 /* DemoBaseViewController.h */,
4708C41E8571123282E2B806 /* DemoBaseViewController.m */,
80D715362B1A0B0DCEAA813D /* DemoNavigationViewController.h */,
16348E2DEBFF10ADD6FCF7A9 /* DemoNavigationViewController.m */,
DDD052D2760E830B1E0095EA /* UIViewController+Title.h */,
C412B5D210F1E3359523628C /* UIViewController+Title.m */,
);
path = RenderPage;
name = Others;
sourceTree = "<group>";
};
73EF815F203E15B86205DFC3 /* PageManager */ = {
Expand Down Expand Up @@ -253,15 +253,15 @@
name = Frameworks;
sourceTree = "<group>";
};
DE44248AB3BFFAAE044EAB9E /* myview */ = {
DE44248AB3BFFAAE044EAB9E /* MyViewDemo */ = {
isa = PBXGroup;
children = (
16E50FF2E97E0CF6CD4B1EE1 /* MyView.h */,
90F34E176169143334EDFC28 /* MyView.m */,
73A859BDC9C3189E38FD082F /* MyViewManager.h */,
834EC46509EC221C787A9F23 /* MyViewManager.mm */,
);
path = myview;
path = MyViewDemo;
sourceTree = "<group>";
};
F3C07E1B41FBB8BA0834C6BC /* fonts */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ - (void)runHippyDemo {
delegate:self];
}

// // Config whether jsc is inspectable, Highly recommended setting,
// Config whether jsc is inspectable, Highly recommended setting,
// since inspectable of JSC is disabled by default since iOS 16.4
[bridge setInspectable:YES];
_hippyBridge = bridge;
Expand Down Expand Up @@ -203,6 +203,12 @@ - (BOOL)shouldStartInspector:(HippyBridge *)bridge {
return bridge.debugMode;
}

- (NSURL *)inspectorSourceURLForBridge:(HippyBridge *)bridge {
// You can customize to any url.
// By default, we resolve the devtools address from the debug url passed to the bridge.
return bridge.debugURL;
}


#pragma mark - Optional - HippyMethodInterceptorProtocol

Expand Down
3 changes: 1 addition & 2 deletions framework/ios/base/bridge/HippyBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,7 @@ HIPPY_EXTERN NSString *HippyBridgeModuleNameForClass(Class bridgeModuleClass);
@property (nonatomic, assign) BOOL debugMode;

/// Debug URL for devtools
/// TODO: debugURL not working ?
@property (nonatomic, strong, readonly) NSURL *debugURL;
@property (nonatomic, strong, nullable, readonly) NSURL *debugURL;

/// Sets whether the context is inspectable in Web Inspector.
/// Default value is NO.
Expand Down
3 changes: 3 additions & 0 deletions framework/ios/base/bridge/HippyBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ - (instancetype)initWithDelegate:(id<HippyBridgeDelegate>)delegate
_bundleURLs = [NSMutableArray array];
_shareOptions = [NSMutableDictionary dictionary];
_debugMode = [launchOptions[@"DebugMode"] boolValue];
if (_debugMode) {
_debugURL = bundleURL;
}
_enableTurbo = !!launchOptions[@"EnableTurbo"] ? [launchOptions[@"EnableTurbo"] boolValue] : YES;
_engineKey = executorKey.length > 0 ? executorKey : [NSString stringWithFormat:@"%p", self];
HippyLogInfo(@"HippyBridge init begin, self:%p", self);
Expand Down
7 changes: 7 additions & 0 deletions framework/ios/base/bridge/HippyBridgeDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@
*/
- (BOOL)shouldStartInspector:(HippyBridge *)bridge;

/**
* Ask delegate URL for web inspector (devtools)
*
* To use remote debugging, must implement this method.
*/
- (NSURL *)inspectorSourceURLForBridge:(HippyBridge *)bridge;

/**
* Get code cache, not working for Javascriptcore engine
*
Expand Down
5 changes: 2 additions & 3 deletions framework/ios/base/executors/HippyJSExecutor.mm
Original file line number Diff line number Diff line change
Expand Up @@ -754,8 +754,8 @@ - (NSString *)completeWSURLWithBridge:(HippyBridge *)bridge {
return @"";
}
HippyDevInfo *devInfo = [[HippyDevInfo alloc] init];
if (bridge.debugURL) {
NSURL *debugURL = bridge.debugURL;
if ([bridge.delegate respondsToSelector:@selector(inspectorSourceURLForBridge:)]) {
NSURL *debugURL = [bridge.delegate inspectorSourceURLForBridge:bridge];
devInfo.scheme = [debugURL scheme];
devInfo.ipAddress = [debugURL host];
devInfo.port = [NSString stringWithFormat:@"%@", [debugURL port]];
Expand All @@ -771,7 +771,6 @@ - (NSString *)completeWSURLWithBridge:(HippyBridge *)bridge {
}
NSString *deviceName = [[UIDevice currentDevice] name];
NSString *clientId = HippyMD5Hash([NSString stringWithFormat:@"%@%p", deviceName, bridge]);

return [devInfo assembleFullWSURLWithClientId:clientId contextName:bridge.contextName];
}

Expand Down

0 comments on commit 6ac9a5d

Please sign in to comment.