js_notifications 1.0.0
js_notifications: ^1.0.0 copied to clipboard
An extended NotificationsAPI for Dart managing web notifications.
1.0.0 #
- Zero-setup service worker:
js_notifications-sw.jsnow ships as a bundled Flutter asset of the package (deployed atassets/packages/js_notifications/assets/) and is registered automatically — manually copying the file into your app'sweb/folder is no longer required. Existing copied files can be deleted; legacy registrations are unregistered automatically on startup. - Service worker URL now resolves against the document base URI, fixing deployments under a
non-root
<base href>. ServiceWorkerManageris now a singleton (ServiceWorkerManager.instance, or the factory constructor to assign event callbacks) — a page has one service worker registration, and the manager owns the listeners attached to it.- Service worker setup moved out of the
ServiceWorkerManagerconstructor into an explicit, idempotentinit(). The plugin calls it automatically on registration and exposesinitialize()(returns whether the worker registered) andisInitialized. Notifications posted before initialisation completes now wait for it instead of being dropped with "No service worker ready". - Added
registerServiceWorker({url, scope})— replace the bundled worker with a custom script (e.g. customsendActionhandling), register the bundled worker under a custom scope, or both. ThescopeUrlsetter now works (previously ineffective): it re-registers the current worker under the new scope. Note: scopes outside the worker script's directory require aService-Worker-Allowedresponse header from the server. - Fixed: service worker updates are now adopted. When a byte-different worker was deployed,
the plugin kept posting to the previous (now redundant) worker and notifications silently
stopped working until a page reload. Updates are tracked via
updatefoundon the plugin's own registration; the new worker is adopted once it reachesactivated, with aredundantfallback to the registration's active worker. - Fixed:
controllerchangeno longer adoptsnavigator.serviceWorker.controller. The controller is the worker controlling the page — never this plugin's worker, whose scope controls no pages — so a controller change (e.g. Flutter's ownflutter_service_worker.jsupdating) could redirectpostMessageto a worker that ignores the plugin's protocol. - Fixed service worker script bugs: error-logger shadowing in the
showNotificationcatch handler,console.warnargument spreading; renamed SW log tagcallkit_sw→js_notifications_sw. - WebAssembly support: full migration off deprecated
dart:htmltopackage:web+dart:js_interop— the package now compiles withflutter build web --wasm. - BREAKING:
badgeis nowString?— the URL of the monochrome badge image, per the Web API'sNotification.badge(previously mistyped asint?, which browsers ignored; not to be confused with the numeric Badging API,navigator.setAppBadge). - BREAKING:
vibrateis nowList<int>?(previouslyweb.VibratePattern?);package:webtypes no longer appear in the public API. - BREAKING: minimum Flutter version raised to 3.22 (stable WASM toolchain floor).
- BREAKING:
SWEventsconstants for events that never dispatch on page-side objects were removed (push,pushsubscriptionchange,sync,install,activate,fetch— these fire inside the worker's own global scope);updatefoundwas added. - Internal: service worker event wiring now uses
EventStreamProvidersubscriptions; removed ~10 dead no-op event listeners that never fired on page-side objects.ServiceWorkerManager.dispose()now cancels and clears every subscription and resets state, soinit()can run again afterwards. - Added
deepCastMap/deepCastValuehelpers (lib/utils/utils.dart) used to normalisedartify()output into theMap<String, dynamic>shape the plugin uses for event payloads. - Added
bundledSwAssetPathandbundledSwAssetDirMarkerconstants;defaultScopeis retained for legacy-registration migration. isSupportednow feature-detects theNotificationglobal (dart:html'sNotification.supportedhas nopackage:webequivalent).- Note: under the WASM runtime, integral JS numbers in notification
datapayloads may be delivered back to Dart asdouble— treat round-tripped numbers asnum.
0.0.5 #
- Fix
NotificationAPIlate init - Updated docs
0.0.4 #
- Fix
JsNotificationDirection'stoString()conversion - Added
autotoJSNotificationDirection
0.0.3+3 #
- Updated docs
- Fix linting
0.0.3 #
- Added notification accessors and notification getters (via caching)
- Fixed notification on tap stream not triggering
0.0.2 #
- Added notification tap stream
- Added factory constructors, helpers for
JSNotification,JSNotificationOptionsandJSNotificationAction
0.0.1 #
- Initial release