28 lines
944 B
Dart
28 lines
944 B
Dart
import 'dart:js_interop';
|
|
|
|
@JS('navigator.userAgent')
|
|
external String get _navigatorUserAgent;
|
|
|
|
@JS('window.matchMedia')
|
|
external _MediaQueryList _matchMedia(String query);
|
|
|
|
extension type _MediaQueryList._(JSObject _) implements JSObject {
|
|
external bool get matches;
|
|
}
|
|
|
|
/// Returns true when the user is on iOS Safari and the app has NOT been added
|
|
/// to the Home Screen (i.e., not running in standalone mode).
|
|
///
|
|
/// When this returns true, we show the "Add to Home Screen" install banner so
|
|
/// that users can unlock iOS 16.4+ web push notifications.
|
|
bool detectIosSafariNotInstalled() {
|
|
final ua = _navigatorUserAgent.toLowerCase();
|
|
final isIos =
|
|
ua.contains('iphone') || ua.contains('ipad') || ua.contains('ipod');
|
|
if (!isIos) return false;
|
|
|
|
// The PWA is "installed" if the display-mode: standalone media query matches.
|
|
final isStandalone = _matchMedia('(display-mode: standalone)').matches;
|
|
return !isStandalone;
|
|
}
|