Skip to content

Commit 2106e63

Browse files
authored
[macos] Adjust for embedding API type name change (#257)
flutter/engine#7567 renamed the type of the result for embedding API calls. Rather than force a Flutter upgrade by using the new type name, temporarily use 'auto' for the type (with a TODO to change it later, since auto is arguably less readable here). This requires converting the file to ObjC++, which required a few explicit casts in places that were previously being silently recast.
1 parent 96e92a9 commit 2106e63

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

library/macos/FLEViewController.m renamed to library/macos/FLEViewController.mm

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ - (BOOL)launchEngineInternalWithAssetsPath:(NSURL *)assets
297297
flutterArguments.command_line_argv = argv;
298298
flutterArguments.platform_message_callback = (FlutterPlatformMessageCallback)OnPlatformMessage;
299299

300-
FlutterResult result = FlutterEngineRun(FLUTTER_ENGINE_VERSION, &config, &flutterArguments,
300+
// TODO: Replace auto with FlutterEngineResult after next required Flutter update.
301+
auto result = FlutterEngineRun(FLUTTER_ENGINE_VERSION, &config, &flutterArguments,
301302
(__bridge void *)(self), &_engine);
302303
free(argv);
303304
if (result != kSuccess) {
@@ -350,7 +351,8 @@ - (void)handlePlatformMessage:(const FlutterPlatformMessage *)message {
350351

351352
FLEBinaryReply binaryResponseHandler = ^(NSData *response) {
352353
if (responseHandle) {
353-
FlutterEngineSendPlatformMessageResponse(self->_engine, responseHandle, response.bytes,
354+
FlutterEngineSendPlatformMessageResponse(self->_engine, responseHandle,
355+
static_cast<const uint8_t *>(response.bytes),
354356
response.length);
355357
responseHandle = NULL;
356358
} else {
@@ -376,7 +378,7 @@ - (void)dispatchMouseEvent:(NSEvent *)event phase:(FlutterPointerPhase)phase {
376378
.phase = phase,
377379
.x = locationInBackingCoordinates.x,
378380
.y = -locationInBackingCoordinates.y, // convertPointToBacking makes this negative.
379-
.timestamp = event.timestamp * NSEC_PER_MSEC,
381+
.timestamp = static_cast<const size_t>(event.timestamp * NSEC_PER_MSEC),
380382
};
381383
FlutterEngineSendPointerEvent(_engine, &flutterEvent, 1);
382384
}
@@ -386,12 +388,11 @@ - (void)dispatchKeyEvent:(NSEvent *)event ofType:(NSString *)type {
386388
@"keymap" : @"android",
387389
@"type" : type,
388390
@"keyCode" : @(event.keyCode),
389-
@"metaState" : @(
390-
((event.modifierFlags & NSEventModifierFlagShift) ? kAndroidMetaStateShift : 0) |
391-
((event.modifierFlags & NSEventModifierFlagOption) ? kAndroidMetaStateAlt : 0) |
392-
((event.modifierFlags & NSEventModifierFlagControl) ? kAndroidMetaStateCtrl : 0) |
393-
((event.modifierFlags & NSEventModifierFlagCommand) ? kAndroidMetaStateMeta : 0)
394-
)
391+
@"metaState" :
392+
@(((event.modifierFlags & NSEventModifierFlagShift) ? kAndroidMetaStateShift : 0) |
393+
((event.modifierFlags & NSEventModifierFlagOption) ? kAndroidMetaStateAlt : 0) |
394+
((event.modifierFlags & NSEventModifierFlagControl) ? kAndroidMetaStateCtrl : 0) |
395+
((event.modifierFlags & NSEventModifierFlagCommand) ? kAndroidMetaStateMeta : 0))
395396
}];
396397
}
397398

@@ -404,8 +405,8 @@ - (void)viewDidReshape:(NSOpenGLView *)view {
404405
CGRect scaledBounds = [view convertRectToBacking:view.bounds];
405406
const FlutterWindowMetricsEvent event = {
406407
.struct_size = sizeof(event),
407-
.width = scaledBounds.size.width,
408-
.height = scaledBounds.size.height,
408+
.width = static_cast<const size_t>(scaledBounds.size.width),
409+
.height = static_cast<const size_t>(scaledBounds.size.height),
409410
.pixel_ratio = scaledBounds.size.width / view.bounds.size.width,
410411
};
411412
FlutterEngineSendWindowMetricsEvent(_engine, &event);
@@ -417,11 +418,12 @@ - (void)sendOnChannel:(nonnull NSString *)channel message:(nullable NSData *)mes
417418
FlutterPlatformMessage platformMessage = {
418419
.struct_size = sizeof(FlutterPlatformMessage),
419420
.channel = [channel UTF8String],
420-
.message = message.bytes,
421+
.message = static_cast<const uint8_t *>(message.bytes),
421422
.message_size = message.length,
422423
};
423424

424-
FlutterResult result = FlutterEngineSendPlatformMessage(_engine, &platformMessage);
425+
// TODO: Replace auto with FlutterEngineResult after next required Flutter update.
426+
auto result = FlutterEngineSendPlatformMessage(_engine, &platformMessage);
425427
if (result != kSuccess) {
426428
NSLog(@"Failed to send message to Flutter engine on channel '%@' (%d).", channel, result);
427429
}

library/macos/FlutterEmbedderMac.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
1E24923C1FCF50BE00DD3BBB /* FLEReshapeListener.h in Headers */ = {isa = PBXBuildFile; fileRef = 1E2492321FCF50BE00DD3BBB /* FLEReshapeListener.h */; settings = {ATTRIBUTES = (Public, ); }; };
2727
1E24923E1FCF50BE00DD3BBB /* FLETextInputPlugin.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E2492341FCF50BE00DD3BBB /* FLETextInputPlugin.m */; };
2828
1E24923F1FCF50BE00DD3BBB /* FLEViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 1E2492351FCF50BE00DD3BBB /* FLEViewController.h */; settings = {ATTRIBUTES = (Public, ); }; };
29-
1E2492401FCF50BE00DD3BBB /* FLEViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E2492361FCF50BE00DD3BBB /* FLEViewController.m */; };
29+
1E2492401FCF50BE00DD3BBB /* FLEViewController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1E2492361FCF50BE00DD3BBB /* FLEViewController.mm */; };
3030
1E2492411FCF50BE00DD3BBB /* FlutterEmbedderMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 1E2492371FCF50BE00DD3BBB /* FlutterEmbedderMac.h */; settings = {ATTRIBUTES = (Public, ); }; };
3131
1EEF8E071FD1F0C300DD563C /* FLEView.h in Headers */ = {isa = PBXBuildFile; fileRef = 1EEF8E051FD1F0C300DD563C /* FLEView.h */; settings = {ATTRIBUTES = (Public, ); }; };
3232
1EEF8E081FD1F0C300DD563C /* FLEView.m in Sources */ = {isa = PBXBuildFile; fileRef = 1EEF8E061FD1F0C300DD563C /* FLEView.m */; };
@@ -87,7 +87,7 @@
8787
1E2492331FCF50BE00DD3BBB /* FLETextInputPlugin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLETextInputPlugin.h; sourceTree = "<group>"; };
8888
1E2492341FCF50BE00DD3BBB /* FLETextInputPlugin.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLETextInputPlugin.m; sourceTree = "<group>"; };
8989
1E2492351FCF50BE00DD3BBB /* FLEViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEViewController.h; sourceTree = "<group>"; };
90-
1E2492361FCF50BE00DD3BBB /* FLEViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEViewController.m; sourceTree = "<group>"; };
90+
1E2492361FCF50BE00DD3BBB /* FLEViewController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FLEViewController.mm; sourceTree = "<group>"; };
9191
1E2492371FCF50BE00DD3BBB /* FlutterEmbedderMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FlutterEmbedderMac.h; sourceTree = "<group>"; };
9292
1E2492381FCF50BE00DD3BBB /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
9393
1EEF8E051FD1F0C300DD563C /* FLEView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEView.h; sourceTree = "<group>"; };
@@ -148,7 +148,7 @@
148148
1E2492341FCF50BE00DD3BBB /* FLETextInputPlugin.m */,
149149
1EEF8E061FD1F0C300DD563C /* FLEView.m */,
150150
6442F82C20EA6C5F00A393AE /* FLEViewController+Internal.h */,
151-
1E2492361FCF50BE00DD3BBB /* FLEViewController.m */,
151+
1E2492361FCF50BE00DD3BBB /* FLEViewController.mm */,
152152
1E2492381FCF50BE00DD3BBB /* Info.plist */,
153153
33B1650E201A5F7400732DC9 /* Dependencies */,
154154
1E2492251FCF504200DD3BBB /* Products */,
@@ -316,7 +316,7 @@
316316
buildActionMask = 2147483647;
317317
files = (
318318
33D7B59A20A4F54400296EFC /* FLEMethodChannel.m in Sources */,
319-
1E2492401FCF50BE00DD3BBB /* FLEViewController.m in Sources */,
319+
1E2492401FCF50BE00DD3BBB /* FLEViewController.mm in Sources */,
320320
3389A68D215949CB00A27898 /* FLEMethodError.m in Sources */,
321321
33C0FA2721B84AA4008F8959 /* FLEMethodCall.m in Sources */,
322322
33C0FA2021B84810008F8959 /* FLEJSONMessageCodec.m in Sources */,

0 commit comments

Comments
 (0)