Don't hold up app loading while waiting for permissions from user on macos. Addresses https://github.com/cypherstack/stack_wallet/issues/936

This commit is contained in:
Julian 2024-07-22 15:50:31 -06:00 committed by julian-CStack
parent 4f5354da0d
commit 2d06a23c97
2 changed files with 25 additions and 5 deletions

View file

@ -242,7 +242,7 @@ void main(List<String> args) async {
// SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
// overlays: [SystemUiOverlay.bottom]);
await NotificationApi.init();
unawaited(NotificationApi.init());
await loadCoinlibFuture;

View file

@ -8,13 +8,16 @@
*
*/
import 'dart:async';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import '../models/notification_model.dart';
import '../utilities/prefs.dart';
import 'notifications_service.dart';
class NotificationApi {
abstract final class NotificationApi {
static Completer<void>? _initCalledCompleter;
static final _notifications = FlutterLocalNotificationsPlugin();
// static final onNotifications = BehaviorSubject<String?>();
@ -33,6 +36,16 @@ class NotificationApi {
}
static Future<void> init({bool initScheduled = false}) async {
if (_initCalledCompleter == null) {
_initCalledCompleter = Completer<void>();
} else {
if (_initCalledCompleter!.isCompleted) {
return;
} else {
return await _initCalledCompleter!.future;
}
}
const android = AndroidInitializationSettings('app_icon_alpha');
const iOS = DarwinInitializationSettings();
const linux = LinuxInitializationSettings(
@ -54,12 +67,18 @@ class NotificationApi {
// onNotifications.add(payload.payload);
// },
);
_initCalledCompleter!.complete();
}
static Future<void> clearNotifications() async => _notifications.cancelAll();
static Future<void> clearNotifications() async {
await init();
await _notifications.cancelAll();
}
static Future<void> clearNotification(int id) async =>
_notifications.cancel(id);
static Future<void> clearNotification(int id) async {
await init();
await _notifications.cancel(id);
}
//===================================
static late Prefs prefs;
@ -79,6 +98,7 @@ class NotificationApi {
String? changeNowId,
String? payload,
}) async {
await init();
await prefs.incrementCurrentNotificationIndex();
final id = prefs.currentNotificationId;