Skip to content

Commit

Permalink
Expose isolateId for engine (flutter#10823)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnfield committed Aug 13, 2019
1 parent a18fa37 commit e228939
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
7 changes: 7 additions & 0 deletions shell/platform/darwin/ios/framework/Headers/FlutterEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,13 @@ FLUTTER_EXPORT
*/
@property(nonatomic, readonly) NSObject<FlutterBinaryMessenger>* binaryMessenger;

/**
* The UI Isolate ID of of the engine.
*
* This property will be nil if the engine is not running.
*/
@property(nonatomic, readonly, copy) NSString* isolateId;

@end

#endif // FLUTTER_FLUTTERENGINE_H_
10 changes: 10 additions & 0 deletions shell/platform/darwin/ios/framework/Source/FlutterEngine.mm
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ @interface FlutterEngine () <FlutterTextInputDelegate, FlutterBinaryMessenger>
// Maintains a dictionary of plugin names that have registered with the engine. Used by
// FlutterEngineRegistrar to implement a FlutterPluginRegistrar.
@property(nonatomic, readonly) NSMutableDictionary* pluginPublications;

@property(nonatomic, readwrite, copy) NSString* isolateId;
@end

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

- (void)destroyContext {
[self resetChannels];
self.isolateId = nil;
_shell.reset();
_threadHost.Reset();
_platformViewsController.reset();
Expand Down Expand Up @@ -233,6 +236,13 @@ - (void)resetChannels {
// Channels get a reference to the engine, and therefore need manual
// cleanup for proper collection.
- (void)setupChannels {
// This will be invoked once the shell is done setting up and the isolate ID
// for the UI isolate is available.
[_binaryMessenger setMessageHandlerOnChannel:@"flutter/isolate"
binaryMessageHandler:^(NSData* message, FlutterBinaryReply reply) {
self.isolateId = [[FlutterStringCodec sharedInstance] decode:message];
}];

_localizationChannel.reset([[FlutterMethodChannel alloc]
initWithName:@"flutter/localization"
binaryMessenger:self.binaryMessenger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
248D76DA22E388380012F0C1 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 248D76D922E388380012F0C1 /* main.m */; };
248D76E422E388380012F0C1 /* ScenariosTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 248D76E322E388380012F0C1 /* ScenariosTests.m */; };
248D76EF22E388380012F0C1 /* ScenariosUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = 248D76EE22E388380012F0C1 /* ScenariosUITests.m */; };
248FDFC422FE7CD0009CC7CD /* FlutterEngineTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 248FDFC322FE7CD0009CC7CD /* FlutterEngineTest.m */; };
/* End PBXBuildFile section */

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

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -162,6 +164,7 @@
248D76E222E388380012F0C1 /* ScenariosTests */ = {
isa = PBXGroup;
children = (
248FDFC322FE7CD0009CC7CD /* FlutterEngineTest.m */,
0DB781FC22EA2C0300E9B371 /* FlutterViewControllerTest.m */,
248D76E322E388380012F0C1 /* ScenariosTests.m */,
248D76E522E388380012F0C1 /* Info.plist */,
Expand Down Expand Up @@ -329,6 +332,7 @@
files = (
248D76E422E388380012F0C1 /* ScenariosTests.m in Sources */,
0DB7820222EA493B00E9B371 /* FlutterViewControllerTest.m in Sources */,
248FDFC422FE7CD0009CC7CD /* FlutterEngineTest.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import <Flutter/Flutter.h>
#import <XCTest/XCTest.h>
#import "AppDelegate.h"

@interface FlutterEngineTest : XCTestCase
@end

@implementation FlutterEngineTest

- (void)testIsolateId {
FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test" project:nil];
XCTAssertNil(engine.isolateId);
[self keyValueObservingExpectationForObject:engine keyPath:@"isolateId" handler:nil];

XCTAssertTrue([engine runWithEntrypoint:nil]);

[self waitForExpectationsWithTimeout:30.0 handler:nil];

XCTAssertNotNil(engine.isolateId);
XCTAssertTrue([engine.isolateId hasPrefix:@"isolates/"]);

[engine destroyContext];

XCTAssertNil(engine.isolateId);
}

@end

0 comments on commit e228939

Please sign in to comment.