mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-16 17:27:39 +00:00
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:
parent
4f5354da0d
commit
2d06a23c97
2 changed files with 25 additions and 5 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue