Skip to content

Commit

Permalink
Merge branch 'develop' into 2989-implement-passkeys
Browse files Browse the repository at this point in the history
  • Loading branch information
longbmk authored Nov 1, 2024
2 parents a158021 + 777ca46 commit 3845213
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 15 deletions.
6 changes: 3 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ Future<void> runFeralFileApp() async {
log.info('Error in AuFileService setup: $e');
}

OneSignal.shared.setLogLevel(OSLogLevel.error, OSLogLevel.none);
OneSignal.shared.setAppId(Environment.onesignalAppID);

OneSignal.initialize(Environment.onesignalAppID);
OneSignal.Debug.setLogLevel(OSLogLevel.error);
SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
statusBarColor: AppColor.white,
statusBarIconBrightness: Brightness.dark,
Expand Down
6 changes: 2 additions & 4 deletions lib/screen/home/home_navigation_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,9 @@ class HomeNavigationPageState extends State<HomeNavigationPage>

_triggerShowAnnouncement();

OneSignal.shared.setNotificationWillShowInForegroundHandler((event) {
OneSignal.Notifications.addForegroundWillDisplayListener((event) {
log.info('Receive notification: ${event.notification.additionalData}');
if (event.notification.additionalData == null) {
event.complete(null);
return;
}
final additionalData =
Expand All @@ -292,7 +291,6 @@ class HomeNavigationPageState extends State<HomeNavigationPage>

/// should complete event after getting all data needed
/// and before calling async function
event.complete(null);
Future.delayed(const Duration(milliseconds: 500), () async {
await injector<AnnouncementService>().fetchAnnouncements();
if (!mounted) {
Expand All @@ -307,7 +305,7 @@ class HomeNavigationPageState extends State<HomeNavigationPage>
);
});
});
OneSignal.shared.setNotificationOpenedHandler((openedResult) async {
OneSignal.Notifications.addClickListener((openedResult) async {
log.info('Tapped push notification: '
'${openedResult.notification.additionalData}');
final additionalData =
Expand Down
9 changes: 4 additions & 5 deletions lib/util/notification_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,16 @@ Future<bool> registerPushNotifications({bool askPermission = false}) async {
if (askPermission) {
final permission = Platform.isAndroid
? true
: await OneSignal.shared.promptUserForPushNotificationPermission();
: await OneSignal.Notifications.requestPermission(true);

if (!permission) {
return false;
}
}

try {
final identityHash = await OneSignalHelper.getIdentityHash();
final primaryAddress = await injector<AddressService>().getPrimaryAddress();
await OneSignal.shared.setExternalUserId(primaryAddress!, identityHash);
await OneSignal.login(primaryAddress!);
await injector<ConfigurationService>().setNotificationEnabled(true);
return true;
} catch (error) {
Expand All @@ -45,13 +44,13 @@ Future<bool> registerPushNotifications({bool askPermission = false}) async {

Future<void> deregisterPushNotification() async {
log.info('unregister notification');
await OneSignal.shared.removeExternalUserId();
await OneSignal.logout();
}

class OneSignalHelper {
static Future<void> setExternalUserId(
{required String userId, String? authHashToken}) async {
await OneSignal.shared.setExternalUserId(userId, authHashToken);
await OneSignal.login(userId);
}

static Future<String> getIdentityHash() async {
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1933,10 +1933,10 @@ packages:
dependency: "direct main"
description:
name: onesignal_flutter
sha256: f4e54ad09bbfc2401b5d3e9cda6b31577facf0dd119d282d008df5710f5665d0
sha256: "28e8295c1e79b029d010c6af6459683b1e1485246d95d42f13bba15ca35a94ae"
url: "https://pub.dev"
source: hosted
version: "3.5.1"
version: "5.2.6"
open_settings:
dependency: "direct main"
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ dependencies:
measured_size: ^1.0.0
mime: ^1.0.1
mixpanel_flutter: ^2.0.0
onesignal_flutter: ^3.3.0
onesignal_flutter: ^5.2.6
open_settings: ^2.0.2
overlay_support: ^2.0.0
package_info_plus: ^8.0.3
Expand Down

0 comments on commit 3845213

Please sign in to comment.