updated README.md and logger_service.dart

appointment_merge
Faiz Hashmi 3 months ago
parent 87880ce1a6
commit 4c54191a34

@ -106,7 +106,7 @@ class AppConstants {
static String testIP = '12.4.5.1'; // projectID.QlineType.ScreenType.AnyNumber (1 to 10) static String testIP = '12.4.5.1'; // projectID.QlineType.ScreenType.AnyNumber (1 to 10)
static int thresholdForListUI = 3; static int thresholdForListUI = 3;
static double currentBuildVersion = 8.4; static double currentBuildVersion = 8.5;
static double clearLogsHoursThreshold = 48; static double clearLogsHoursThreshold = 48;
} }

@ -32,7 +32,11 @@ class PrayersWidgetModel {
} }
static dateTimeConversion(String date, String time) { 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 @override

@ -21,6 +21,8 @@ class SignalrRepoImp implements SignalrRepo {
HubConnection? connection; HubConnection? connection;
LoggerService loggerService; LoggerService loggerService;
bool get isConnected => connection?.state == HubConnectionState.connected;
SignalrRepoImp({this.connection, required this.loggerService}); SignalrRepoImp({this.connection, required this.loggerService});
@override @override
@ -54,11 +56,9 @@ class SignalrRepoImp implements SignalrRepo {
connection!.onclose((exception) async { connection!.onclose((exception) async {
log(exception.toString()); log(exception.toString());
onHubDisconnected(exception); onHubDisconnected(exception);
// Attempt to reconnect with limit and delay
if (reconnectAttempts < maxReconnectAttempts) { if (reconnectAttempts < maxReconnectAttempts) {
reconnectAttempts++; reconnectAttempts++;
loggerService.logToFile(message: "SignalR reconnect attempt #$reconnectAttempts", source: "startHubConnection -> signalR_repo.dart", type: LogTypeEnum.data); loggerService.logToFile(message: "SignalR reconnect attempt #$reconnectAttempts", source: "startHubConnection -> signalR_repo.dart", type: LogTypeEnum.data);
await Future.delayed(reconnectDelay); await Future.delayed(reconnectDelay);
try { try {
await connection!.start(); await connection!.start();

@ -11,7 +11,6 @@ import 'package:path_provider/path_provider.dart';
abstract class LoggerService { abstract class LoggerService {
Future<void> logToFile({required String message, required LogTypeEnum type, required String source}); Future<void> logToFile({required String message, required LogTypeEnum type, required String source});
Future<void> clearLogs();
void logError(String message); void logError(String message);
@ -59,26 +58,6 @@ class LoggerServiceImp implements LoggerService {
} }
} }
@override
Future<void> 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 @override
void logError(String message) { void logError(String message) {

@ -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/rss_feed_model.dart';
import 'package:hmg_qline/models/weathers_widget_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/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/cache_service.dart';
import 'package:hmg_qline/services/connectivity_service.dart'; import 'package:hmg_qline/services/connectivity_service.dart';
import 'package:hmg_qline/services/logger_service.dart'; import 'package:hmg_qline/services/logger_service.dart';
@ -57,7 +58,7 @@ class ScreenConfigViewModel extends ChangeNotifier {
// nativeMethodChannelService.reopenApp(); // nativeMethodChannelService.reopenApp();
nativeMethodChannelService.restartApp(); nativeMethodChannelService.restartApp();
runApp(const MyApp()); // runApp(const MyApp());
} }
Future<void> waitForIPAndInitializeConfigVM() async { Future<void> waitForIPAndInitializeConfigVM() async {
@ -229,18 +230,7 @@ class ScreenConfigViewModel extends ChangeNotifier {
void getNextPrayerToShow() async { void getNextPrayerToShow() async {
final current = DateTime.now(); final current = DateTime.now();
log("Checking Namaz time Locally at ${current.toString()} and ${current.timeZoneName} "); log("Checking Namaz time Locally at $current and ${current.timeZoneName}");
if (!isHubConnected) {
log("Hub is Not Connected!, I will try to reconnect now.");
QueuingViewModel queuingViewModel = getIt.get<QueuingViewModel>();
bool? status = await queuingViewModel.startHubConnection();
if (status != false) {
updateIsHubConnected(true);
}
} else {
log("Hub is Connected!");
}
// log("Data Before Check : ${prayersWidgetModel.fajr}"); // log("Data Before Check : ${prayersWidgetModel.fajr}");
// log("Data Before Check : ${globalConfigurationsModel.isPrayerTimeReq}"); // log("Data Before Check : ${globalConfigurationsModel.isPrayerTimeReq}");
@ -287,7 +277,7 @@ class ScreenConfigViewModel extends ChangeNotifier {
} }
int counter = 0; int counter = 0;
DateTime lastChecked = DateTime.now();
Timer? _midnightTimer; Timer? _midnightTimer;
Future<void> getTheWidgetsConfigurationsEveryMidnight() async { Future<void> getTheWidgetsConfigurationsEveryMidnight() async {
@ -298,16 +288,18 @@ class ScreenConfigViewModel extends ChangeNotifier {
return; return;
} }
int counter = 0; // Only start timer if not already running
DateTime lastChecked = DateTime.now(); if (_midnightTimer != null) {
return;
}
_midnightTimer = Timer.periodic(const Duration(minutes: 5), (timer) async { _midnightTimer = Timer.periodic(const Duration(minutes: 1), (timer) async {
counter++; counter++;
DateTime now = DateTime.now(); DateTime now = DateTime.now();
log("counterValue: $counter"); log("counterValue: $counter");
// Every hour, update RSS feed if required // Every hour, update RSS feed if required
if (counter % 12 == 0 && globalConfigurationsModel.isRssFeedReq) { if (counter % 60 == 0 && globalConfigurationsModel.isRssFeedReq) {
await getRssFeedDetailsFromServer(); await getRssFeedDetailsFromServer();
} }
@ -326,6 +318,7 @@ class ScreenConfigViewModel extends ChangeNotifier {
} }
getNextPrayerToShow(); getNextPrayerToShow();
syncHubConnectionState();
}); });
} }
@ -534,4 +527,20 @@ class ScreenConfigViewModel extends ChangeNotifier {
await qrViewController!.flipCamera(); await qrViewController!.flipCamera();
} }
} }
void syncHubConnectionState() async {
QueuingViewModel queuingViewModel = getIt.get<QueuingViewModel>();
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<QueuingViewModel>();
bool? status = await queuingViewModel.startHubConnection();
// syncHubConnectionState will update isHubConnected
} else {
log("Hub is Connected!");
}
}
} }

@ -47,8 +47,6 @@ class SplashScreen extends StatelessWidget {
// If the data is loaded successfully // If the data is loaded successfully
if (snapshot.connectionState == ConnectionState.done) { if (snapshot.connectionState == ConnectionState.done) {
Future.delayed(const Duration(seconds: 1)).whenComplete(() { Future.delayed(const Duration(seconds: 1)).whenComplete(() {
// log("context.read<ScreenConfigViewModel>().currentScreenTypeEnum: ${context.read<ScreenConfigViewModel>().currentScreenTypeEnum}");
// log("context.read<ScreenConfigViewModel>().currentQTypeEnum: ${context.read<ScreenConfigViewModel>().currentQTypeEnum}");
if (context.read<ScreenConfigViewModel>().currentScreenTypeEnum == ScreenTypeEnum.kioskScreen) { if (context.read<ScreenConfigViewModel>().currentScreenTypeEnum == ScreenTypeEnum.kioskScreen) {
context.navigateReplaceTo(AppRoutes.kioskMainScreen); context.navigateReplaceTo(AppRoutes.kioskMainScreen);
} else { } else {

Loading…
Cancel
Save