Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit e228939

Browse files
authored
Expose isolateId for engine (#10823)
1 parent a18fa37 commit e228939

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,13 @@ FLUTTER_EXPORT
242242
*/
243243
@property(nonatomic, readonly) NSObject<FlutterBinaryMessenger>* binaryMessenger;
244244

245+
/**
246+
* The UI Isolate ID of of the engine.
247+
*
248+
* This property will be nil if the engine is not running.
249+
*/
250+
@property(nonatomic, readonly, copy) NSString* isolateId;
251+
245252
@end
246253

247254
#endif // FLUTTER_FLUTTERENGINE_H_

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ @interface FlutterEngine () <FlutterTextInputDelegate, FlutterBinaryMessenger>
3131
// Maintains a dictionary of plugin names that have registered with the engine. Used by
3232
// FlutterEngineRegistrar to implement a FlutterPluginRegistrar.
3333
@property(nonatomic, readonly) NSMutableDictionary* pluginPublications;
34+
35+
@property(nonatomic, readwrite, copy) NSString* isolateId;
3436
@end
3537

3638
@interface FlutterEngineRegistrar : NSObject <FlutterPluginRegistrar>
@@ -171,6 +173,7 @@ - (void)notifyViewControllerDeallocated {
171173

172174
- (void)destroyContext {
173175
[self resetChannels];
176+
self.isolateId = nil;
174177
_shell.reset();
175178
_threadHost.Reset();
176179
_platformViewsController.reset();
@@ -233,6 +236,13 @@ - (void)resetChannels {
233236
// Channels get a reference to the engine, and therefore need manual
234237
// cleanup for proper collection.
235238
- (void)setupChannels {
239+
// This will be invoked once the shell is done setting up and the isolate ID
240+
// for the UI isolate is available.
241+
[_binaryMessenger setMessageHandlerOnChannel:@"flutter/isolate"
242+
binaryMessageHandler:^(NSData* message, FlutterBinaryReply reply) {
243+
self.isolateId = [[FlutterStringCodec sharedInstance] decode:message];
244+
}];
245+
236246
_localizationChannel.reset([[FlutterMethodChannel alloc]
237247
initWithName:@"flutter/localization"
238248
binaryMessenger:self.binaryMessenger

testing/scenario_app/ios/Scenarios/Scenarios.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
248D76DA22E388380012F0C1 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 248D76D922E388380012F0C1 /* main.m */; };
2424
248D76E422E388380012F0C1 /* ScenariosTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 248D76E322E388380012F0C1 /* ScenariosTests.m */; };
2525
248D76EF22E388380012F0C1 /* ScenariosUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = 248D76EE22E388380012F0C1 /* ScenariosUITests.m */; };
26+
248FDFC422FE7CD0009CC7CD /* FlutterEngineTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 248FDFC322FE7CD0009CC7CD /* FlutterEngineTest.m */; };
2627
/* End PBXBuildFile section */
2728

2829
/* Begin PBXContainerItemProxy section */
@@ -95,6 +96,7 @@
9596
248D76EA22E388380012F0C1 /* ScenariosUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ScenariosUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
9697
248D76EE22E388380012F0C1 /* ScenariosUITests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ScenariosUITests.m; sourceTree = "<group>"; };
9798
248D76F022E388380012F0C1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
99+
248FDFC322FE7CD0009CC7CD /* FlutterEngineTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FlutterEngineTest.m; sourceTree = "<group>"; };
98100
/* End PBXFileReference section */
99101

100102
/* Begin PBXFrameworksBuildPhase section */
@@ -162,6 +164,7 @@
162164
248D76E222E388380012F0C1 /* ScenariosTests */ = {
163165
isa = PBXGroup;
164166
children = (
167+
248FDFC322FE7CD0009CC7CD /* FlutterEngineTest.m */,
165168
0DB781FC22EA2C0300E9B371 /* FlutterViewControllerTest.m */,
166169
248D76E322E388380012F0C1 /* ScenariosTests.m */,
167170
248D76E522E388380012F0C1 /* Info.plist */,
@@ -329,6 +332,7 @@
329332
files = (
330333
248D76E422E388380012F0C1 /* ScenariosTests.m in Sources */,
331334
0DB7820222EA493B00E9B371 /* FlutterViewControllerTest.m in Sources */,
335+
248FDFC422FE7CD0009CC7CD /* FlutterEngineTest.m in Sources */,
332336
);
333337
runOnlyForDeploymentPostprocessing = 0;
334338
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#import <Flutter/Flutter.h>
6+
#import <XCTest/XCTest.h>
7+
#import "AppDelegate.h"
8+
9+
@interface FlutterEngineTest : XCTestCase
10+
@end
11+
12+
@implementation FlutterEngineTest
13+
14+
- (void)testIsolateId {
15+
FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test" project:nil];
16+
XCTAssertNil(engine.isolateId);
17+
[self keyValueObservingExpectationForObject:engine keyPath:@"isolateId" handler:nil];
18+
19+
XCTAssertTrue([engine runWithEntrypoint:nil]);
20+
21+
[self waitForExpectationsWithTimeout:30.0 handler:nil];
22+
23+
XCTAssertNotNil(engine.isolateId);
24+
XCTAssertTrue([engine.isolateId hasPrefix:@"isolates/"]);
25+
26+
[engine destroyContext];
27+
28+
XCTAssertNil(engine.isolateId);
29+
}
30+
31+
@end

0 commit comments

Comments
 (0)