Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,11 @@ class AddOrUpdateAlarmController extends GetxController {
}
}

checkOverlayPermissionAndNavigate() async {
if (!(await Permission.systemAlertWindow.isGranted) &&
Future<bool> checkOverlayPermission() async {
if (!(await Permission.systemAlertWindow.isGranted) ||
!(await Permission.ignoreBatteryOptimizations.isGranted)) {
Get.defaultDialog(
bool result = false;
await Get.defaultDialog(
backgroundColor: themeController.secondaryBackgroundColor.value,
title: 'Permission Required',
titleStyle: TextStyle(
Expand All @@ -208,8 +209,8 @@ class AddOrUpdateAlarmController extends GetxController {
const EdgeInsets.symmetric(vertical: 20, horizontal: 20),
titlePadding: const EdgeInsets.only(top: 30, right: 40),
content: const Text(
'This app requires permission to draw overlays,send notifications'
' and Ignore batter optimization.',
'This app requires permission to draw overlays, send notifications'
' and ignore battery optimization for the alarm to work reliably.',
),
actions: [
TextButton(
Expand All @@ -218,6 +219,7 @@ class AddOrUpdateAlarmController extends GetxController {
),
child: const Text('Cancel', style: TextStyle(color: Colors.black)),
onPressed: () {
result = false;
Get.back();
},
),
Expand All @@ -233,47 +235,30 @@ class AddOrUpdateAlarmController extends GetxController {
style: TextStyle(color: Colors.black),
),
onPressed: () async {
Get.back();

if (Platform.isAndroid) {
// Request overlay permission
if (!(await Permission.systemAlertWindow.isGranted)) {
final status = await Permission.systemAlertWindow.request();
if (!status.isGranted) {
debugPrint('SYSTEM_ALERT_WINDOW permission denied!');
return;
}
await Permission.systemAlertWindow.request();
}

if (!(await Permission.ignoreBatteryOptimizations.isGranted)) {
bool requested = await Permission.ignoreBatteryOptimizations
.request()
.isGranted;
if (!requested) {
debugPrint(
'IGNORE_BATTERY_OPTIMIZATION permission denied!',
);
return;
}
await Permission.ignoreBatteryOptimizations.request();
}
}

// Request notification permission
if (!await Permission.notification.isGranted) {
final status = await Permission.notification.request();
if (status != PermissionStatus.granted) {
debugPrint('Notification permission denied!');
return;
// Request notification permission
if (!await Permission.notification.isGranted) {
await Permission.notification.request();
}
}

result = true;
Get.back();
},
),
],
);
return result;
} else {
Get.back();
return true;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1044,11 +1044,10 @@ class AddOrUpdateAlarmView extends GetView<AddOrUpdateAlarmController> {
),
onPressed: () async {
Utils.hapticFeedback();
await controller.checkOverlayPermissionAndNavigate();
bool hasPermission =
await controller.checkOverlayPermission();

if ((await Permission.systemAlertWindow.isGranted) &&
(await Permission
.ignoreBatteryOptimizations.isGranted)) {
if (hasPermission) {
if (!controller.homeController.isProfile.value) {
if (controller.userModel.value != null) {
controller.offsetDetails[
Expand Down Expand Up @@ -1178,18 +1177,19 @@ class AddOrUpdateAlarmView extends GetView<AddOrUpdateAlarmController> {
await controller
.updateAlarm(updatedAlarmModel);
}
Get.back();
} catch (e) {
debugPrint(e.toString());
}
} else {
controller.createProfile();
await controller.createProfile();
Get.back();
}
}
},
),
),
),
],
)],
),
),
);
Expand Down