nexo/packages/messaging_flutter/lib/src/web_notification_permission.dart
toki 098abcaa99 feat(messaging): Web 전경 알림 표시를 추가한다
브라우저 전경 알림 표시와 click routing의 첫 구현을 남기고, 리뷰에서 확인된 실제 web click bridge 보완 계획을 함께 기록한다.
2026-06-07 17:30:25 +09:00

87 lines
2.8 KiB
Dart

/// Browser notification permission states exposed by [NexoMessagingPlugin].
enum NexoMessagingWebNotificationPermission {
/// Browser Notification API is not available on this platform/runtime.
unsupported,
/// Browser permission has not been granted or denied yet.
defaultPermission,
/// Browser permission was denied.
denied,
/// Browser permission was granted.
granted,
/// Browser returned an unknown permission string.
unknown,
}
/// Current browser notification support and permission status.
class NexoMessagingWebNotificationStatus {
const NexoMessagingWebNotificationStatus({
required this.isSupported,
required this.permission,
this.rawPermission,
});
/// Creates an unsupported status for non-web or unsupported web runtimes.
const NexoMessagingWebNotificationStatus.unsupported()
: isSupported = false,
permission = NexoMessagingWebNotificationPermission.unsupported,
rawPermission = null;
/// Creates a supported status from a browser `Notification.permission` value.
factory NexoMessagingWebNotificationStatus.fromBrowserPermission(
String permission,
) {
final normalized = permission.trim().toLowerCase();
return NexoMessagingWebNotificationStatus(
isSupported: true,
permission: switch (normalized) {
'default' => NexoMessagingWebNotificationPermission.defaultPermission,
'denied' => NexoMessagingWebNotificationPermission.denied,
'granted' => NexoMessagingWebNotificationPermission.granted,
_ => NexoMessagingWebNotificationPermission.unknown,
},
rawPermission: permission,
);
}
/// Whether the current runtime exposes browser notifications.
final bool isSupported;
/// Normalized browser notification permission.
final NexoMessagingWebNotificationPermission permission;
/// Raw browser permission string, when available.
final String? rawPermission;
/// Whether browser notification display is currently allowed.
bool get isGranted =>
permission == NexoMessagingWebNotificationPermission.granted;
}
/// Result of [NexoMessagingPlugin.showWebForegroundNotification].
class NexoMessagingWebNotificationDisplayResult {
const NexoMessagingWebNotificationDisplayResult({
required this.success,
required this.isSupported,
required this.permissionGranted,
});
/// Convenience constructor for unsupported platform result.
const NexoMessagingWebNotificationDisplayResult.unsupported()
: success = false,
isSupported = false,
permissionGranted = false;
/// Whether the browser notification was successfully displayed.
final bool success;
/// Whether the current runtime supports browser notifications.
final bool isSupported;
/// Whether the browser notification permission was granted.
final bool permissionGranted;
}