Skip to content
Merged
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 @@ -10,7 +10,7 @@ import 'package:whph/core/domain/features/app_usages/app_usage_time_record.dart'
import 'package:whph/core/application/features/app_usages/services/abstraction/i_app_usage_repository.dart';
import 'package:whph/core/application/features/app_usages/services/abstraction/i_app_usage_time_record_repository.dart';
import 'package:whph/core/domain/shared/constants/app_theme.dart';
import 'package:whph/core/shared/utils/logger.dart';
import 'package:whph/core/domain/shared/utils/logger.dart';
import 'i_app_usage_service.dart';
import 'package:whph/core/application/features/app_usages/services/abstraction/i_app_usage_tag_rule_repository.dart';
import 'package:whph/core/application/features/app_usages/services/abstraction/i_app_usage_tag_repository.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:flutter/foundation.dart';
import 'package:whph/core/application/features/app_usages/constants/system_app_exclusions.dart';
import 'package:whph/core/application/features/app_usages/services/abstraction/i_app_usage_filter_service.dart';
import 'package:whph/core/application/features/app_usages/services/abstraction/i_app_usage_ignore_rule_repository.dart';
import 'package:whph/core/shared/utils/logger.dart';
import 'package:whph/core/domain/shared/utils/logger.dart';

class AppUsageFilterService implements IAppUsageFilterService {
final IAppUsageIgnoreRuleRepository _appUsageIgnoreRuleRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import 'package:whph/core/domain/features/habits/habit_tag.dart';
import 'package:whph/core/domain/features/notes/note_tag.dart';
import 'package:whph/core/domain/features/app_usages/app_usage_tag.dart';
import 'package:whph/core/application/shared/utils/key_helper.dart';
import 'package:whph/core/shared/utils/logger.dart';
import 'package:whph/core/domain/shared/utils/logger.dart';

/// Demo data service implementation
///
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:mediatr/mediatr.dart';
import 'package:whph/core/application/features/sync/services/abstraction/i_sync_service.dart';
import 'package:whph/core/shared/utils/logger.dart';
import 'package:whph/core/domain/shared/utils/logger.dart';

class StartSyncCommand implements IRequest<void> {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:mediatr/mediatr.dart';
import 'package:whph/core/application/features/sync/services/abstraction/i_sync_device_repository.dart';
import 'package:whph/core/shared/utils/logger.dart';
import 'package:whph/core/domain/shared/utils/logger.dart';
import 'package:acore/acore.dart';
import 'package:whph/core/application/features/sync/constants/sync_translation_keys.dart';

Expand Down Expand Up @@ -54,15 +54,15 @@ class UpdateSyncDeviceIpCommandHandler

await _syncDeviceRepository.update(syncDevice);

Logger.info('βœ… Updated sync device ${request.deviceId} IP address from $oldIpAddress to ${request.newIpAddress}');
Logger.info('Updated sync device ${request.deviceId} IP address from $oldIpAddress to ${request.newIpAddress}');

return UpdateSyncDeviceIpCommandResponse(
success: true,
message: 'IP address updated successfully',
oldIpAddress: oldIpAddress,
);
} catch (e) {
Logger.error('❌ Failed to update sync device IP: $e');
Logger.error('Failed to update sync device IP: $e');
return UpdateSyncDeviceIpCommandResponse(
success: false,
message: e.toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import 'package:whph/core/domain/features/settings/setting.dart';
import 'package:whph/core/domain/features/sync/sync_device.dart';
import 'package:whph/core/domain/features/notes/note.dart';
import 'package:whph/core/domain/features/notes/note_tag.dart';
import 'package:whph/core/shared/utils/logger.dart';
import 'package:whph/core/domain/shared/utils/logger.dart';

@jsonSerializable
class SyncData<T extends BaseEntity<dynamic>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import 'dart:io';
import 'package:dart_json_mapper/dart_json_mapper.dart';
import 'package:whph/core/application/features/sync/services/abstraction/i_concurrent_connection_service.dart';
import 'package:whph/core/application/shared/models/websocket_request.dart';
import 'package:whph/core/shared/utils/logger.dart';
import 'package:whph/core/shared/utils/unawaited.dart';
import 'package:whph/core/domain/shared/utils/logger.dart';

/// Service for establishing concurrent connections to multiple IP addresses
/// Implements intelligent connection logic with timeout handling and cancellation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:whph/core/shared/utils/logger.dart';
import 'package:whph/core/domain/shared/utils/logger.dart';
import 'package:whph/infrastructure/persistence/shared/contexts/drift/drift_app_context.dart';

class DatabaseIntegrityService {
Expand All @@ -20,24 +20,24 @@ class DatabaseIntegrityService {

/// Automatically fix common integrity issues
Future<void> fixIntegrityIssues() async {
Logger.info('πŸ”§ Starting database integrity fixes...');
Logger.info('Starting database integrity fixes...');

await _fixDuplicateIds();
await _cleanupOrphanedReferences();
await _fixSyncStateIssues();

Logger.info('βœ… Database integrity fixes completed');
Logger.info('Database integrity fixes completed');
}

/// Fix only critical integrity issues (not ancient devices)
Future<void> fixCriticalIntegrityIssues() async {
Logger.info('πŸ”§ Starting critical database integrity fixes...');
Logger.info('Starting critical database integrity fixes...');

await _fixDuplicateIds();
await _cleanupOrphanedReferences();
// Skip _fixSyncStateIssues() as it includes ancient device cleanup

Logger.info('βœ… Critical database integrity fixes completed');
Logger.info('Critical database integrity fixes completed');
}

Future<void> _checkDuplicateIds(DatabaseIntegrityReport report) async {
Expand Down Expand Up @@ -103,7 +103,7 @@ class DatabaseIntegrityService {
}

Future<void> _checkSyncStateConsistency(DatabaseIntegrityReport report) async {
Logger.debug('πŸ” Checking sync state consistency...');
Logger.debug('Checking sync state consistency...');

try {
// Check for sync devices with invalid IP addresses
Expand Down Expand Up @@ -149,7 +149,7 @@ class DatabaseIntegrityService {
final oldestDate = oldSyncDevices.data['oldest_date'] as String?;
final newestDate = oldSyncDevices.data['newest_date'] as String?;

Logger.debug('πŸ“… Sync device date analysis: count=$totalCount, oldest=$oldestDate, newest=$newestDate');
Logger.debug('Sync device date analysis: count=$totalCount, oldest=$oldestDate, newest=$newestDate');

// Check for devices older than 5 years
// First, get accurate count
Expand Down Expand Up @@ -179,7 +179,7 @@ class DatabaseIntegrityService {
for (final device in ancientDeviceSamples) {
final deviceId = device.data['id'] as String?;
final createdDate = device.data['created_date'] as String?;
Logger.warning(' - Device ID: $deviceId, Created: $createdDate');
Logger.warning('- Device ID: $deviceId, Created: $createdDate');
}
}
}
Expand All @@ -201,9 +201,9 @@ class DatabaseIntegrityService {
}
}

Logger.debug('βœ… Sync state consistency check completed');
Logger.debug('Sync state consistency check completed');
} catch (e) {
Logger.warning('⚠️ Error during sync state consistency check: $e');
Logger.warning('Error during sync state consistency check: $e');
// Don't let sync state check failures prevent other integrity checks
}
}
Expand All @@ -219,7 +219,7 @@ class DatabaseIntegrityService {
];

for (final tableName in tables) {
Logger.info('πŸ”§ Fixing duplicates in $tableName...');
Logger.info('Fixing duplicates in $tableName...');

// Keep the most recent record for each ID, soft-delete the rest
await _database.customStatement('''
Expand All @@ -236,7 +236,7 @@ class DatabaseIntegrityService {
}

Future<void> _cleanupOrphanedReferences() async {
Logger.info('πŸ”§ Cleaning up orphaned references...');
Logger.info('Cleaning up orphaned references...');

// Soft-delete task_tags that reference deleted tags
await _database.customStatement('''
Expand All @@ -258,7 +258,7 @@ class DatabaseIntegrityService {
}

Future<void> _fixSyncStateIssues() async {
Logger.info('πŸ”§ Fixing sync state issues...');
Logger.info('Fixing sync state issues...');

try {
// Fix sync devices with invalid IP addresses by setting them to localhost
Expand All @@ -275,7 +275,7 @@ class DatabaseIntegrityService {
WHERE deleted_date IS NULL
AND (from_ip IS NULL OR from_ip = '' OR to_ip IS NULL OR to_ip = '')
''');
Logger.debug('πŸ”§ Fixed invalid IP addresses in sync devices');
Logger.debug('Fixed invalid IP addresses in sync devices');

// Soft-delete duplicate sync devices, keeping the most recent one
await _database.customStatement('''
Expand All @@ -288,7 +288,7 @@ class DatabaseIntegrityService {
GROUP BY from_device_id, to_device_id
) AND deleted_date IS NULL
''');
Logger.debug('πŸ”§ Soft-deleted duplicate sync device records');
Logger.debug('Soft-deleted duplicate sync device records');

// Fix sync devices with invalid device IDs by setting them to default values
await _database.customStatement('''
Expand All @@ -304,7 +304,7 @@ class DatabaseIntegrityService {
WHERE deleted_date IS NULL
AND (from_device_id IS NULL OR from_device_id = '' OR to_device_id IS NULL OR to_device_id = '')
''');
Logger.debug('πŸ”§ Fixed invalid device IDs in sync devices');
Logger.debug('Fixed invalid device IDs in sync devices');

// Soft-delete extremely old sync devices (older than 5 years)
await _database.customStatement('''
Expand All @@ -313,11 +313,11 @@ class DatabaseIntegrityService {
WHERE deleted_date IS NULL
AND created_date < datetime('now', '-5 years')
''');
Logger.debug('πŸ”§ Soft-deleted ancient sync device records (older than 5 years)');
Logger.debug('Soft-deleted ancient sync device records (older than 5 years)');

Logger.info('βœ… Sync state issues fixed');
Logger.info('Sync state issues fixed');
} catch (e) {
Logger.error('❌ Error fixing sync state issues: $e');
Logger.error('Error fixing sync state issues: $e');
// Don't rethrow - sync state fix failures shouldn't prevent app startup
}
}
Expand All @@ -337,30 +337,30 @@ class DatabaseIntegrityReport {

@override
String toString() {
if (!hasIssues) return 'Database integrity: βœ… No issues found';
if (!hasIssues) return 'Database integrity: No issues found';

final buffer = StringBuffer('Database integrity issues found:\n');

if (duplicateIds.isNotEmpty) {
buffer.writeln('πŸ”„ Duplicate IDs:');
buffer.writeln('Duplicate IDs:');
duplicateIds.forEach((table, count) {
buffer.writeln(' - $table: $count duplicates');
});
}

if (orphanedReferences.isNotEmpty) {
buffer.writeln('πŸ”— Orphaned references:');
buffer.writeln('Orphaned references:');
orphanedReferences.forEach((type, count) {
buffer.writeln(' - $type: $count orphaned');
});
}

if (softDeleteInconsistencies > 0) {
buffer.writeln('❌ Soft-delete inconsistencies: $softDeleteInconsistencies');
buffer.writeln('Soft-delete inconsistencies: $softDeleteInconsistencies');
}

if (syncStateIssues.isNotEmpty) {
buffer.writeln('πŸ”„ Sync state issues:');
buffer.writeln('Sync state issues:');
syncStateIssues.forEach((type, count) {
buffer.writeln(' - $type: $count issues');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'dart:async';
import 'package:dart_json_mapper/dart_json_mapper.dart';
import 'package:web_socket_channel/web_socket_channel.dart';
import 'package:whph/core/application/shared/models/websocket_request.dart';
import 'package:whph/core/shared/utils/logger.dart';
import 'package:whph/core/domain/shared/utils/logger.dart';

/// Service for performing device handshake to get device information
class DeviceHandshakeService {
Expand All @@ -12,7 +12,7 @@ class DeviceHandshakeService {
WebSocketChannel? channel;
StreamSubscription? subscription;
try {
Logger.info('🀝 Attempting handshake with device at $ipAddress:$port');
Logger.info('Attempting handshake with device at $ipAddress:$port');

// Connect to the device
final uri = Uri.parse('ws://$ipAddress:$port');
Expand All @@ -25,7 +25,7 @@ class DeviceHandshakeService {
subscription = channel.stream.listen(
(message) {
try {
Logger.debug('πŸ“¨ Received handshake response: $message');
Logger.debug('Received handshake response: $message');
final response = JsonMapper.deserialize<WebSocketMessage>(message.toString());

if (response?.type == 'device_info_response') {
Expand Down Expand Up @@ -56,37 +56,37 @@ class DeviceHandshakeService {
);

Logger.info(
'βœ… Device handshake successful: ${deviceInfo.deviceName} (${deviceInfo.deviceId}) - Capabilities: ${deviceInfo.capabilitiesText}');
'Device handshake successful: ${deviceInfo.deviceName} (${deviceInfo.deviceId}) - Capabilities: ${deviceInfo.capabilitiesText}');
if (!completer.isCompleted) {
completer.complete(deviceInfo);
}
} else {
Logger.warning('❌ Device handshake failed: ${data['error']}');
Logger.warning('Device handshake failed: ${data['error']}');
if (!completer.isCompleted) {
completer.complete(null);
}
}
} else if (response?.type == 'error') {
Logger.warning('❌ Device returned error during handshake');
Logger.warning('Device returned error during handshake');
if (!completer.isCompleted) {
completer.complete(null);
}
}
} catch (e) {
Logger.error('❌ Failed to parse handshake response: $e');
Logger.error('Failed to parse handshake response: $e');
if (!completer.isCompleted) {
completer.complete(null);
}
}
},
onError: (error) {
Logger.error('❌ WebSocket error during handshake: $error');
Logger.error('WebSocket error during handshake: $error');
if (!completer.isCompleted) {
completer.complete(null);
}
},
onDone: () {
Logger.debug('πŸ”š Handshake WebSocket connection closed');
Logger.debug('Handshake WebSocket connection closed');
if (!completer.isCompleted) {
completer.complete(null);
}
Expand All @@ -100,7 +100,7 @@ class DeviceHandshakeService {
);

channel.sink.add(JsonMapper.serialize(request));
Logger.debug('πŸ“€ Sent device info request to $ipAddress:$port');
Logger.debug('Sent device info request to $ipAddress:$port');

// Wait for response with timeout
final result = await completer.future.timeout(
Expand All @@ -113,7 +113,7 @@ class DeviceHandshakeService {

return result;
} catch (e) {
Logger.error('❌ Device handshake failed for $ipAddress:$port - $e');
Logger.error('Device handshake failed for $ipAddress:$port - $e');
return null;
} finally {
// Clean up subscription
Expand Down
Loading