Skip to content

Commit

Permalink
Merge pull request #30 from CoderJava/feature/setelah-logout-reset-ni…
Browse files Browse the repository at this point in the history
…lai-timer-nya

 Feature - Reset timer setelah user logout dan cegah si user agar tidak bisa logout jika timer-nya hidup
  • Loading branch information
CoderJava authored Oct 6, 2023
2 parents 38e7a94 + 2bb29c3 commit 17ae421
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 18 deletions.
3 changes: 2 additions & 1 deletion assets/translations/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -293,5 +293,6 @@
"please_set_finish_date": "Please set finish date",
"finish_date_time_must_be_after_of_start_date_time": "The finish date time must be after the start date time",
"reason": "Reason",
"why_are_you_adding_manual_track": "e.g. Forgot to start timer"
"why_are_you_adding_manual_track": "e.g. Forgot to start timer",
"please_stop_the_timer_if_you_want_to_logout": "Please stop the timer if you want to logout."
}
32 changes: 16 additions & 16 deletions lib/feature/presentation/page/home/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import 'package:tray_manager/tray_manager.dart';
import 'package:window_manager/window_manager.dart';

var countTimeReminderTrackInSeconds = 0;
var isGlobalTimerStart = false;

class HomePage extends StatefulWidget {
static const routePath = '/home';
Expand Down Expand Up @@ -83,7 +84,6 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
var isWindowVisible = true;
var userId = '';
var email = '';
var isTimerStart = false;
var isTimerStartTemp = false;
TrackUserLiteResponse? trackUserLite;
ItemProjectResponse? selectedProject;
Expand Down Expand Up @@ -147,7 +147,7 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
now.day,
);
timerDate = Timer.periodic(const Duration(seconds: 1), (_) {
if (!isTimerStart) {
if (!isGlobalTimerStart) {
// reminder track
var isShowReminderTrack = false;
final now = DateTime.now();
Expand Down Expand Up @@ -533,7 +533,7 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
final firstTask = filteredTask.first;
startTime = DateTime.now();
selectedTask = firstTask;
isTimerStart = true;
isGlobalTimerStart = true;
setTrayContextMenu();
valueNotifierTaskTracked.value = firstTask.trackedInSeconds;
resetCountTimer();
Expand Down Expand Up @@ -666,7 +666,7 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
}
startTime = DateTime.now();
selectedTask = itemTask;
isTimerStart = true;
isGlobalTimerStart = true;
setTrayContextMenu();
valueNotifierTaskTracked.value = itemTask.trackedInSeconds;
resetCountTimer();
Expand Down Expand Up @@ -733,7 +733,7 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
}

void stopTimerFromButton(TrackTask itemTask) {
isTimerStart = false;
isGlobalTimerStart = false;
setTrayContextMenu();
itemTask.trackedInSeconds = valueNotifierTaskTracked.value;
stopTimer();
Expand All @@ -747,7 +747,7 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
borderRadius: BorderRadius.circular(8),
child: InkWell(
borderRadius: BorderRadius.circular(8),
onTap: isTimerStart || isTimerStartTemp
onTap: isGlobalTimerStart || isTimerStartTemp
? null
: () async {
final selectedProjectTemp = await showModalBottomSheet(
Expand Down Expand Up @@ -806,7 +806,7 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
height: 8,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: isTimerStart || isTimerStartTemp ? Colors.green : Colors.grey,
color: isGlobalTimerStart || isTimerStartTemp ? Colors.green : Colors.grey,
),
),
const SizedBox(width: 4),
Expand All @@ -822,7 +822,7 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
),
),
const SizedBox(width: 16),
isTimerStart || isTimerStartTemp
isGlobalTimerStart || isTimerStartTemp
? Container()
: const Icon(
Icons.keyboard_arrow_down,
Expand Down Expand Up @@ -995,7 +995,7 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
void setTrayContextMenu() {
final items = <MenuItem>[];
if (listTrackTask.isNotEmpty) {
if (!isTimerStart) {
if (!isGlobalTimerStart) {
items.add(
MenuItem(
key: keyTrayStartWorking,
Expand Down Expand Up @@ -1096,7 +1096,7 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
final task = listTrackTask.first;
startTime = DateTime.now();
selectedTask = task;
isTimerStart = true;
isGlobalTimerStart = true;
setTrayContextMenu();
valueNotifierTaskTracked.value = task.trackedInSeconds;
resetCountTimer();
Expand All @@ -1107,7 +1107,7 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
final task = filteredTask.first;
startTime = DateTime.now();
selectedTask = task;
isTimerStart = true;
isGlobalTimerStart = true;
setTrayContextMenu();
valueNotifierTaskTracked.value = task.trackedInSeconds;
resetCountTimer();
Expand All @@ -1117,7 +1117,7 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
}

void stopTimerFromSystemTray() {
isTimerStart = false;
isGlobalTimerStart = false;
setTrayContextMenu();
selectedTask?.trackedInSeconds = valueNotifierTaskTracked.value;
stopTimer();
Expand Down Expand Up @@ -1158,8 +1158,8 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
isHaveActivity = true;
} else if (strEvent == 'screen_is_locked') {
// auto stop timer dan ambil screenshot-nya
if (isTimerStart) {
isTimerStart = false;
if (isGlobalTimerStart) {
isGlobalTimerStart = false;
setTrayContextMenu();
stopTimer();
finishTime = DateTime.now();
Expand Down Expand Up @@ -1271,7 +1271,7 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
// stop timer-nya jika permission screen recording-nya tidak diallow-kan atau
// gagal ambil screenshot-nya di end time
stopTimer();
isTimerStart = false;
isGlobalTimerStart = false;
setTrayContextMenu();
selectedTask = null;
setState(() {});
Expand All @@ -1294,7 +1294,7 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
// stop timer-nya jika isForceStop bernilai true
listPathScreenshots.clear();
stopTimer();
isTimerStart = false;
isGlobalTimerStart = false;
setTrayContextMenu();
selectedTask = null;
setState(() {});
Expand Down
21 changes: 21 additions & 0 deletions lib/feature/presentation/page/setting/setting_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import 'package:flutter/scheduler.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:launch_at_startup/launch_at_startup.dart';
import 'package:tray_manager/tray_manager.dart';
import 'package:window_manager/window_manager.dart';

class SettingPage extends StatefulWidget {
Expand Down Expand Up @@ -1002,6 +1003,25 @@ class _SettingPageState extends State<SettingPage> {
}

Future<void> doLogout() async {
if (isGlobalTimerStart) {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text('warning'.tr()),
content: Text('please_stop_the_timer_if_you_want_to_logout'.tr()),
actions: [
TextButton(
onPressed: () => context.pop(),
child: Text('dismiss'.tr()),
),
],
);
},
);
return;
}

final isLogout = await showDialog(
context: context,
builder: (context) {
Expand Down Expand Up @@ -1032,6 +1052,7 @@ class _SettingPageState extends State<SettingPage> {
if (isLogout != null && mounted) {
await helper.setLogout();
if (mounted) {
trayManager.setTitle('--:--:--');
context.goNamed(SplashPage.routeName);
}
}
Expand Down
2 changes: 1 addition & 1 deletion macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ SPEC CHECKSUMS:
tray_manager: 9064e219c56d75c476e46b9a21182087930baf90
window_manager: 3a1844359a6295ab1e47659b1a777e36773cd6e8

PODFILE CHECKSUM: 7b8886a4ad89b3a2f7a16642e81ab6bed5c5d3ac
PODFILE CHECKSUM: 8d40c19d3cbdb380d870685c3a564c989f1efa52

COCOAPODS: 1.13.0

0 comments on commit 17ae421

Please sign in to comment.