Skip to content

Commit 04b74bd

Browse files
Convert plugins to Swift-based
Updates the example, testbed, and plugins on macOS to account for flutter/flutter#33997 example_plugin is now entirely Swift, with the ObjC wrapper removed; the other plugins remain ObjC for now, with a Swift wrapper. The podspecs have been adjusted to remove the public ObjC headers. The example has been switched from an empty ObjC registrant to an empty Swift registrant, and testbed has been updated with the results of re-running `flutter run` with the new tooling support, and switched to calling the Swift registrant as well.
1 parent 045ce4a commit 04b74bd

32 files changed

+130
-135
lines changed

example/macos/ExampleWindow.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ExampleWindow: NSWindow {
1818
@IBOutlet weak var flutterViewController: FLEViewController!
1919

2020
override func awakeFromNib() {
21-
GeneratedPluginRegistrant.register(with: flutterViewController)
21+
RegisterGeneratedPlugins(registry: flutterViewController)
2222

2323
let assets = NSURL.fileURL(withPath: "flutter_assets", relativeTo: Bundle.main.resourceURL)
2424
var arguments: [String] = [];

example/macos/Flutter/GeneratedPluginRegistrant.h

Lines changed: 0 additions & 14 deletions
This file was deleted.

example/macos/Flutter/GeneratedPluginRegistrant.m

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//
2+
// Generated file. Do not edit.
3+
//
4+
import Foundation
5+
import FlutterMacOS
6+
7+
8+
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
9+
}

example/macos/Runner-Bridging-Header.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,3 @@
1313
// limitations under the License.
1414

1515
#import <FlutterMacOS/FlutterMacOS.h>
16-
17-
#import "GeneratedPluginRegistrant.h"

example/macos/Runner.xcodeproj/project.pbxproj

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
/* End PBXAggregateTarget section */
2222

2323
/* Begin PBXBuildFile section */
24+
335BBD1B22A9A15E00E9071D /* GeneratedPluginRegistrant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */; };
2425
33CC10F12044A3C60003C045 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CC10F02044A3C60003C045 /* AppDelegate.swift */; };
2526
33CC10F32044A3C60003C045 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F22044A3C60003C045 /* Assets.xcassets */; };
2627
33CC10F62044A3C60003C045 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F42044A3C60003C045 /* MainMenu.xib */; };
2728
33CC11132044BFA00003C045 /* ExampleWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CC11122044BFA00003C045 /* ExampleWindow.swift */; };
2829
33CC112F204626C80003C045 /* flutter_assets in Resources */ = {isa = PBXBuildFile; fileRef = 33CC112C20461AD40003C045 /* flutter_assets */; };
2930
33D1A10422148B71006C7A3E /* FlutterMacOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 33D1A10322148B71006C7A3E /* FlutterMacOS.framework */; };
3031
33D1A10522148B93006C7A3E /* FlutterMacOS.framework in Bundle Framework */ = {isa = PBXBuildFile; fileRef = 33D1A10322148B71006C7A3E /* FlutterMacOS.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
31-
33D47B2422A09D2000D05F4F /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 33D47B2322A09D2000D05F4F /* GeneratedPluginRegistrant.m */; };
3232
/* End PBXBuildFile section */
3333

3434
/* Begin PBXContainerItemProxy section */
@@ -56,6 +56,7 @@
5656
/* End PBXCopyFilesBuildPhase section */
5757

