Skip to content

Commit

Permalink
chore(api): API Pigeon update (#1813)
Browse files Browse the repository at this point in the history
  • Loading branch information
Equartey authored and Travis Sheppard committed Sep 26, 2022
1 parent 93203b1 commit 92e53d4
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 27 deletions.
2 changes: 1 addition & 1 deletion packages/api/amplify_api/lib/src/native_api_plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.
//
// Autogenerated from Pigeon (v3.1.5), do not edit directly.
// Autogenerated from Pigeon (v3.2.0), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name
// @dart = 2.12
Expand Down
1 change: 1 addition & 0 deletions packages/api/amplify_api/pigeons/native_api_plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ import 'package:pigeon/pigeon.dart';

@HostApi()
abstract class NativeApiBridge {
@async
void addPlugin(List<String> authProvidersList);
}
8 changes: 1 addition & 7 deletions packages/api/amplify_api/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ dependencies:
meta: ^1.7.0
plugin_platform_interface: ^2.0.0

dependency_overrides:
# TODO(dnys1): Remove when pigeon is bumped
# https://github.com/flutter/flutter/issues/105090
analyzer: ^3.0.0


dev_dependencies:
amplify_lints:
path: ../../amplify_lints
Expand All @@ -38,7 +32,7 @@ dev_dependencies:
flutter_test:
sdk: flutter
mocktail: ^0.3.0
pigeon: ^3.1.5
pigeon: ^3.1.6

# The following section is specific to Flutter.
flutter:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ class AmplifyApi : FlutterPlugin, MethodCallHandler, NativeApiPluginBindings.Nat
)
}

override fun addPlugin(authProvidersList: MutableList<String>) {
override fun addPlugin(
authProvidersList: MutableList<String>,
result: NativeApiPluginBindings.Result<Void>
) {
try {
val authProviders = authProvidersList.map { AuthorizationType.valueOf(it) }
if (flutterAuthProviders == null) {
Expand All @@ -173,8 +176,10 @@ class AmplifyApi : FlutterPlugin, MethodCallHandler, NativeApiPluginBindings.Nat
.build()
)
logger.info("Added API plugin")
result.success(null)
} catch (e: Exception) {
logger.error(e.message)
result.error(e)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.
//
// Autogenerated from Pigeon (v3.1.5), do not edit directly.
// Autogenerated from Pigeon (v3.2.0), do not edit directly.
// See also: https://pub.dev/packages/pigeon

package com.amazonaws.amplify.amplify_api;
Expand All @@ -35,14 +35,19 @@
/** Generated class from Pigeon. */
@SuppressWarnings({"unused", "unchecked", "CodeBlock2Expr", "RedundantSuppression"})
public class NativeApiPluginBindings {

public interface Result<T> {
void success(T result);
void error(Throwable error);
}
private static class NativeApiBridgeCodec extends StandardMessageCodec {
public static final NativeApiBridgeCodec INSTANCE = new NativeApiBridgeCodec();
private NativeApiBridgeCodec() {}
}

/** Generated interface from Pigeon that represents a handler of messages from Flutter.*/
public interface NativeApiBridge {
void addPlugin(@NonNull List<String> authProvidersList);
void addPlugin(@NonNull List<String> authProvidersList, Result<Void> result);

/** The codec used by NativeApiBridge. */
static MessageCodec<Object> getCodec() {
Expand All @@ -63,13 +68,23 @@ static void setup(BinaryMessenger binaryMessenger, NativeApiBridge api) {
if (authProvidersListArg == null) {
throw new NullPointerException("authProvidersListArg unexpectedly null.");
}
api.addPlugin(authProvidersListArg);
wrapped.put("result", null);
Result<Void> resultCallback = new Result<Void>() {
public void success(Void result) {
wrapped.put("result", null);
reply.reply(wrapped);
}
public void error(Throwable error) {
wrapped.put("error", wrapError(error));
reply.reply(wrapped);
}
};

api.addPlugin(authProvidersListArg, resultCallback);
}
catch (Error | RuntimeException exception) {
wrapped.put("error", wrapError(exception));
reply.reply(wrapped);
}
reply.reply(wrapped);
});
} else {
channel.setMessageHandler(null);
Expand Down
4 changes: 2 additions & 2 deletions packages/api/amplify_api_ios/ios/Classes/NativeApiPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.
//
// Autogenerated from Pigeon (v3.1.5), do not edit directly.
// Autogenerated from Pigeon (v3.2.0), do not edit directly.
// See also: https://pub.dev/packages/pigeon
#import <Foundation/Foundation.h>
@protocol FlutterBinaryMessenger;
Expand All @@ -27,7 +27,7 @@ NS_ASSUME_NONNULL_BEGIN
NSObject<FlutterMessageCodec> *NativeApiBridgeGetCodec(void);

@protocol NativeApiBridge
- (void)addPluginAuthProvidersList:(NSArray<NSString *> *)authProvidersList error:(FlutterError *_Nullable *_Nonnull)error;
- (void)addPluginAuthProvidersList:(NSArray<NSString *> *)authProvidersList completion:(void(^)(FlutterError *_Nullable))completion;
@end

extern void NativeApiBridgeSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<NativeApiBridge> *_Nullable api);
Expand Down
10 changes: 5 additions & 5 deletions packages/api/amplify_api_ios/ios/Classes/NativeApiPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.
//
// Autogenerated from Pigeon (v3.1.5), do not edit directly.
// Autogenerated from Pigeon (v3.2.0), do not edit directly.
// See also: https://pub.dev/packages/pigeon
#import "NativeApiPlugin.h"
#import <Flutter/Flutter.h>
Expand Down Expand Up @@ -86,13 +86,13 @@ void NativeApiBridgeSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<N
binaryMessenger:binaryMessenger
codec:NativeApiBridgeGetCodec() ];
if (api) {
NSCAssert([api respondsToSelector:@selector(addPluginAuthProvidersList:error:)], @"NativeApiBridge api (%@) doesn't respond to @selector(addPluginAuthProvidersList:error:)", api);
NSCAssert([api respondsToSelector:@selector(addPluginAuthProvidersList:completion:)], @"NativeApiBridge api (%@) doesn't respond to @selector(addPluginAuthProvidersList:completion:)", api);
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
NSArray *args = message;
NSArray<NSString *> *arg_authProvidersList = GetNullableObjectAtIndex(args, 0);
FlutterError *error;
[api addPluginAuthProvidersList:arg_authProvidersList error:&error];
callback(wrapResult(nil, error));
[api addPluginAuthProvidersList:arg_authProvidersList completion:^(FlutterError *_Nullable error) {
callback(wrapResult(nil, error));
}];
}];
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class SwiftAmplifyApiPlugin: NSObject, FlutterPlugin, NativeApiBridge {
}
}

public func addPluginAuthProvidersList(_ authProvidersList: [String], error: AutoreleasingUnsafeMutablePointer<FlutterError?>) {
public func addPluginAuthProvidersList(_ authProvidersList: [String]) async -> FlutterError? {
do {
let authProviders = authProvidersList.compactMap {
AWSAuthorizationType(rawValue: $0)
Expand All @@ -79,8 +79,9 @@ public class SwiftAmplifyApiPlugin: NSObject, FlutterPlugin, NativeApiBridge {
plugin: AWSAPIPlugin(
sessionFactory: FlutterURLSessionBehaviorFactory(),
apiAuthProviderFactory: FlutterAuthProviders(authProviders)))
return nil
} catch let apiError as APIError {
error.pointee = FlutterError(
return FlutterError(
code: "APIException",
message: apiError.localizedDescription,
details: [
Expand All @@ -94,7 +95,7 @@ public class SwiftAmplifyApiPlugin: NSObject, FlutterPlugin, NativeApiBridge {
if case .amplifyAlreadyConfigured = configError {
errorCode = "AmplifyAlreadyConfiguredException"
}
error.pointee = FlutterError(
return FlutterError(
code: errorCode,
message: configError.localizedDescription,
details: [
Expand All @@ -104,7 +105,7 @@ public class SwiftAmplifyApiPlugin: NSObject, FlutterPlugin, NativeApiBridge {
]
)
} catch let e {
error.pointee = FlutterError(
return FlutterError(
code: "UNKNOWN",
message: e.localizedDescription,
details: nil
Expand Down
6 changes: 4 additions & 2 deletions packages/api/amplify_api_ios/ios/amplify_api_ios.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ The API module for Amplify Flutter.
s.dependency 'Amplify', '1.23.0'
s.dependency 'AmplifyPlugins/AWSAPIPlugin', '1.23.0'
s.dependency 'amplify_flutter_ios'
s.platform = :ios, '11.0'
s.swift_version = '5.0'

# These are needed to support async/await with pigeon
s.platform = :ios, '13.0'
s.swift_version = '5.5'

# Use a custom module map with a manually written umbrella header.
#
Expand Down

0 comments on commit 92e53d4

Please sign in to comment.