add UnifiedPushAllowedController
This commit is contained in:
parent
fe871217b2
commit
7218eb5195
3 changed files with 67 additions and 16 deletions
|
|
@ -11,6 +11,7 @@ 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/controllers/unified_push_allowed.dart";
|
||||
import "package:nexus/models/account_data.dart";
|
||||
import "package:nexus/models/settings_category.dart";
|
||||
import "package:nexus/main.dart";
|
||||
|
|
@ -100,7 +101,6 @@ class SettingsSectionsController
|
|||
title: "Notifications",
|
||||
icon: Icons.notifications,
|
||||
settings: .new([
|
||||
// TODO: Disable if not supported
|
||||
.new(
|
||||
title: "Push notifications",
|
||||
description: "Enable push notifications using Web Push",
|
||||
|
|
@ -109,26 +109,43 @@ class SettingsSectionsController
|
|||
final pusherRegistered = ref.watch(
|
||||
UnifiedPushController.provider,
|
||||
);
|
||||
final unifiedPushAllowed = ref.watch(
|
||||
UnifiedPushAllowedController.provider,
|
||||
);
|
||||
return SwitchListTile(
|
||||
title: Text(title),
|
||||
subtitle: Text(description),
|
||||
subtitle: Text(
|
||||
unifiedPushAllowed.maybeWhen(
|
||||
data: (data) => data,
|
||||
orElse: () => null,
|
||||
) ??
|
||||
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,
|
||||
),
|
||||
onChanged:
|
||||
unifiedPushAllowed.maybeWhen(
|
||||
data: (data) => data == null,
|
||||
orElse: () => false,
|
||||
)
|
||||
? pusherRegistered.maybeWhen(
|
||||
data: (_) =>
|
||||
(value) => value
|
||||
? ref
|
||||
.watch(
|
||||
UnifiedPushController
|
||||
.provider
|
||||
.notifier,
|
||||
)
|
||||
.register()
|
||||
.onError(showError)
|
||||
: /*deregeister*/ null,
|
||||
orElse: () => null,
|
||||
)
|
||||
: null,
|
||||
);
|
||||
},
|
||||
),
|
||||
|
|
|
|||
Loading…
Reference in a new issue