~emersion/goguma

667cc38074e75a842311789f5be7397841935ba3 — Simon Ser 8 days ago e92ac5f
unifiedpush: use same singleton pattern as NotificationController
1 files changed, 14 insertions(+), 11 deletions(-)

M lib/unifiedpush.dart
M lib/unifiedpush.dart => lib/unifiedpush.dart +14 -11
@@ 9,23 9,20 @@ import 'package:unifiedpush/unifiedpush.dart';
import 'database.dart';
import 'push.dart';

UnifiedPushController? _singleton;
String? _distributor;

class UnifiedPushController extends PushController {
	final Map<String, Completer<PushSubscription>> _pendingSubscriptions = {};
	String? _distributor;

	UnifiedPushController._();
	static UnifiedPushController? _instance;

	static Future<UnifiedPushController> init() async {
		_singleton ??= UnifiedPushController._();
		var controller = _singleton!;
	UnifiedPushController._();

	Future<void> _init() async {
		try {
			await UnifiedPush.initialize(
				onNewEndpoint: controller._handleNewEndpoint,
				onRegistrationFailed: controller._handleRegistrationFailed,
				onUnregistered: controller._handleUnregistered,
				onNewEndpoint: _handleNewEndpoint,
				onRegistrationFailed: _handleRegistrationFailed,
				onUnregistered: _handleUnregistered,
				onMessage: _handleMessage,
			);
		} on UnimplementedError {


@@ 44,8 41,14 @@ class UnifiedPushController extends PushController {
		}
		print('Using UnifiedPush distributor: $distributor');
		_distributor = distributor;
	}

		return controller;
	static Future<UnifiedPushController> init() async {
		if (_instance == null) {
			_instance = UnifiedPushController._();
			await _instance!._init();
		}
		return _instance!;
	}

	@override