Expose isolateId for engine (flutter/engine#10823)

This commit is contained in:
Dan Field
2019-08-12 21:20:59 -07:00
committed by GitHub
parent c114e1bc54
commit 4ea3a6b031
4 changed files with 52 additions and 0 deletions

View File

@@ -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_

View File

@@ -31,6 +31,8 @@
// 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>
@@ -171,6 +173,7 @@
- (void)destroyContext {
[self resetChannels];
self.isolateId = nil;
_shell.reset();
_threadHost.Reset();
_platformViewsController.reset();
@@ -233,6 +236,13 @@
// 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

View File

@@ -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 */
@@ -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 */
@@ -162,6 +164,7 @@
248D76E222E388380012F0C1 /* ScenariosTests */ = {
isa = PBXGroup;
children = (
248FDFC322FE7CD0009CC7CD /* FlutterEngineTest.m */,
0DB781FC22EA2C0300E9B371 /* FlutterViewControllerTest.m */,
248D76E322E388380012F0C1 /* ScenariosTests.m */,
248D76E522E388380012F0C1 /* Info.plist */,
@@ -329,6 +332,7 @@
files = (
248D76E422E388380012F0C1 /* ScenariosTests.m in Sources */,
0DB7820222EA493B00E9B371 /* FlutterViewControllerTest.m in Sources */,
248FDFC422FE7CD0009CC7CD /* FlutterEngineTest.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@@ -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