|
|
|
@@ -7,6 +7,11 @@ import 'package:system_tray/system_tray.dart';
|
|
|
|
|
import 'package:window_manager/window_manager.dart';
|
|
|
|
|
import 'package:audioplayers/audioplayers.dart';
|
|
|
|
|
|
|
|
|
|
// TODO: Add an icon to the executable, simply use the existing tray icon
|
|
|
|
|
// TODO: Add an entry field for the duration ie. the interval of apperance
|
|
|
|
|
// TODO: Also the sound file, if possible...
|
|
|
|
|
// TODO: Cram the above into the database
|
|
|
|
|
|
|
|
|
|
const Duration popupInterval = Duration(minutes: 20);
|
|
|
|
|
const String notificationSound = 'MeetTheSniper.mp3';
|
|
|
|
|
|
|
|
|
@@ -116,16 +121,18 @@ class MainPage extends StatefulWidget {
|
|
|
|
|
const MainPage({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<MainPage> createState() => _MainPageState();
|
|
|
|
|
State<MainPage> createState() => MainPageState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _MainPageState extends State<MainPage> with WindowListener {
|
|
|
|
|
class MainPageState extends State<MainPage> with WindowListener {
|
|
|
|
|
final SystemTray _systemTray = SystemTray();
|
|
|
|
|
final Menu _menu = Menu();
|
|
|
|
|
final AudioPlayer _audioPlayer = AudioPlayer();
|
|
|
|
|
|
|
|
|
|
final TextEditingController _previousEntryController =
|
|
|
|
|
TextEditingController();
|
|
|
|
|
final TextEditingController _currentEntryController = TextEditingController();
|
|
|
|
|
final FocusNode _currentEntryFocusNode = FocusNode();
|
|
|
|
|
final TextEditingController _todoController = TextEditingController();
|
|
|
|
|
|
|
|
|
|
Note? previousNote;
|
|
|
|
@@ -151,6 +158,7 @@ class _MainPageState extends State<MainPage> with WindowListener {
|
|
|
|
|
_debounceTimer?.cancel();
|
|
|
|
|
_previousEntryController.dispose();
|
|
|
|
|
_currentEntryController.dispose();
|
|
|
|
|
_currentEntryFocusNode.dispose();
|
|
|
|
|
_todoController.dispose();
|
|
|
|
|
_audioPlayer.dispose();
|
|
|
|
|
super.dispose();
|
|
|
|
@@ -172,9 +180,22 @@ class _MainPageState extends State<MainPage> with WindowListener {
|
|
|
|
|
|
|
|
|
|
await _systemTray.initSystemTray(iconPath: iconPath, toolTip: "Journaler");
|
|
|
|
|
|
|
|
|
|
await _menu.buildFrom([
|
|
|
|
|
MenuItemLabel(
|
|
|
|
|
label: 'Commit Sudoku',
|
|
|
|
|
onClicked: (menuItem) => windowManager.destroy(),
|
|
|
|
|
),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
await _systemTray.setContextMenu(_menu);
|
|
|
|
|
|
|
|
|
|
_systemTray.registerSystemTrayEventHandler((eventName) {
|
|
|
|
|
debugPrint("System Tray Event: $eventName");
|
|
|
|
|
if (eventName == kSystemTrayEventClick) {
|
|
|
|
|
_showWindow();
|
|
|
|
|
} else if (eventName == kSystemTrayEventRightClick) {
|
|
|
|
|
_systemTray.popUpContextMenu();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -192,9 +213,11 @@ class _MainPageState extends State<MainPage> with WindowListener {
|
|
|
|
|
await windowManager.center();
|
|
|
|
|
await windowManager.show();
|
|
|
|
|
await windowManager.focus();
|
|
|
|
|
_currentEntryFocusNode.requestFocus();
|
|
|
|
|
await _playSound();
|
|
|
|
|
} else {
|
|
|
|
|
await windowManager.focus();
|
|
|
|
|
_currentEntryFocusNode.requestFocus();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -237,13 +260,17 @@ class _MainPageState extends State<MainPage> with WindowListener {
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return KeyboardListener(
|
|
|
|
|
focusNode: FocusNode(),
|
|
|
|
|
autofocus: true,
|
|
|
|
|
onKeyEvent: (event) {
|
|
|
|
|
if (event is KeyDownEvent &&
|
|
|
|
|
// Wrap Scaffold with RawKeyboardListener as workaround for Escape key
|
|
|
|
|
return RawKeyboardListener(
|
|
|
|
|
focusNode: FocusNode(), // Needs its own node
|
|
|
|
|
onKey: (RawKeyEvent event) {
|
|
|
|
|
if (event is RawKeyDownEvent &&
|
|
|
|
|
event.logicalKey == LogicalKeyboardKey.escape) {
|
|
|
|
|
debugPrint("Escape key pressed - hiding window.");
|
|
|
|
|
debugPrint(
|
|
|
|
|
"Escape pressed inside MainPage (RawKeyboardListener - Workaround)",
|
|
|
|
|
);
|
|
|
|
|
// Call method directly since we are in the state
|
|
|
|
|
FocusManager.instance.primaryFocus?.unfocus(); // Keep unfocus attempt
|
|
|
|
|
onWindowClose();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
@@ -274,6 +301,7 @@ class _MainPageState extends State<MainPage> with WindowListener {
|
|
|
|
|
Expanded(
|
|
|
|
|
child: TextField(
|
|
|
|
|
controller: _currentEntryController,
|
|
|
|
|
focusNode: _currentEntryFocusNode,
|
|
|
|
|
maxLines: null,
|
|
|
|
|
expands: true,
|
|
|
|
|
autofocus: true,
|
|
|
|
@@ -312,3 +340,5 @@ class _MainPageState extends State<MainPage> with WindowListener {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- End Actions and Shortcuts ---
|
|
|
|
|