Skip to content

Commit 9d7cd70

Browse files
authored
add observatoryUrl property to FlutterEngine (#8987)
1 parent 34a5248 commit 9d7cd70

4 files changed

Lines changed: 24 additions & 5 deletions

File tree

shell/platform/darwin/ios/framework/Headers/FlutterEngine.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,15 @@ FLUTTER_EXPORT
228228
*/
229229
@property(nonatomic, readonly) FlutterBasicMessageChannel* settingsChannel;
230230

231+
/**
232+
* The `NSURL` of the observatory for the service isolate.
233+
*
234+
* This is only set in debug and profile runtime modes, and only after the
235+
* observatory service is ready. In release mode or before the observatory has
236+
* started, it returns `nil`.
237+
*/
238+
@property(nonatomic, readonly) NSURL* observatoryUrl;
239+
231240
@end
232241

233242
#endif // FLUTTER_FLUTTERENGINE_H_

shell/platform/darwin/ios/framework/Source/FlutterEngine.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ - (FlutterBasicMessageChannel*)settingsChannel {
207207
return _settingsChannel.get();
208208
}
209209

210+
- (NSURL*)observatoryUrl {
211+
return [_publisher.get() url];
212+
}
213+
210214
- (void)resetChannels {
211215
_localizationChannel.reset();
212216
_navigationChannel.reset();

shell/platform/darwin/ios/framework/Source/FlutterObservatoryPublisher.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
@interface FlutterObservatoryPublisher : NSObject
1111

12+
@property(nonatomic, readonly) NSURL* url;
13+
1214
@end
1315

1416
#endif // FLUTTER_FLUTTEROBSERVATORYPUBLISHER_H_

shell/platform/darwin/ios/framework/Source/FlutterObservatoryPublisher.mm

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ @interface FlutterObservatoryPublisher () <NSNetServiceDelegate>
3636
@end
3737

3838
@implementation FlutterObservatoryPublisher {
39+
fml::scoped_nsobject<NSURL> _url;
3940
#if TARGET_IPHONE_SIMULATOR
4041
DNSServiceRef _dnsServiceRef;
4142
#else // TARGET_IPHONE_SIMULATOR
@@ -46,6 +47,10 @@ @implementation FlutterObservatoryPublisher {
4647
std::unique_ptr<fml::WeakPtrFactory<FlutterObservatoryPublisher>> _weakFactory;
4748
}
4849

50+
- (NSURL*)url {
51+
return _url.get();
52+
}
53+
4954
- (instancetype)init {
5055
self = [super init];
5156
NSAssert(self, @"Super must not return null on init.");
@@ -92,15 +97,14 @@ - (void)publishServiceProtocolPort:(std::string)uri {
9297
}
9398
// uri comes in as something like 'http://127.0.0.1:XXXXX/' where XXXXX is the port
9499
// number.
95-
NSURL* url =
96-
[[[NSURL alloc] initWithString:[NSString stringWithUTF8String:uri.c_str()]] autorelease];
100+
_url.reset([[NSURL alloc] initWithString:[NSString stringWithUTF8String:uri.c_str()]]);
97101

98102
NSString* serviceName =
99103
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];
100104

101105
// Check to see if there's an authentication code. If there is, we'll provide
102106
// it as a txt record so flutter tools can establish a connection.
103-
auto path = std::string{[[url path] UTF8String]};
107+
auto path = std::string{[[_url path] UTF8String]};
104108
if (!path.empty()) {
105109
// Remove leading "/"
106110
path = path.substr(1);
@@ -116,7 +120,7 @@ - (void)publishServiceProtocolPort:(std::string)uri {
116120
uint32_t interfaceIndex = if_nametoindex("lo0");
117121
const char* registrationType = "_dartobservatory._tcp";
118122
const char* domain = "local."; // default domain
119-
uint16_t port = [[url port] intValue];
123+
uint16_t port = [[_url port] intValue];
120124

121125
int err = DNSServiceRegister(&_dnsServiceRef, flags, interfaceIndex, [serviceName UTF8String],
122126
registrationType, domain, NULL, htons(port), txtData.length,
@@ -131,7 +135,7 @@ - (void)publishServiceProtocolPort:(std::string)uri {
131135
NSNetService* netServiceTmp = [[NSNetService alloc] initWithDomain:@"local."
132136
type:@"_dartobservatory._tcp."
133137
name:serviceName
134-
port:[[url port] intValue]];
138+
port:[[_url port] intValue]];
135139
[netServiceTmp setTXTRecordData:txtData];
136140
_netService.reset(netServiceTmp);
137141
[_netService.get() setDelegate:self];

0 commit comments

Comments
 (0)