Skip to content

Commit

Permalink
[iOS] Make FlutterInit redundant and deprecate the same. (flutter#3377)
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmaygarde authored Jan 31, 2017
1 parent e5c05a8 commit 25791da
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 23 deletions.
4 changes: 1 addition & 3 deletions shell/platform/darwin/common/platform_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

namespace shell {

void PlatformMacMain(int argc,
const char* argv[],
std::string icu_data_path,
void PlatformMacMain(std::string icu_data_path,
std::string application_library_path);

bool AttemptLaunchFromCommandLineSwitches(Engine* engine);
Expand Down
27 changes: 18 additions & 9 deletions shell/platform/darwin/common/platform_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,22 @@ static void RedirectIOConnectionsToSyslog() {
#endif
}

static void InitializeCommandLine() {
base::mac::ScopedNSAutoreleasePool pool;
base::CommandLine::StringVector vector;

for (NSString* arg in [NSProcessInfo processInfo].arguments) {
vector.emplace_back(arg.UTF8String);
}

base::CommandLine::Init(0, nullptr);
base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
command_line.InitFromArgv(vector);
}

class EmbedderState {
public:
EmbedderState(int argc,
const char* argv[],
std::string icu_data_path,
EmbedderState(std::string icu_data_path,
std::string application_library_path) {
#if TARGET_OS_IPHONE
// This calls crashes on MacOS because we haven't run Dart_Initialize yet.
Expand All @@ -64,7 +75,7 @@ static void RedirectIOConnectionsToSyslog() {
CHECK([NSThread isMainThread])
<< "Embedder initialization must occur on the main platform thread";

base::CommandLine::Init(argc, argv);
InitializeCommandLine();

RedirectIOConnectionsToSyslog();

Expand Down Expand Up @@ -109,16 +120,14 @@ static void RedirectIOConnectionsToSyslog() {
FTL_DISALLOW_COPY_AND_ASSIGN(EmbedderState);
};

void PlatformMacMain(int argc,
const char* argv[],
std::string icu_data_path,
void PlatformMacMain(std::string icu_data_path,
std::string application_library_path) {
static std::unique_ptr<EmbedderState> g_embedder;
static std::once_flag once_main;

std::call_once(once_main, [&]() {
g_embedder = WTF::MakeUnique<EmbedderState>(argc, argv, icu_data_path,
application_library_path);
g_embedder =
WTF::MakeUnique<EmbedderState>(icu_data_path, application_library_path);
});
}

Expand Down
2 changes: 1 addition & 1 deletion shell/platform/darwin/desktop/main_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void AttachMessageLoopToMainRunLoop(void) {
int main(int argc, const char* argv[]) {
[FlutterApplication sharedApplication];

shell::PlatformMacMain(argc, argv, "", "");
shell::PlatformMacMain("", "");

base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(shell::FlagForSwitch(shell::Switch::Help))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#ifndef FLUTTER_FLUTTERVIEWCONTROLLER_H_
#define FLUTTER_FLUTTERVIEWCONTROLLER_H_

#include <sys/cdefs.h>
#import <UIKit/UIKit.h>
#include <sys/cdefs.h>

#include "FlutterAsyncMessageListener.h"
#include "FlutterDartProject.h"
Expand All @@ -24,23 +24,27 @@ FLUTTER_EXPORT
- (void)sendString:(NSString*)message withMessageName:(NSString*)messageName;

- (void)sendString:(NSString*)message
withMessageName:(NSString*)messageName
callback:(void (^)(NSString*))callback;
withMessageName:(NSString*)messageName
callback:(void (^)(NSString*))callback;

- (void)addMessageListener:(NSObject<FlutterMessageListener>*)listener;

- (void)removeMessageListener:(NSObject<FlutterMessageListener>*)listener;

- (void)addAsyncMessageListener:(NSObject<FlutterAsyncMessageListener>*)listener;
- (void)addAsyncMessageListener:
(NSObject<FlutterAsyncMessageListener>*)listener;

- (void)removeAsyncMessageListener:(NSObject<FlutterAsyncMessageListener>*)listener;
- (void)removeAsyncMessageListener:
(NSObject<FlutterAsyncMessageListener>*)listener;

@end

__BEGIN_DECLS

// Initializes Flutter for this process. Need only be called once per process.
FLUTTER_EXPORT void FlutterInit(int argc, const char* argv[]);
FLUTTER_EXPORT void FlutterInit(int argc, const char* argv[])
__attribute__((deprecated("This call is no longer necessary and will be "
"removed in an upcoming release.")));

__END_DECLS

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,15 @@ @interface FlutterViewController ()<UIAlertViewDelegate,
@end

void FlutterInit(int argc, const char* argv[]) {
// Deprecated. To be removed.
}

static void FlutterInitShell() {
NSBundle* bundle = [NSBundle bundleForClass:[FlutterViewController class]];
NSString* icuDataPath = [bundle pathForResource:@"icudtl" ofType:@"dat"];
NSString* libraryName =
[[NSBundle mainBundle] objectForInfoDictionaryKey:@"FLTLibraryPath"];
shell::PlatformMacMain(argc, argv, icuDataPath.UTF8String,
shell::PlatformMacMain(icuDataPath.UTF8String,
libraryName != nil ? libraryName.UTF8String : "");
}

Expand All @@ -82,6 +86,8 @@ @implementation FlutterViewController {
- (instancetype)initWithProject:(FlutterDartProject*)project
nibName:(NSString*)nibNameOrNil
bundle:(NSBundle*)nibBundleOrNil {
FlutterInitShell();

self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

if (self) {
Expand Down Expand Up @@ -111,6 +117,7 @@ - (instancetype)initWithCoder:(NSCoder*)aDecoder {
- (void)performCommonViewControllerInitialization {
if (_initialized)
return;

_initialized = YES;

_orientationPreferences = UIInterfaceOrientationMaskAll;
Expand Down Expand Up @@ -342,7 +349,7 @@ - (void)updateViewportMetrics {
}

- (bool)isWindowFullscreen {
UIWindow *window = self.view.window;
UIWindow* window = self.view.window;
return CGRectEqualToRect(window.frame, window.screen.bounds);
}

Expand All @@ -357,11 +364,12 @@ - (CGFloat)statusBarPadding {
return 0.0;
}

UIScreen *screen = self.view.window.screen;
UIScreen* screen = self.view.window.screen;
CGRect statusFrame = [UIApplication sharedApplication].statusBarFrame;
CGRect viewFrame = [self.view convertRect:self.view.bounds
toCoordinateSpace:screen.coordinateSpace];
CGFloat padding = statusFrame.origin.y + statusFrame.size.height - viewFrame.origin.y;
CGFloat padding =
statusFrame.origin.y + statusFrame.size.height - viewFrame.origin.y;
return MAX(padding, 0.0);
}

Expand Down

0 comments on commit 25791da

Please sign in to comment.