백품타 타이머 켜놓고 탭 이탈 시 브라우저 알림 추가

공부 타이머가 진행 중일 때 브라우저 탭이 백그라운드로 가면(다른
탭/창/앱으로 이동) 20초 뒤에도 계속 그 상태면 "다시 돌아와서
집중해볼까요?" 브라우저 알림을 띄운다. dart:html 대신 package:web +
js_interop로 구현하고, 웹이 아닌 빌드에서는 조건부 임포트로 아무
동작 안 하는 스텁을 쓴다.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-21 04:17:48 +00:00
co-authored by Claude Sonnet 5
parent 8a9b414535
commit e8b375a18c
4 changed files with 58 additions and 3 deletions
@@ -0,0 +1,24 @@
// 🌐 웹 전용 - 브라우저 알림(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 (_) {
// 조용히 무시
}
}