5858
/* Begin PBXFileReference section */
59+
335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneratedPluginRegistrant.swift; sourceTree = "<group>"; };
5960
33CC10ED2044A3C60003C045 /* Flutter Desktop Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Flutter Desktop Example.app"; sourceTree = BUILT_PRODUCTS_DIR; };
6061
33CC10F02044A3C60003C045 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
6162
33CC10F22044A3C60003C045 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
@@ -68,8 +69,6 @@
6869
33CEB47422A05771004F2AC0 /* Flutter-Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Flutter-Release.xcconfig"; sourceTree = "<group>"; };
6970
33CEB47722A0578A004F2AC0 /* Flutter-Generated.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = "Flutter-Generated.xcconfig"; path = "ephemeral/Flutter-Generated.xcconfig"; sourceTree = "<group>"; };
7071
33D1A10322148B71006C7A3E /* FlutterMacOS.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = FlutterMacOS.framework; path = Flutter/ephemeral/FlutterMacOS.framework; sourceTree = SOURCE_ROOT; };
71-
33D47B2222A09D2000D05F4F /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
72-
33D47B2322A09D2000D05F4F /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
7372
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Configs/Release.xcconfig; sourceTree = "<group>"; };
7473
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Configs/Debug.xcconfig; sourceTree = "<group>"; };
7574
/* End PBXFileReference section */
@@ -130,8 +129,7 @@
130129
33CEB47122A05771004F2AC0 /* Flutter */ = {
131130
isa = PBXGroup;
132131
children = (
133-
33D47B2222A09D2000D05F4F /* GeneratedPluginRegistrant.h */,
134-
33D47B2322A09D2000D05F4F /* GeneratedPluginRegistrant.m */,
132+
335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */,
135133
33CEB47222A05771004F2AC0 /* Flutter-Debug.xcconfig */,
136134
33CEB47422A05771004F2AC0 /* Flutter-Release.xcconfig */,
137135
33CEB47722A0578A004F2AC0 /* Flutter-Generated.xcconfig */,
@@ -256,7 +254,7 @@
256254
files = (
257255
33CC11132044BFA00003C045 /* ExampleWindow.swift in Sources */,
258256
33CC10F12044A3C60003C045 /* AppDelegate.swift in Sources */,
259-
33D47B2422A09D2000D05F4F /* GeneratedPluginRegistrant.m in Sources */,
257+
335BBD1B22A9A15E00E9071D /* GeneratedPluginRegistrant.swift in Sources */,
260258
);
261259
runOnlyForDeploymentPostprocessing = 0;
262260
};
@@ -403,7 +401,7 @@
403401
COMBINE_HIDPI_IMAGES = YES;
404402
DEVELOPMENT_TEAM = "";
405403
FRAMEWORK_SEARCH_PATHS = (
406-
"$PROJECT_DIR/Flutter/ephemeral",
404+
$PROJECT_DIR/Flutter/ephemeral,
407405
"$(inherited)",
408406
);
409407
INFOPLIST_FILE = Info.plist;
@@ -426,7 +424,7 @@
426424
COMBINE_HIDPI_IMAGES = YES;
427425
DEVELOPMENT_TEAM = "";
428426
FRAMEWORK_SEARCH_PATHS = (
429-
"$PROJECT_DIR/Flutter/ephemeral",
427+
$PROJECT_DIR/Flutter/ephemeral,
430428
"$(inherited)",
431429
);
432430
INFOPLIST_FILE = Info.plist;

plugins/example_plugin/macos/Classes/ExamplePlugin.m renamed to plugins/color_panel/macos/Classes/ColorPanelPlugin.swift

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#import "ExamplePlugin.h"
15+
import FlutterMacOS
16+
import Foundation
1617

17-
#import <example_plugin/example_plugin-Swift.h>
18-
19-
@implementation FDEExamplePlugin
20-
21-
+ (void)registerWithRegistrar:(id<FlutterPluginRegistrar>)registrar {
22-
[SwiftExamplePlugin registerWithRegistrar:registrar];
18+
public class ColorPanelPlugin: NSObject, FlutterPlugin {
19+
public static func register(with registrar: FlutterPluginRegistrar) {
20+
FLEColorPanelPlugin.register(with: registrar)
21+
}
2322
}
24-
25-
@end

plugins/color_panel/macos/Classes/ColorPanelPlugin.m renamed to plugins/color_panel/macos/Classes/FLEColorPanelPlugin.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#import "ColorPanelPlugin.h"
15+
#import "FLEColorPanelPlugin.h"
1616

1717
#import <AppKit/AppKit.h>
1818

plugins/color_panel/macos/color_panel.podspec

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
Pod::Spec.new do |s|
55
s.name = 'color_panel'
6-
s.version = '0.0.1'
6+
s.version = '0.0.2'
77
s.summary = 'Provides access to the macOS color picker.'
88
s.description = <<-DESC
99
Provides access to the macOS color picker.
@@ -13,10 +13,9 @@ Provides access to the macOS color picker.
1313
s.author = { 'Flutter Desktop Embedding Developers' => 'flutter-desktop-embedding-dev@googlegroups.com' }
1414
s.source = { :path => '.' }
1515
s.source_files = 'Classes/**/*'
16-
s.public_header_files = 'Classes/**/*.h'
1716
s.dependency 'FlutterMacOS'
1817

1918
s.platform = :osx
20-
s.osx.deployment_target = '10.9'
19+
s.osx.deployment_target = '10.12'
2120
end
2221

plugins/example_plugin/macos/Classes/SwiftExamplePlugin.swift renamed to plugins/example_plugin/macos/Classes/ExamplePlugin.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
import FlutterMacOS
1616
import Cocoa
1717

18-
public class SwiftExamplePlugin: NSObject, FlutterPlugin {
18+
public class ExamplePlugin: NSObject, FlutterPlugin {
1919
public static func register(with registrar: FlutterPluginRegistrar) {
2020
let channel = FlutterMethodChannel(name: "example_plugin", binaryMessenger: registrar.messenger)
21-
let instance = SwiftExamplePlugin()
21+
let instance = ExamplePlugin()
2222
registrar.addMethodCallDelegate(instance, channel: channel)
2323
}
2424

plugins/example_plugin/macos/example_plugin.podspec

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
Pod::Spec.new do |s|
55
s.name = 'example_plugin'
6-
s.version = '0.0.2'
6+
s.version = '0.0.3'
77
s.summary = 'A new flutter plugin project.'
88
s.description = <<-DESC
99
A new flutter plugin project.
@@ -13,10 +13,9 @@ A new flutter plugin project.
1313
s.author = { 'Your Company' => 'email@example.com' }
1414
s.source = { :path => '.' }
1515
s.source_files = 'Classes/**/*'
16-
s.public_header_files = 'Classes/**/*.h'
1716
s.dependency 'FlutterMacOS'
1817

1918
s.platform = :osx
20-
s.osx.deployment_target = '10.9'
19+
s.osx.deployment_target = '10.12'
2120
end
2221

plugins/example_plugin/pubspec.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ homepage:
66

77
flutter:
88
plugin:
9-
macosPrefix: FDE
9+
# Currently macosPrefix is used to indicate macOS support, but the value is
10+
# not actually used. See https://github.com/flutter/flutter/issues/33597
11+
macosPrefix: unused
1012
pluginClass: ExamplePlugin
1113

1214
environment:

plugins/file_chooser/macos/Classes/FileChooserPlugin.m renamed to plugins/file_chooser/macos/Classes/FLEFileChooserPlugin.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#import "FileChooserPlugin.h"
15+
#import "FLEFileChooserPlugin.h"
1616

1717
#import <AppKit/AppKit.h>
1818

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import FlutterMacOS
16+
import Foundation
17+
18+
public class FileChooserPlugin: NSObject, FlutterPlugin {
19+
public static func register(with registrar: FlutterPluginRegistrar) {
20+
FLEFileChooserPlugin.register(with: registrar)
21+
}
22+
}

plugins/file_chooser/macos/file_chooser.podspec

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
Pod::Spec.new do |s|
55
s.name = 'file_chooser'
6-
s.version = '0.0.1'
6+
s.version = '0.0.2'
77
s.summary = 'Displays macOS open and save panels.'
88
s.description = <<-DESC
99
Displays macOS open and save panels.
@@ -13,10 +13,9 @@ Displays macOS open and save panels.
1313
s.author = { 'Flutter Desktop Embedding Developers' => 'flutter-desktop-embedding-dev@googlegroups.com' }
1414
s.source = { :path => '.' }
1515
s.source_files = 'Classes/**/*'
16-
s.public_header_files = 'Classes/**/*.h'
1716
s.dependency 'FlutterMacOS'
1817

1918
s.platform = :osx
20-
s.osx.deployment_target = '10.9'
19+
s.osx.deployment_target = '10.12'
2120
end
2221

plugins/menubar/macos/Classes/MenubarPlugin.m renamed to plugins/menubar/macos/Classes/FLEMenubarPlugin.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#import "MenubarPlugin.h"
15+
#import "FLEMenubarPlugin.h"
1616

1717
// See menu_channel.dart for documentation.
1818
static NSString *const kChannelName = @"flutter/menubar";

plugins/example_plugin/macos/Classes/ExamplePlugin.h renamed to plugins/menubar/macos/Classes/MenubarPlugin.swift

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#import <Foundation/Foundation.h>
15+
import FlutterMacOS
16+
import Foundation
1617

17-
#import <FlutterMacOS/FlutterMacOS.h>
18-
19-
/**
20-
* An example Flutter plugin for macOS.
21-
*/
22-
@interface FDEExamplePlugin : NSObject <FlutterPlugin>
23-
24-
@end
18+
public class MenubarPlugin: NSObject, FlutterPlugin {
19+
public static func register(with registrar: FlutterPluginRegistrar) {
20+
FLEMenubarPlugin.register(with: registrar)
21+
}
22+
}

plugins/menubar/macos/menubar.podspec

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
Pod::Spec.new do |s|
55
s.name = 'menubar'
6-
s.version = '0.0.1'
6+
s.version = '0.0.2'
77
s.summary = 'Provides the ability to add menubar items with Dart callbacks.'
88
s.description = <<-DESC
99
Provides the ability to add menubar items with Dart callbacks.
@@ -13,10 +13,9 @@ Provides the ability to add menubar items with Dart callbacks.
1313
s.author = { 'Flutter Desktop Embedding Developers' => 'flutter-desktop-embedding-dev@googlegroups.com' }
1414
s.source = { :path => '.' }
1515
s.source_files = 'Classes/**/*'
16-
s.public_header_files = 'Classes/**/*.h'
1716
s.dependency 'FlutterMacOS'
1817

1918
s.platform = :osx
20-
s.osx.deployment_target = '10.9'
19+
s.osx.deployment_target = '10.12'
2120
end
2221

plugins/window_size/macos/Classes/WindowSizePlugin.m renamed to plugins/window_size/macos/Classes/FLEWindowSizePlugin.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#import "WindowSizePlugin.h"
15+
#import "FLEWindowSizePlugin.h"
1616

1717
#import <AppKit/AppKit.h>
1818

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import FlutterMacOS
16+
import Foundation
17+
18+
public class WindowSizePlugin: NSObject, FlutterPlugin {
19+
public static func register(with registrar: FlutterPluginRegistrar) {
20+
FLEWindowSizePlugin.register(with: registrar)
21+
}
22+
}

plugins/window_size/macos/window_size.podspec

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
Pod::Spec.new do |s|
55
s.name = 'window_size'
6-
s.version = '0.0.1'
6+
s.version = '0.0.2'
77
s.summary = 'Allows resizing and repositioning the window containing Flutter.'
88
s.description = <<-DESC
99
Allows resizing and repositioning the window containing Flutter.
@@ -13,10 +13,9 @@ Allows resizing and repositioning the window containing Flutter.
1313
s.author = { 'Flutter Desktop Embedding Developers' => 'flutter-desktop-embedding-dev@googlegroups.com' }
1414
s.source = { :path => '.' }
1515
s.source_files = 'Classes/**/*'
16-
s.public_header_files = 'Classes/**/*.h'
1716
s.dependency 'FlutterMacOS'
1817

1918
s.platform = :osx
20-
s.osx.deployment_target = '10.9'
19+
s.osx.deployment_target = '10.12'
2120
end
2221

testbed/macos/Flutter/GeneratedPluginRegistrant.h

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)