Implement whole ass "backend"

This commit is contained in:
2025-04-21 22:24:41 +02:00
parent 740fef5d7d
commit 427b503e5e
5 changed files with 202 additions and 34 deletions

View File

@@ -1,6 +1,8 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:journaler/db.dart';
import 'package:journaler/notes.dart';
import 'package:system_tray/system_tray.dart';
import 'package:window_manager/window_manager.dart';
import 'package:audioplayers/audioplayers.dart';
@@ -9,6 +11,7 @@ const Duration popupInterval = Duration(hours: 1);
const String notificationSound = 'MeetTheSniper.mp3';
void main() async {
await DB.init();
WidgetsFlutterBinding.ensureInitialized();
await windowManager.ensureInitialized();
@@ -125,6 +128,8 @@ class _MainPageState extends State<MainPage> with WindowListener {
final TextEditingController _currentEntryController = TextEditingController();
final TextEditingController _todoController = TextEditingController();
Note? previousNote;
Timer? _popupTimer;
Timer? _debounceTimer;
@@ -180,6 +185,7 @@ class _MainPageState extends State<MainPage> with WindowListener {
}
Future<void> _showWindow() async {
_loadData();
bool wasVisible = await windowManager.isVisible();
if (!wasVisible) {
await windowManager.setSize(const Size(1600, 900));
@@ -193,47 +199,38 @@ class _MainPageState extends State<MainPage> with WindowListener {
}
Future<void> _playSound() async {
try {
await _audioPlayer.stop();
await _audioPlayer.play(AssetSource('sounds/$notificationSound'));
debugPrint("Played sound: $notificationSound");
} catch (e, stackTrace) {
debugPrint("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
debugPrint("Error playing sound '$notificationSound': $e");
debugPrint("Stack trace: $stackTrace");
debugPrint(
"Ensure file exists, is valid audio, and assets/sounds/ is in pubspec.yaml",
);
debugPrint("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
await _audioPlayer.stop();
await _audioPlayer.play(AssetSource('sounds/$notificationSound'));
debugPrint("Played sound: $notificationSound");
}
void _loadData() {
_previousEntryController.text =
"This is a placeholder for the previous entry.";
_todoController.text = "- Placeholder Todo 1\n- Placeholder Todo 2";
void _loadData() async {
final note = await getLatestNote();
previousNote = note;
_previousEntryController.text = note?.content ?? "";
final todo = await getLatestTodo();
_todoController.text = todo?.content ?? "";
_currentEntryController.text = "";
debugPrint("Data loaded (placeholder).");
}
void _saveData() {
void _saveData() async {
String previousEntry = _previousEntryController.text;
String currentEntry = _currentEntryController.text;
String todoList = _todoController.text;
print(
await createNote(currentEntry);
await createTodo(todoList);
previousNote!.content = previousEntry;
await updateNote(previousNote!);
debugPrint(
"Saving data (placeholder)... Current Entry: [${currentEntry.length} chars], Todo: [${todoList.length} chars]",
);
}
void _saveTodoList() {
if (_debounceTimer?.isActive ?? false) _debounceTimer!.cancel();
_debounceTimer = Timer(const Duration(milliseconds: 500), () {
String todoList = _todoController.text;
print("Debounced Save: Saving Todo list... [${todoList.length} chars]");
});
}
Future<void> _setWindowConfig() async {
await windowManager.setAspectRatio(16 / 9);
}
@@ -247,7 +244,7 @@ class _MainPageState extends State<MainPage> with WindowListener {
if (event is KeyDownEvent &&
event.logicalKey == LogicalKeyboardKey.escape) {
debugPrint("Escape key pressed - hiding window.");
windowManager.hide();
onWindowClose();
}
},
child: Scaffold(
@@ -302,14 +299,10 @@ class _MainPageState extends State<MainPage> with WindowListener {
context,
).textTheme.bodyMedium, // Apply theme text style
decoration: const InputDecoration(
labelText: 'Todo List',
labelText: 'Todo',
// border: OutlineInputBorder(), // Handled by theme
// contentPadding: EdgeInsets.all(8.0), // Handled by theme or default
),
onChanged: (text) {
// Auto-save Todo list changes (consider debouncing)
_saveTodoList();
},
),
),
],