Skip to content

Commit d221010

Browse files
committed
Handle device sleep agar timer-nya distop saja
Ketika device sleep dan timer-nya sedang berjalan itu tidak dapat mengambil screenshot dari layar-nya. Jadi, solusinya adalah stop timer-nya saja ketika terdeteksi device-nya sleep atau path screenshot-nya kosong.
1 parent e959a9b commit d221010

File tree

1 file changed

+37
-30
lines changed

1 file changed

+37
-30
lines changed

lib/feature/presentation/page/home/home_page.dart

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -888,36 +888,6 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
888888
}
889889

890890
Future<void> doTakeScreenshot() async {
891-
final listPathScreenshots = await platformChannelHelper.doTakeScreenshot();
892-
if (listPathScreenshots.isEmpty) {
893-
return;
894-
}
895-
listPathScreenshots.removeWhere((element) => element == null || element.isEmpty);
896-
if (listPathScreenshots.isNotEmpty) {
897-
final firstElement = listPathScreenshots.first ?? '';
898-
final splitBySlash = firstElement.split('/');
899-
var baseFilePath = '';
900-
if (splitBySlash.isNotEmpty) {
901-
for (var index = 0; index < splitBySlash.length - 1; index++) {
902-
final element = splitBySlash[index];
903-
baseFilePath += '/$element';
904-
}
905-
}
906-
if (baseFilePath.isNotEmpty) {
907-
await sharedPreferencesManager.putString(
908-
SharedPreferencesManager.keyBaseFilePathScreenshot,
909-
baseFilePath,
910-
);
911-
}
912-
}
913-
final files = listPathScreenshots.join(',');
914-
915-
final isShowScreenshotNotification =
916-
sharedPreferencesManager.getBool(SharedPreferencesManager.keyIsEnableScreenshotNotification) ?? false;
917-
if (isShowScreenshotNotification) {
918-
notificationHelper.showScreenshotTakenNotification();
919-
}
920-
921891
var percentActivity = 0.0;
922892
if (counterActivity > 0 && countTimerInSeconds > 0) {
923893
percentActivity = (counterActivity / countTimerInSeconds) * 100;
@@ -972,6 +942,43 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
972942

973943
final activity = percentActivity.round();
974944

945+
final listPathScreenshots = await platformChannelHelper.doTakeScreenshot();
946+
if (listPathScreenshots.isEmpty) {
947+
debugPrint('list path screenshots is empty');
948+
valueNotifierTotalTracked.value -= durationInSeconds;
949+
valueNotifierTaskTracked.value -= durationInSeconds;
950+
isTimerStart = false;
951+
stopTimer();
952+
selectedTask = null;
953+
setState(() {});
954+
return;
955+
}
956+
listPathScreenshots.removeWhere((element) => element == null || element.isEmpty);
957+
if (listPathScreenshots.isNotEmpty) {
958+
final firstElement = listPathScreenshots.first ?? '';
959+
final splitBySlash = firstElement.split('/');
960+
var baseFilePath = '';
961+
if (splitBySlash.isNotEmpty) {
962+
for (var index = 0; index < splitBySlash.length - 1; index++) {
963+
final element = splitBySlash[index];
964+
baseFilePath += '/$element';
965+
}
966+
}
967+
if (baseFilePath.isNotEmpty) {
968+
await sharedPreferencesManager.putString(
969+
SharedPreferencesManager.keyBaseFilePathScreenshot,
970+
baseFilePath,
971+
);
972+
}
973+
}
974+
final files = listPathScreenshots.join(',');
975+
976+
final isShowScreenshotNotification =
977+
sharedPreferencesManager.getBool(SharedPreferencesManager.keyIsEnableScreenshotNotification) ?? false;
978+
if (isShowScreenshotNotification) {
979+
notificationHelper.showScreenshotTakenNotification();
980+
}
981+
975982
final trackEntity = Track(
976983
userId: userId,
977984
taskId: taskId!,

0 commit comments

Comments
 (0)