mirror of
https://github.com/jonasbark/swiftcontrol.git
synced 2026-02-18 00:17:40 +01:00
make notifications optional on macOS & iOS
This commit is contained in:
@@ -141,6 +141,7 @@ class NotificationRequirement extends PlatformRequirement {
|
||||
badge: false,
|
||||
sound: false,
|
||||
);
|
||||
core.settings.setHasAskedPermissions(true);
|
||||
if (result == false) {
|
||||
buildToast(
|
||||
navigatorKey.currentContext!,
|
||||
@@ -156,6 +157,7 @@ class NotificationRequirement extends PlatformRequirement {
|
||||
badge: false,
|
||||
sound: false,
|
||||
);
|
||||
core.settings.setHasAskedPermissions(true);
|
||||
if (result == false) {
|
||||
buildToast(
|
||||
navigatorKey.currentContext!,
|
||||
@@ -181,12 +183,12 @@ class NotificationRequirement extends PlatformRequirement {
|
||||
final permissions = await core.flutterLocalNotificationsPlugin
|
||||
.resolvePlatformSpecificImplementation<IOSFlutterLocalNotificationsPlugin>()
|
||||
?.checkPermissions();
|
||||
status = permissions?.isEnabled == true;
|
||||
status = permissions?.isEnabled == true || core.settings.hasAskedPermissions();
|
||||
} else if (Platform.isMacOS) {
|
||||
final permissions = await core.flutterLocalNotificationsPlugin
|
||||
.resolvePlatformSpecificImplementation<MacOSFlutterLocalNotificationsPlugin>()
|
||||
?.checkPermissions();
|
||||
status = permissions?.isEnabled == true;
|
||||
status = permissions?.isEnabled == true || core.settings.hasAskedPermissions();
|
||||
} else {
|
||||
status = true;
|
||||
}
|
||||
|
||||
@@ -389,4 +389,12 @@ class Settings {
|
||||
Future<void> setShowOnboarding(bool show) async {
|
||||
await prefs.setBool('show_onboarding', show);
|
||||
}
|
||||
|
||||
bool hasAskedPermissions() {
|
||||
return prefs.getBool('asked_permissions') ?? false;
|
||||
}
|
||||
|
||||
Future<void> setHasAskedPermissions(bool asked) async {
|
||||
await prefs.setBool('asked_permissions', asked);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:bike_control/utils/requirements/android.dart';
|
||||
import 'package:bike_control/utils/requirements/platform.dart';
|
||||
import 'package:dartx/dartx.dart';
|
||||
import 'package:shadcn_flutter/shadcn_flutter.dart';
|
||||
@@ -74,6 +77,7 @@ class _PermissionListState extends State<PermissionList> with WidgetsBindingObse
|
||||
}
|
||||
});
|
||||
};
|
||||
final optional = e is NotificationRequirement && (Platform.isMacOS || Platform.isIOS);
|
||||
return SizedBox(
|
||||
width: double.infinity,
|
||||
child: Button(
|
||||
@@ -100,7 +104,12 @@ class _PermissionListState extends State<PermissionList> with WidgetsBindingObse
|
||||
? ButtonStyle.secondary(size: ButtonSize.small)
|
||||
: ButtonStyle.primary(size: ButtonSize.small),
|
||||
onPressed: onPressed,
|
||||
child: e.status ? Text(context.i18n.granted) : Text(context.i18n.grant),
|
||||
child: Column(
|
||||
children: [
|
||||
e.status ? Text(context.i18n.granted) : Text(context.i18n.grant),
|
||||
if (optional) Text('Optional', style: TextStyle(fontSize: 10)).muted,
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user