From 4c54191a3414ca657c88a2f1d9fe80bbc4e1a20a Mon Sep 17 00:00:00 2001 From: Faiz Hashmi Date: Mon, 11 Aug 2025 15:57:55 +0300 Subject: [PATCH] updated README.md and logger_service.dart --- lib/constants/app_constants.dart | 2 +- lib/models/prayers_widget_model.dart | 6 ++- lib/repositories/signalR_repo.dart | 4 +- lib/services/logger_service.dart | 21 --------- lib/view_models/screen_config_view_model.dart | 45 +++++++++++-------- lib/views/splash_screen/splash_screen.dart | 2 - 6 files changed, 35 insertions(+), 45 deletions(-) diff --git a/lib/constants/app_constants.dart b/lib/constants/app_constants.dart index db0e3a4..78d0e7c 100644 --- a/lib/constants/app_constants.dart +++ b/lib/constants/app_constants.dart @@ -106,7 +106,7 @@ class AppConstants { static String testIP = '12.4.5.1'; // projectID.QlineType.ScreenType.AnyNumber (1 to 10) static int thresholdForListUI = 3; - static double currentBuildVersion = 8.4; + static double currentBuildVersion = 8.5; static double clearLogsHoursThreshold = 48; } diff --git a/lib/models/prayers_widget_model.dart b/lib/models/prayers_widget_model.dart index 447a819..df9652f 100644 --- a/lib/models/prayers_widget_model.dart +++ b/lib/models/prayers_widget_model.dart @@ -32,7 +32,11 @@ class PrayersWidgetModel { } static dateTimeConversion(String date, String time) { - return DateFormat('dd MMM yyyy HH:mm').parse("$date $time").millisecondsSinceEpoch; + try { + return DateFormat('dd MMM yyyy HH:mm').parse("$date $time").millisecondsSinceEpoch; + } catch (e) { + return null; + } } @override diff --git a/lib/repositories/signalR_repo.dart b/lib/repositories/signalR_repo.dart index 2956aa8..430440f 100644 --- a/lib/repositories/signalR_repo.dart +++ b/lib/repositories/signalR_repo.dart @@ -21,6 +21,8 @@ class SignalrRepoImp implements SignalrRepo { HubConnection? connection; LoggerService loggerService; + bool get isConnected => connection?.state == HubConnectionState.connected; + SignalrRepoImp({this.connection, required this.loggerService}); @override @@ -54,11 +56,9 @@ class SignalrRepoImp implements SignalrRepo { connection!.onclose((exception) async { log(exception.toString()); onHubDisconnected(exception); - // Attempt to reconnect with limit and delay if (reconnectAttempts < maxReconnectAttempts) { reconnectAttempts++; loggerService.logToFile(message: "SignalR reconnect attempt #$reconnectAttempts", source: "startHubConnection -> signalR_repo.dart", type: LogTypeEnum.data); - await Future.delayed(reconnectDelay); try { await connection!.start(); diff --git a/lib/services/logger_service.dart b/lib/services/logger_service.dart index 75c1abc..ac551f4 100644 --- a/lib/services/logger_service.dart +++ b/lib/services/logger_service.dart @@ -11,7 +11,6 @@ import 'package:path_provider/path_provider.dart'; abstract class LoggerService { Future logToFile({required String message, required LogTypeEnum type, required String source}); - Future clearLogs(); void logError(String message); @@ -59,26 +58,6 @@ class LoggerServiceImp implements LoggerService { } } - @override - Future clearLogs() async { - try { - final dir = await getApplicationDocumentsDirectory(); - final logDir = Directory('${dir.path}/logs'); - - final filesToClear = [ - File('${logDir.path}/${AppStrings.errorLogsFileName}'), - File('${logDir.path}/${AppStrings.dataLogsFileName}'), - ]; - - for (var file in filesToClear) { - if (await file.exists()) { - await file.writeAsString(''); - } - } - } catch (e) { - logger.e("Failed to clear logs: ${e.toString()}"); - } - } @override void logError(String message) { diff --git a/lib/view_models/screen_config_view_model.dart b/lib/view_models/screen_config_view_model.dart index a668ce5..8b5dd9c 100644 --- a/lib/view_models/screen_config_view_model.dart +++ b/lib/view_models/screen_config_view_model.dart @@ -14,6 +14,7 @@ import 'package:hmg_qline/models/prayers_widget_model.dart'; import 'package:hmg_qline/models/rss_feed_model.dart'; import 'package:hmg_qline/models/weathers_widget_model.dart'; import 'package:hmg_qline/repositories/screen_details_repo.dart'; +import 'package:hmg_qline/repositories/signalR_repo.dart'; import 'package:hmg_qline/services/cache_service.dart'; import 'package:hmg_qline/services/connectivity_service.dart'; import 'package:hmg_qline/services/logger_service.dart'; @@ -57,7 +58,7 @@ class ScreenConfigViewModel extends ChangeNotifier { // nativeMethodChannelService.reopenApp(); nativeMethodChannelService.restartApp(); - runApp(const MyApp()); + // runApp(const MyApp()); } Future waitForIPAndInitializeConfigVM() async { @@ -229,18 +230,7 @@ class ScreenConfigViewModel extends ChangeNotifier { void getNextPrayerToShow() async { final current = DateTime.now(); - log("Checking Namaz time Locally at ${current.toString()} and ${current.timeZoneName} "); - - if (!isHubConnected) { - log("Hub is Not Connected!, I will try to reconnect now."); - QueuingViewModel queuingViewModel = getIt.get(); - bool? status = await queuingViewModel.startHubConnection(); - if (status != false) { - updateIsHubConnected(true); - } - } else { - log("Hub is Connected!"); - } + log("Checking Namaz time Locally at $current and ${current.timeZoneName}"); // log("Data Before Check : ${prayersWidgetModel.fajr}"); // log("Data Before Check : ${globalConfigurationsModel.isPrayerTimeReq}"); @@ -287,7 +277,7 @@ class ScreenConfigViewModel extends ChangeNotifier { } int counter = 0; - + DateTime lastChecked = DateTime.now(); Timer? _midnightTimer; Future getTheWidgetsConfigurationsEveryMidnight() async { @@ -298,16 +288,18 @@ class ScreenConfigViewModel extends ChangeNotifier { return; } - int counter = 0; - DateTime lastChecked = DateTime.now(); + // Only start timer if not already running + if (_midnightTimer != null) { + return; + } - _midnightTimer = Timer.periodic(const Duration(minutes: 5), (timer) async { + _midnightTimer = Timer.periodic(const Duration(minutes: 1), (timer) async { counter++; DateTime now = DateTime.now(); log("counterValue: $counter"); // Every hour, update RSS feed if required - if (counter % 12 == 0 && globalConfigurationsModel.isRssFeedReq) { + if (counter % 60 == 0 && globalConfigurationsModel.isRssFeedReq) { await getRssFeedDetailsFromServer(); } @@ -326,6 +318,7 @@ class ScreenConfigViewModel extends ChangeNotifier { } getNextPrayerToShow(); + syncHubConnectionState(); }); } @@ -534,4 +527,20 @@ class ScreenConfigViewModel extends ChangeNotifier { await qrViewController!.flipCamera(); } } + + void syncHubConnectionState() async { + QueuingViewModel queuingViewModel = getIt.get(); + bool newState = (queuingViewModel.signalrRepo as SignalrRepoImp).isConnected; + if (isHubConnected != newState) { + updateIsHubConnected(newState); + } + if (!isHubConnected) { + log("Hub is Not Connected!, I will try to reconnect now."); + QueuingViewModel queuingViewModel = getIt.get(); + bool? status = await queuingViewModel.startHubConnection(); + // syncHubConnectionState will update isHubConnected + } else { + log("Hub is Connected!"); + } + } } diff --git a/lib/views/splash_screen/splash_screen.dart b/lib/views/splash_screen/splash_screen.dart index e03e1b1..a4b2885 100644 --- a/lib/views/splash_screen/splash_screen.dart +++ b/lib/views/splash_screen/splash_screen.dart @@ -47,8 +47,6 @@ class SplashScreen extends StatelessWidget { // If the data is loaded successfully if (snapshot.connectionState == ConnectionState.done) { Future.delayed(const Duration(seconds: 1)).whenComplete(() { - // log("context.read().currentScreenTypeEnum: ${context.read().currentScreenTypeEnum}"); - // log("context.read().currentQTypeEnum: ${context.read().currentQTypeEnum}"); if (context.read().currentScreenTypeEnum == ScreenTypeEnum.kioskScreen) { context.navigateReplaceTo(AppRoutes.kioskMainScreen); } else {