init method
Initialises the manager: registers the bundled service worker, cleans up legacy registrations, and attaches the event listeners that relay notification events back to Dart.
Must be called before any notification can be posted — postMessage and friends await initialisation internally, so calls made while init is still in flight are queued rather than dropped.
Returns true when a service worker was registered successfully, false when service workers are unsupported (see isSupported) or registration failed — failures are logged, never thrown, so plugin registration cannot break app startup.
Idempotent: repeat calls return the result of the first call without re-registering. Use registerServiceWorker to (re-)register a custom worker or scope after initialisation.
Implementation
Future<bool> init() {
return _initFuture ??= _setupServiceWorker().then((registered) {
if (registered) {
printDebug("Service worker initialised.", tag: tag);
}
return registered;
}).catchError((e) {
printDebug("Service worker setup failed: $e", tag: tag);
return false;
});
}