Use native service as Android notification source
This commit is contained in:
@@ -35,10 +35,12 @@ class SettingsDeviceDeliverySection extends StatefulWidget {
|
||||
const SettingsDeviceDeliverySection({
|
||||
super.key,
|
||||
required this.bridge,
|
||||
this.controller,
|
||||
this.requestNotificationPermission,
|
||||
});
|
||||
|
||||
final NotificationServiceBridge bridge;
|
||||
final NotificationServiceController? controller;
|
||||
final Future<void> Function()? requestNotificationPermission;
|
||||
|
||||
@override
|
||||
@@ -49,10 +51,12 @@ class SettingsDeviceDeliverySection extends StatefulWidget {
|
||||
class _SettingsDeviceDeliverySectionState
|
||||
extends State<SettingsDeviceDeliverySection> {
|
||||
late final NotificationServiceController _controller =
|
||||
widget.controller ??
|
||||
NotificationServiceController(
|
||||
widget.bridge,
|
||||
requestNotificationPermission: widget.requestNotificationPermission,
|
||||
);
|
||||
bool get _ownsController => widget.controller == null;
|
||||
|
||||
// System prompts (permission, battery) return by resuming the app.
|
||||
late final AppLifecycleListener _lifecycle = AppLifecycleListener(
|
||||
@@ -69,7 +73,7 @@ class _SettingsDeviceDeliverySectionState
|
||||
@override
|
||||
void dispose() {
|
||||
_lifecycle.dispose();
|
||||
_controller.dispose();
|
||||
if (_ownsController) _controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import 'settings_notifications_section.dart';
|
||||
import 'settings_ntfy_section.dart';
|
||||
import 'settings_device_delivery_section.dart';
|
||||
import '../notification_service/notification_service_bridge.dart';
|
||||
import '../notification_service/notification_service_controller.dart';
|
||||
import 'settings_android_download_section.dart';
|
||||
import 'settings_schedules_section.dart';
|
||||
import 'settings_sections.dart';
|
||||
@@ -51,10 +52,12 @@ class SettingsScreen extends StatefulWidget {
|
||||
this.showAndroidDownload = false,
|
||||
this.servers,
|
||||
this.deliveryService,
|
||||
this.deliveryServiceController,
|
||||
});
|
||||
|
||||
/// Android background delivery; hidden when absent or unsupported.
|
||||
final NotificationServiceBridge? deliveryService;
|
||||
final NotificationServiceController? deliveryServiceController;
|
||||
|
||||
final transport.PipelinesClient client;
|
||||
|
||||
@@ -192,6 +195,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
if (widget.deliveryService case final service? when service.supported)
|
||||
SettingsDeviceDeliverySection(
|
||||
bridge: service,
|
||||
controller: widget.deliveryServiceController,
|
||||
requestNotificationPermission: widget.notifications == null
|
||||
? null
|
||||
: () async {
|
||||
|
||||
Reference in New Issue
Block a user