Skip to content

Commit

Permalink
Merge pull request #5 from autopilot3/feat/widget-promise
Browse files Browse the repository at this point in the history
add callback for widget
  • Loading branch information
scrummitch authored Oct 11, 2024
2 parents 082a7c6 + 65f885b commit 42654bb
Show file tree
Hide file tree
Showing 17 changed files with 117 additions and 34 deletions.
7 changes: 7 additions & 0 deletions ortto_flutter_sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.3.3
* Updates iOS SDK to v1.6.2
* Returns Future<WidgetResult> instead of void for showWidget(widgetId)

## 0.3.2
- Update Native iOS SDK to v1.5.9

## 0.3.1
- Update Flutter Android SDK to v1.6.4
- Update Flutter iOS SDK to v1.5.8
Expand Down
3 changes: 2 additions & 1 deletion ortto_flutter_sdk/lib/ortto_flutter_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export 'package:ortto_flutter_sdk_platform_interface/src/models/ortto_config.dar
export 'package:ortto_flutter_sdk_platform_interface/src/models/push_permission.dart';
export 'package:ortto_flutter_sdk_platform_interface/src/models/user_id.dart';
export 'package:ortto_flutter_sdk_platform_interface/src/models/identity_result.dart';
export 'package:ortto_flutter_sdk_platform_interface/src/models/widget_result.dart';


