Remade frontend dashboard as flutter dashboard, still WIP
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:sqlite3/sqlite3.dart';
|
||||
import 'package:xp_nix/src/monitors/productivity_monitor.dart';
|
||||
import 'package:xp_nix/src/config/config_manager.dart';
|
||||
import 'package:xp_nix/src/logging/logger.dart';
|
||||
import 'package:xp_nix/src/web/dashboard_server.dart';
|
||||
import 'package:xp_nix/src/database/database_manager.dart';
|
||||
import 'package:xp_nix/src/detectors/idle_monitor.dart';
|
||||
import 'package:xp_nix/src/providers/system_time_provider.dart';
|
||||
import 'package:xp_nix/src/enhancers/hyprland_enhancer.dart';
|
||||
|
||||
// Enhanced main function with interactive commands and one-shot mode
|
||||
void main(List<String> args) async {
|
||||
// Initialize logging system
|
||||
await Logger.instance.initialize(level: LogLevel.info, logDirectory: 'logs', maxFileSizeMB: 10, maxFiles: 5);
|
||||
|
||||
// Initialize configuration manager
|
||||
await ConfigManager.instance.initialize();
|
||||
|
||||
final db = sqlite3.open('productivity_tracker.db');
|
||||
|
||||
// Create production dependencies
|
||||
final idleMonitor = IdleMonitor();
|
||||
final timeProvider = SystemTimeProvider();
|
||||
final desktopEnhancer = HyprlandEnhancer();
|
||||
|
||||
// Create monitor with dependency injection
|
||||
final monitor = ProductivityMonitor(
|
||||
db: db,
|
||||
idleMonitor: idleMonitor,
|
||||
timeProvider: timeProvider,
|
||||
desktopEnhancer: desktopEnhancer,
|
||||
// No activity detector provided - will use legacy polling mode
|
||||
);
|
||||
|
||||
final dashboardServer = DashboardServer.withDatabase(DatabaseManager(db));
|
||||
|
||||
ProcessSignal.sigint.watch().listen((_) async {
|
||||
Logger.info('Shutting down XP Nix...');
|
||||
print('\nShutting down...');
|
||||
|
||||
monitor.stop();
|
||||
await dashboardServer.stop();
|
||||
await Logger.instance.dispose();
|
||||
db.dispose();
|
||||
exit(0);
|
||||
});
|
||||
|
||||
// Start the dashboard server
|
||||
try {
|
||||
await dashboardServer.start(8080);
|
||||
Logger.info('Dashboard available at: ${dashboardServer.dashboardUrl}');
|
||||
print('🌐 Dashboard available at: ${dashboardServer.dashboardUrl}');
|
||||
} catch (e) {
|
||||
Logger.error('Failed to start dashboard server: $e');
|
||||
print('⚠️ Dashboard server failed to start: $e');
|
||||
}
|
||||
|
||||
monitor.start();
|
||||
monitor.printDetailedStats();
|
||||
|
||||
// Add command listener for manual controls
|
||||
stdin.transform(utf8.decoder).transform(LineSplitter()).listen((line) {
|
||||
final parts = line.trim().split(' ');
|
||||
final command = parts[0].toLowerCase();
|
||||
|
||||
switch (command) {
|
||||
case 'stats':
|
||||
monitor.printDetailedStats();
|
||||
break;
|
||||
case 'test':
|
||||
if (parts.length > 1) {
|
||||
final level = int.tryParse(parts[1]) ?? 1;
|
||||
monitor.testTheme(level);
|
||||
}
|
||||
break;
|
||||
case 'restore':
|
||||
monitor.restoreDesktop();
|
||||
break;
|
||||
case 'refresh':
|
||||
monitor.refreshConfig();
|
||||
break;
|
||||
case 'help':
|
||||
print('''
|
||||
Available commands:
|
||||
- stats: Show current productivity stats
|
||||
- test [level]: Test theme for specific level
|
||||
- restore: Restore desktop backup
|
||||
- refresh: Refresh base config from current system config
|
||||
- help: Show this help
|
||||
''');
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
print('💡 Type "help" for available commands');
|
||||
|
||||
// Keep running and show stats periodically
|
||||
while (true) {
|
||||
await Future.delayed(Duration(seconds: 1));
|
||||
|
||||
if (DateTime.now().second == 0 && DateTime.now().minute % 10 == 0) {
|
||||
monitor.printDetailedStats();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user