From 85d050ac987fa4f21aa614b577ac2784a6656350 Mon Sep 17 00:00:00 2001 From: Alexander Aprelev Date: Wed, 10 Jan 2018 17:40:47 -0800 Subject: [PATCH] When running on iOS deduce bundle path during engine initialization. (flutter/engine#4532) --- .../shell/platform/darwin/common/platform_mac.h | 3 ++- .../shell/platform/darwin/common/platform_mac.mm | 14 ++++++++++---- .../shell/platform/darwin/desktop/main_mac.mm | 2 +- .../ios/framework/Source/flutter_main_ios.mm | 8 +++++++- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/engine/src/flutter/shell/platform/darwin/common/platform_mac.h b/engine/src/flutter/shell/platform/darwin/common/platform_mac.h index 4d2f42dfe3..1989b25f11 100644 --- a/engine/src/flutter/shell/platform/darwin/common/platform_mac.h +++ b/engine/src/flutter/shell/platform/darwin/common/platform_mac.h @@ -10,7 +10,8 @@ namespace shell { void PlatformMacMain(std::string icu_data_path, - std::string application_library_path); + std::string application_library_path, + std::string bundle_path); bool AttemptLaunchFromCommandLineSwitches(Engine* engine); diff --git a/engine/src/flutter/shell/platform/darwin/common/platform_mac.mm b/engine/src/flutter/shell/platform/darwin/common/platform_mac.mm index adfaea7fb0..4504838de0 100644 --- a/engine/src/flutter/shell/platform/darwin/common/platform_mac.mm +++ b/engine/src/flutter/shell/platform/darwin/common/platform_mac.mm @@ -31,7 +31,9 @@ static fxl::CommandLine InitializedCommandLine() { class EmbedderState { public: - EmbedderState(std::string icu_data_path, std::string application_library_path) { + EmbedderState(std::string icu_data_path, + std::string application_library_path, + std::string bundle_path) { #if TARGET_OS_IPHONE // This calls crashes on MacOS because we haven't run Dart_Initialize yet. // See https://github.com/flutter/flutter/issues/4006 @@ -46,7 +48,8 @@ class EmbedderState { // marker that can be used as a reference for startup. TRACE_EVENT_INSTANT0("flutter", "main"); - shell::Shell::InitStandalone(std::move(command_line), icu_data_path, application_library_path); + shell::Shell::InitStandalone(std::move(command_line), icu_data_path, application_library_path, + bundle_path); } ~EmbedderState() {} @@ -55,12 +58,15 @@ class EmbedderState { FXL_DISALLOW_COPY_AND_ASSIGN(EmbedderState); }; -void PlatformMacMain(std::string icu_data_path, std::string application_library_path) { +void PlatformMacMain(std::string icu_data_path, + std::string application_library_path, + std::string bundle_path) { static std::unique_ptr g_embedder; static std::once_flag once_main; std::call_once(once_main, [&]() { - g_embedder = WTF::MakeUnique(icu_data_path, application_library_path); + g_embedder = + WTF::MakeUnique(icu_data_path, application_library_path, bundle_path); }); } diff --git a/engine/src/flutter/shell/platform/darwin/desktop/main_mac.mm b/engine/src/flutter/shell/platform/darwin/desktop/main_mac.mm index 24a55f3495..c8fd14326a 100644 --- a/engine/src/flutter/shell/platform/darwin/desktop/main_mac.mm +++ b/engine/src/flutter/shell/platform/darwin/desktop/main_mac.mm @@ -16,7 +16,7 @@ int main(int argc, const char* argv[]) { [FlutterApplication sharedApplication]; - shell::PlatformMacMain("", ""); + shell::PlatformMacMain("", "", ""); const auto& command_line = shell::Shell::Shared().GetCommandLine(); diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/flutter_main_ios.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/flutter_main_ios.mm index 725af17660..cec3668d84 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/flutter_main_ios.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/flutter_main_ios.mm @@ -12,7 +12,13 @@ void FlutterMain() { NSBundle* bundle = [NSBundle bundleForClass:[FlutterViewController class]]; NSString* icuDataPath = [bundle pathForResource:@"icudtl" ofType:@"dat"]; NSString* libraryName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"FLTLibraryPath"]; - shell::PlatformMacMain(icuDataPath.UTF8String, libraryName != nil ? libraryName.UTF8String : ""); + + NSBundle* mainBundle = [NSBundle mainBundle]; + + NSString* flutterAssetsPath = [mainBundle pathForResource:@"flutter_assets" ofType:nil]; + + shell::PlatformMacMain(icuDataPath.UTF8String, libraryName != nil ? libraryName.UTF8String : "", + flutterAssetsPath.UTF8String); } } // namespace shell