class Ortto {
Expand Down Expand Up @@ -61,7 +62,7 @@ class Ortto {
return _platform.registerDeviceToken(token);
}

Future<void> showWidget(String widgetId) {
Future<WidgetResult> showWidget(String widgetId) {
return _platform.showWidget(widgetId);
}

Expand Down
10 changes: 5 additions & 5 deletions ortto_flutter_sdk/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: ortto_flutter_sdk
description: Ortto Flutter SDK
version: 0.3.1
version: 0.3.3
homepage: https://ortto.com/
repository: https://github.com/autopilot3/ortto-flutter-sdk

Expand All @@ -21,16 +21,16 @@ dependencies:
firebase_messaging: ^14.6.5
flutter:
sdk: flutter
ortto_flutter_sdk_android: ^0.3.1
ortto_flutter_sdk_android: ^0.3.3
# ortto_flutter_sdk_android:
# path: ../ortto_flutter_sdk_android
ortto_flutter_sdk_platform_interface: ^0.3.0
ortto_flutter_sdk_platform_interface: ^0.3.3
# ortto_flutter_sdk_platform_interface:
# path: ../ortto_flutter_sdk_platform_interface
ortto_flutter_sdk_ios: ^0.3.1
ortto_flutter_sdk_ios: ^0.3.3
# ortto_flutter_sdk_ios:
# path: ../ortto_flutter_sdk_ios
#

dev_dependencies:
flutter_test:
sdk: flutter
Expand Down
3 changes: 3 additions & 0 deletions ortto_flutter_sdk_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.3.3
* Returns Future<WidgetResult> instead of void for showWidget(widgetId)

## 0.3.1
* Fixes an issue with base64URL decoding deep link tracking URLs
* Updates Android Java SDK to v1.6.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.ortto.messaging.data.LinkUtm
import com.ortto.messaging.identity.UserID
import com.ortto.messaging.widget.CaptureConfig
import com.ortto.messaging.PushNotificationHandler
import com.ortto.messaging.OrttoCaptureInitException

import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.embedding.engine.plugins.activity.ActivityAware
Expand Down Expand Up @@ -52,10 +53,7 @@ class OrttoFlutterSdkPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
queueWidget(call)
result.success(null)
}
"showWidget" -> {
showWidget(call)
result.success(null)
}
"showWidget" -> showWidget(call, result)
"processNextWidgetFromQueue" -> {
processNextWidgetFromQueue()
result.success(null)
Expand Down Expand Up @@ -158,8 +156,7 @@ class OrttoFlutterSdkPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
private fun trackLinkClick(call: MethodCall, result: MethodChannel.Result) {
val link = call.argument<String>("link");

Ortto.instance().trackLinkClick(link
) {
Ortto.instance().trackLinkClick(link) {
Log.d(tag, "trackLinkClick: $it")

val map = mapOf(
Expand All @@ -179,10 +176,29 @@ class OrttoFlutterSdkPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
Ortto.instance().queueWidget(widgetId);
}

private fun showWidget(call: MethodCall) {
private fun showWidget(call: MethodCall, result: MethodChannel.Result) {
val widgetId = call.argument<String>("widgetId");

Ortto.instance().showWidget(widgetId);
try {
Ortto.instance().showWidget(widgetId)

val widgetResult = mapOf(
"success" to true,
"message" to "Widget shown successfully."
)

result.success(widgetResult)
} catch (e: OrttoCaptureInitException) {
// Handle the exception here
e.printStackTrace()

val widgetResult = mapOf(
"success" to false,
"message" to e.message
)

result.success(widgetResult)
}
}

private fun processNextWidgetFromQueue() {
Expand Down
4 changes: 2 additions & 2 deletions ortto_flutter_sdk_android/lib/ortto_flutter_sdk_android.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ class FlutterOrttoPushSdkAndroid extends OrttoFlutterSdkPlatformInterface {
}

@override
Future<void> showWidget(String widgetId) {
Future<WidgetResult> showWidget(String widgetId) {
return methodChannel.invokeMethod('showWidget', {
'widgetId': widgetId,
});
}).then((value) => WidgetResult.fromMap(value.cast<String, dynamic>()));
}

@override
Expand Down
4 changes: 2 additions & 2 deletions ortto_flutter_sdk_android/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: ortto_flutter_sdk_android
description: Ortto Flutter SDK Android
version: 0.3.1
version: 0.3.3
homepage: https://ortto.com/
repository: https://github.com/autopilot3/ortto-flutter-sdk

Expand All @@ -19,7 +19,7 @@ flutter:
dependencies:
flutter:
sdk: flutter
ortto_flutter_sdk_platform_interface: ^0.3.0
ortto_flutter_sdk_platform_interface: ^0.3.3
# ortto_flutter_sdk_platform_interface:
# path: ../ortto_flutter_sdk_platform_interface

Expand Down
7 changes: 7 additions & 0 deletions ortto_flutter_sdk_ios/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.3.3
* Updates iOS SDK to v1.6.2
* Returns Future<WidgetResult> instead of void for showWidget(widgetId)

## 0.3.2
* Update Ortto SDK to v1.5.9 which fixes an issue with registering nil push tokens

## 0.3.1
* Fixes an issue with base64URL decoding deep link tracking URLs
* Updates iOS Swift SDK to v1.5.8
Expand Down
36 changes: 31 additions & 5 deletions ortto_flutter_sdk_ios/ios/Classes/OrttoFlutterSdkPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public class OrttoFlutterSdkPlugin: NSObject, FlutterPlugin, UNUserNotificationC
queueWidget(call)
result(nil)
case "showWidget":
showWidget(call)
result(nil)
showWidget(call, result)
case "processNextWidgetFromQueue":
processNextWidgetFromQueue()
result(nil)
Expand Down Expand Up @@ -93,13 +92,40 @@ public class OrttoFlutterSdkPlugin: NSObject, FlutterPlugin, UNUserNotificationC
}
}

private func showWidget(_ call: FlutterMethodCall) {
private func showWidget(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) {
guard let args = call.arguments as? [String:Any?] else {
result(["message": "invalid_arguments", "success": false])
return
}

if let widgetId = args["widgetId"] as? String {
OrttoCapture.shared.showWidget(widgetId)
guard let widgetId = args["widgetId"] as? String else {
result(["message": "missing_widget_id", "success": false])
return
}

guard OrttoCapture.shared != nil else {
result(["message": "ortto_capture_not_initialized", "success": false])
return
}

OrttoCapture.shared.showWidget(widgetId).then { showResult in
switch showResult {
case .success:
result(["success": true])
case .failure(let error):
print("error: \(error)")
if let widgetError = error as? WidgetError {
result([
"message": widgetError.errorDescription,
"success": false
])
} else {
result([
"message": error.localizedDescription,
"success": false
])
}
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions ortto_flutter_sdk_ios/ios/ortto_flutter_sdk_ios.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'ortto_flutter_sdk_ios'
s.version = '1.5.6'
s.version = '1.6.2'
s.summary = 'OrttoSDK'
s.homepage = 'https://github.com/autopilot3/ortto-push-ios-sdk'
s.license = { :type => 'MIT', :file => 'LICENSE' }
Expand All @@ -17,7 +17,7 @@ Pod::Spec.new do |s|

# Dependencies
s.dependency 'Flutter'
s.dependency 'OrttoSDKCore', '1.5.8'
s.dependency 'OrttoInAppNotifications', '1.5.8'
s.dependency 'OrttoPushMessagingFCM', '1.5.8'
s.dependency 'OrttoSDKCore', '1.6.2'
s.dependency 'OrttoInAppNotifications', '1.6.2'
s.dependency 'OrttoPushMessagingFCM', '1.6.2'
end
4 changes: 2 additions & 2 deletions ortto_flutter_sdk_ios/lib/ortto_flutter_sdk_ios.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ class OrttoFlutterSdkIOS extends OrttoFlutterSdkPlatformInterface {
}

@override
Future<void> showWidget(String widgetId) {
Future<WidgetResult> showWidget(String widgetId) {
return methodChannel.invokeMethod("showWidget", {
'widgetId': widgetId,
});
}).then((value) => WidgetResult.fromMap(value.cast<String, dynamic>()));
}

@override
Expand Down
4 changes: 2 additions & 2 deletions ortto_flutter_sdk_ios/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: ortto_flutter_sdk_ios
description: Ortto Flutter SDK iOS
version: 0.3.1
version: 0.3.3
homepage: https://ortto.com/
repository: https://github.com/autopilot3/ortto-flutter-sdk

Expand All @@ -18,7 +18,7 @@ flutter:
dependencies:
flutter:
sdk: flutter
ortto_flutter_sdk_platform_interface: ^0.3.0
ortto_flutter_sdk_platform_interface: ^0.3.3
# ortto_flutter_sdk_platform_interface:
# path: ../ortto_flutter_sdk_platform_interface

Expand Down
6 changes: 6 additions & 0 deletions ortto_flutter_sdk_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.3.3
* Returns Future<WidgetResult> instead of void for showWidget(widgetId)

## 0.3.2
* Updates iOS SDK

## 0.3.0
* Adds `clearIdentity` method to unsubscribe from push notifications

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:ortto_flutter_sdk_platform_interface/src/models/link_utm.dart';
import 'package:ortto_flutter_sdk_platform_interface/src/models/ortto_config.dart';
import 'package:ortto_flutter_sdk_platform_interface/src/models/push_permission.dart';
import 'package:ortto_flutter_sdk_platform_interface/src/models/user_id.dart';
import 'package:ortto_flutter_sdk_platform_interface/src/models/widget_result.dart';
import 'src/models/identity_result.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';

Expand All @@ -13,6 +14,7 @@ export 'src/models/ortto_config.dart';
export 'src/models/push_permission.dart';
export 'src/models/user_id.dart';
export 'src/models/identity_result.dart';
export 'src/models/widget_result.dart';


/// The interface that implementations of flutter_ortto_push_sdk must implement.
Expand Down Expand Up @@ -65,7 +67,7 @@ abstract class OrttoFlutterSdkPlatformInterface extends PlatformInterface {

Future<void> queueWidget(String widgetId);

Future<void> showWidget(String widgetId);
Future<WidgetResult> showWidget(String widgetId);

Future<void> processNextWidgetFromQueue();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class MethodChannelOrttoFlutterSdk extends OrttoFlutterSdkPlatformInterface {
}

@override
Future<void> showWidget(String widgetId) {
Future<WidgetResult> showWidget(String widgetId) {
throw UnimplementedError();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

class WidgetResult {
bool? success;
String? message;

WidgetResult({
this.success,
this.message,
});

WidgetResult.fromMap(Map<String, dynamic> map) {
success = map['success'] as bool?;
message = map['message'] as String?;
}
}
2 changes: 1 addition & 1 deletion ortto_flutter_sdk_platform_interface/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: ortto_flutter_sdk_platform_interface
description: Ortto Flutter SDK Platform Interface
version: 0.3.0
version: 0.3.3
homepage: https://ortto.com/
repository: https://github.com/autopilot3/ortto-flutter-sdk

Expand Down

0 comments on commit 42654bb

Please sign in to comment.