mirror of
https://github.com/immich-app/immich.git
synced 2024-11-18 03:19:01 -07:00
12217bde8a
* adds onboarding * fixed error where login was taking you to permission page * fixed a bad rebase and added more checks to not start backup service on login if no gallery permission * forgot the permission handler import in AppDelegate * reverts album selection page * change to ref watch * added device_info_plus to podspec * removed unused import --------- Co-authored-by: Marty Fuhry <marty@fuhry.farm>
45 lines
1.4 KiB
Dart
45 lines
1.4 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
|
|
class NotificationPermissionNotifier extends StateNotifier<PermissionStatus> {
|
|
NotificationPermissionNotifier() :
|
|
super(Platform.isAndroid
|
|
? PermissionStatus.granted
|
|
: PermissionStatus.restricted,
|
|
) {
|
|
// Sets the initial state
|
|
getNotificationPermission().then((p) => state = p);
|
|
}
|
|
|
|
/// Requests the notification permission
|
|
/// Note: In Android, this is always granted
|
|
Future<PermissionStatus> requestNotificationPermission() async {
|
|
final permission = await Permission.notification.request();
|
|
state = permission;
|
|
return permission;
|
|
}
|
|
|
|
/// Whether the user has the permission or not
|
|
/// Note: In Android, this is always true
|
|
Future<bool> hasNotificationPermission() {
|
|
return Permission.notification.isGranted;
|
|
}
|
|
|
|
Future<PermissionStatus> getNotificationPermission() async {
|
|
final status = await Permission.notification.status;
|
|
state = status;
|
|
return status;
|
|
}
|
|
|
|
/// Either the permission was granted already or else ask for the permission
|
|
Future<bool> hasOrAskForNotificationPermission() {
|
|
return requestNotificationPermission().then((p) => p.isGranted);
|
|
}
|
|
|
|
}
|
|
final notificationPermissionProvider
|
|
= StateNotifierProvider<NotificationPermissionNotifier, PermissionStatus>
|
|
((ref) => NotificationPermissionNotifier());
|