25 lines
882 B
Dart
25 lines
882 B
Dart
// 🌐 웹 전용 - 브라우저 알림(Notification) API로 "타이머 켜놓고 탭을 벗어났을 때" 같은
|
|||
|
|
// 즉각적인 로컬 알림을 띄운다. FCM 푸시와 달리 서버 왕복 없이 바로 뜬다.
|
||
|
|
// 알림 API를 지원하지 않는 브라우저에서는 조용히 무시한다.
|
||
|
|
import 'dart:js_interop';
|
||
|
|
import 'package:web/web.dart' as web;
|
||
|
|
|
||
|
|
Future<bool> requestNotificationPermission() async {
|
||
|
|
try {
|
||
|
|
if (web.Notification.permission == 'granted') return true;
|
||
|
|
final permission = await web.Notification.requestPermission().toDart;
|
||
|
|
return permission.toDart == 'granted';
|
||
|
|
} catch (_) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void showBrowserNotification(String title, String body) {
|
||
|
|
try {
|
||
|
|
if (web.Notification.permission != 'granted') return;
|
||
|
|
web.Notification(title, web.NotificationOptions(body: body));
|
||
|
|
} catch (_) {
|
||
|
|
// 조용히 무시
|
||
|
|
}
|
||
|
|
}
|