fc7dbb0ac0
Server: drop ntfy publishing (stage hooks, run outbox, chat attention, chat tool notify, auto-switch and schedule notices), the chat push outbox (its table is dropped at startup), ntfy status/endpoints and PIPELINES_NTFY_*. The app_notifications stream, subscribe/clear and kinds are unchanged. Notification settings keep run_finished/chat_needs_you/chat_reply_finished; ntfy_enabled is accepted and ignored and its stored row is never read. Stage type=ntfy is rejected: "ntfy stages were removed; notifications go to the Pipelines apps — use the stage notify hook". The notify hook remains. Installer: no ntfy build, accounts, config or supervisor child; manifest gets top-level "mode" (legacy ntfy.mode still read). Reinstall retires an old ntfy (safe PID-file stop, deletes binary, config, data dir, token, log, with a note in logs/install.log); uninstall cleans leftovers. App: ntfy settings section replaced by "Notification events"; texts updated. Docs: docs/ntfy.md folded into docs/notifications.md; install, docker, cli, author skill references updated; security review M1 marked resolved. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
194 lines
6.7 KiB
Dart
194 lines
6.7 KiB
Dart
import 'dart:async';
|
||
|
||
import 'package:flutter/material.dart';
|
||
|
||
import '../notification_service/notification_service_bridge.dart';
|
||
import '../notification_service/notification_service_controller.dart';
|
||
import 'settings_group.dart';
|
||
import 'settings_row.dart';
|
||
import 'settings_theme.dart';
|
||
|
||
const deviceDeliveryTitle = 'Notifications in Pipelines';
|
||
const deviceDeliverySwitchLabel = 'Receive notifications in Pipelines';
|
||
const deviceDeliveryNote =
|
||
'Pipelines keeps its own connection to the server and shows its '
|
||
'notifications even while the app is closed. Android shows a quiet '
|
||
'"Pipelines is connected" notification while it runs.';
|
||
const deviceDeliveryBatteryLabel = 'Allow background delivery';
|
||
const deviceDeliveryNotificationsLabel = 'Allow notifications';
|
||
const deviceDeliveryWarningTitle = 'Delivery can pause while idle';
|
||
const deviceDeliveryWarningText =
|
||
'Android may pause Pipelines in the background, so notifications can '
|
||
'arrive late. Allow background delivery above.';
|
||
const deviceDeliverySamsungNote =
|
||
'Samsung phones: also add Pipelines under Settings › Battery › '
|
||
'Background usage limits › Never sleeping apps.';
|
||
const deviceDeliveryLogTitle = 'Connection log';
|
||
const deviceDeliveryLogEmpty = 'No connection events yet';
|
||
|
||
abstract final class DeviceDeliveryKeys {
|
||
static const toggle = ValueKey<String>('settings.deviceDelivery.toggle');
|
||
static const status = ValueKey<String>('settings.deviceDelivery.status');
|
||
static const battery = ValueKey<String>('settings.deviceDelivery.battery');
|
||
static const batteryWarning = ValueKey<String>(
|
||
'settings.deviceDelivery.batteryWarning',
|
||
);
|
||
static const log = ValueKey<String>('settings.deviceDelivery.log');
|
||
static const permission = ValueKey<String>(
|
||
'settings.deviceDelivery.permission',
|
||
);
|
||
static const error = ValueKey<String>('settings.deviceDelivery.error');
|
||
}
|
||
|
||
/// Android background delivery in Settings: the switch, the service's live
|
||
/// status, and the two system grants it relies on (notification permission and
|
||
/// the battery-optimisation exemption). Absent where there is no service.
|
||
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
|
||
State<SettingsDeviceDeliverySection> createState() =>
|
||
_SettingsDeviceDeliverySectionState();
|
||
}
|
||
|
||
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(
|
||
onResume: () => unawaited(_controller.refresh()),
|
||
);
|
||
|
||
@override
|
||
void initState() {
|
||
super.initState();
|
||
_lifecycle;
|
||
unawaited(_controller.open());
|
||
}
|
||
|
||
@override
|
||
void dispose() {
|
||
_lifecycle.dispose();
|
||
if (_ownsController) _controller.dispose();
|
||
super.dispose();
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) => ListenableBuilder(
|
||
listenable: _controller,
|
||
builder: (context, _) => _body(context),
|
||
);
|
||
|
||
Widget _body(BuildContext context) {
|
||
final status = _controller.status;
|
||
final enabled = status?.enabled ?? false;
|
||
final onChanged = status == null || _controller.busy
|
||
? null
|
||
: (bool value) => unawaited(_controller.setEnabled(value));
|
||
return SettingsGroup(
|
||
title: deviceDeliveryTitle,
|
||
footer: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||
children: <Widget>[
|
||
const Text(deviceDeliveryNote),
|
||
if (_controller.error.isNotEmpty)
|
||
Text(
|
||
_controller.error,
|
||
key: DeviceDeliveryKeys.error,
|
||
style: TextStyle(color: settingsErrorColor(context)),
|
||
),
|
||
],
|
||
),
|
||
children: <Widget>[
|
||
SwitchListTile(
|
||
key: DeviceDeliveryKeys.toggle,
|
||
title: const Text(deviceDeliverySwitchLabel),
|
||
value: enabled,
|
||
onChanged: onChanged,
|
||
),
|
||
SettingsRow(
|
||
key: DeviceDeliveryKeys.status,
|
||
title: const Text('Status'),
|
||
subtitle: Text(status == null ? 'Loading…' : status.label),
|
||
),
|
||
if (status != null && enabled && !status.notificationsAllowed)
|
||
SettingsRow(
|
||
key: DeviceDeliveryKeys.permission,
|
||
title: const Text(deviceDeliveryNotificationsLabel),
|
||
subtitle: const Text('Android is blocking Pipelines notifications'),
|
||
action: true,
|
||
enabled: !_controller.busy,
|
||
onTap: () => unawaited(_controller.allowNotifications()),
|
||
),
|
||
if (status != null && enabled)
|
||
SettingsRow(
|
||
key: DeviceDeliveryKeys.battery,
|
||
title: const Text(deviceDeliveryBatteryLabel),
|
||
subtitle: Text(
|
||
status.batteryExempt
|
||
? 'Allowed: battery optimisation will not pause delivery'
|
||
: 'Keeps notifications instant while the phone is idle',
|
||
),
|
||
action: !status.batteryExempt,
|
||
enabled: !status.batteryExempt && !_controller.busy,
|
||
onTap: () => unawaited(_controller.allowBackgroundDelivery()),
|
||
),
|
||
if (status != null && enabled && !status.batteryExempt)
|
||
SettingsRow(
|
||
key: DeviceDeliveryKeys.batteryWarning,
|
||
leading: Icon(
|
||
Icons.warning_amber_rounded,
|
||
color: settingsErrorColor(context),
|
||
),
|
||
title: const Text(deviceDeliveryWarningTitle),
|
||
subtitle: Text(
|
||
'$deviceDeliveryWarningText\n$deviceDeliverySamsungNote',
|
||
),
|
||
),
|
||
if (status != null)
|
||
ExpansionTile(
|
||
key: DeviceDeliveryKeys.log,
|
||
title: const Text(deviceDeliveryLogTitle),
|
||
children: _logRows(),
|
||
),
|
||
],
|
||
);
|
||
}
|
||
|
||
List<Widget> _logRows() {
|
||
final events = _controller.events;
|
||
if (events.isEmpty) {
|
||
return const <Widget>[ListTile(title: Text(deviceDeliveryLogEmpty))];
|
||
}
|
||
return [
|
||
for (final event in events)
|
||
ListTile(
|
||
dense: true,
|
||
title: Text(event.title),
|
||
subtitle: Text(
|
||
[
|
||
event.timeLabel,
|
||
if (event.detail != null) event.detail!,
|
||
].join('\n'),
|
||
),
|
||
),
|
||
];
|
||
}
|
||
}
|