support for registering pushers
This commit is contained in:
parent
88cdcf9863
commit
fe871217b2
21 changed files with 350 additions and 22 deletions
|
|
@ -9,6 +9,7 @@ import "package:nexus/controllers/account_data.dart";
|
|||
import "package:nexus/controllers/client.dart";
|
||||
import "package:nexus/controllers/client_state.dart";
|
||||
import "package:nexus/controllers/settings.dart";
|
||||
import "package:nexus/controllers/unified_push.dart";
|
||||
import "package:nexus/controllers/spec_versions.dart";
|
||||
import "package:nexus/models/account_data.dart";
|
||||
import "package:nexus/models/settings_category.dart";
|
||||
|
|
@ -95,6 +96,46 @@ class SettingsSectionsController
|
|||
if (ref.watch(ClientStateController.provider)?.isLoggedIn == true)
|
||||
"Account": .new([
|
||||
.new(title: "Profile", icon: Icons.person, settings: .new([])),
|
||||
.new(
|
||||
title: "Notifications",
|
||||
icon: Icons.notifications,
|
||||
settings: .new([
|
||||
// TODO: Disable if not supported
|
||||
.new(
|
||||
title: "Push notifications",
|
||||
description: "Enable push notifications using Web Push",
|
||||
builder: (title, description, icon) => Consumer(
|
||||
builder: (context, ref, _) {
|
||||
final pusherRegistered = ref.watch(
|
||||
UnifiedPushController.provider,
|
||||
);
|
||||
return SwitchListTile(
|
||||
title: Text(title),
|
||||
subtitle: Text(description),
|
||||
secondary: Icon(icon),
|
||||
value: pusherRegistered.maybeWhen(
|
||||
data: (value) => value,
|
||||
orElse: () => false,
|
||||
),
|
||||
onChanged: pusherRegistered.maybeWhen(
|
||||
data: (_) =>
|
||||
(value) => value
|
||||
? ref
|
||||
.watch(
|
||||
UnifiedPushController.provider.notifier,
|
||||
)
|
||||
.register()
|
||||
.onError(showError)
|
||||
: /*deregeister*/ null,
|
||||
orElse: () => null,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
icon: Icons.notification_add,
|
||||
),
|
||||
]),
|
||||
),
|
||||
.new(
|
||||
title: "Safety",
|
||||
icon: Icons.gpp_good,
|
||||
|
|
@ -166,6 +207,8 @@ class SettingsSectionsController
|
|||
onPressed: () async {
|
||||
Navigator.of(context)
|
||||
.popUntil((route) => route.isFirst);
|
||||
Navigator.of(context)
|
||||
.popUntil((route) => route.isFirst);
|
||||
|
||||
await WidgetsBinding.instance.endOfFrame;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue