Files
plezy/lib/utils/notification_permission.dart
T
edde746 db18ee4b34 feat(music): android background playback via media_controls foreground service
Bumps os_media_controls to 4f4b28f3: MediaStyle foreground service with
a JUnit-tested promote/demote/stop policy, artwork URL download (also
fixes video lock-screen art), and task-removal teardown that can't leak
orphan notifications. The music service opts into background mode per
session and requests POST_NOTIFICATIONS before first playback.
2026-07-05 21:52:58 +02:00

32 lines
1.2 KiB
Dart

import 'dart:io';
import 'package:background_downloader/background_downloader.dart';
import 'app_logger.dart';
bool _requested = false;
/// Best-effort request for the Android 13+ POST_NOTIFICATIONS runtime
/// permission (routed through background_downloader's permissions API, which
/// the app already ships for download notifications).
///
/// Needed so the background music playback notification is visible; playback
/// and its foreground service run regardless of the outcome, so a denial only
/// costs notification visibility. Asked at most once per app run — Android
/// remembers a real denial, so re-prompting is a no-op anyway.
///
/// No-op off Android: iOS/macOS media controls don't use notifications.
Future<void> ensureNotificationPermission() async {
if (_requested || !Platform.isAndroid) return;
_requested = true;
try {
final permissions = FileDownloader().permissions;
final status = await permissions.status(PermissionType.notifications);
if (status == PermissionStatus.granted) return;
final result = await permissions.request(PermissionType.notifications);
appLogger.d('Notification permission request result: $result');
} catch (e) {
appLogger.w('Notification permission request failed', error: e);
}
}