Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
1051805463 | |||
173c4fbee2 | |||
d06a8d6698 | |||
d788c110a7 |
@@ -7,6 +7,11 @@ import 'package:system_tray/system_tray.dart';
|
|||||||
import 'package:window_manager/window_manager.dart';
|
import 'package:window_manager/window_manager.dart';
|
||||||
import 'package:audioplayers/audioplayers.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 Duration popupInterval = Duration(minutes: 20);
|
||||||
const String notificationSound = 'MeetTheSniper.mp3';
|
const String notificationSound = 'MeetTheSniper.mp3';
|
||||||
|
|
||||||
@@ -33,6 +38,9 @@ void main() async {
|
|||||||
class JournalerApp extends StatelessWidget {
|
class JournalerApp extends StatelessWidget {
|
||||||
const JournalerApp({super.key});
|
const JournalerApp({super.key});
|
||||||
|
|
||||||
|
static final GlobalKey<MainPageState> _mainPageKey =
|
||||||
|
GlobalKey<MainPageState>();
|
||||||
|
|
||||||
static final TextTheme _baseTextTheme = const TextTheme(
|
static final TextTheme _baseTextTheme = const TextTheme(
|
||||||
bodyMedium: TextStyle(fontSize: 24),
|
bodyMedium: TextStyle(fontSize: 24),
|
||||||
);
|
);
|
||||||
@@ -106,7 +114,30 @@ class JournalerApp extends StatelessWidget {
|
|||||||
theme: lightTheme,
|
theme: lightTheme,
|
||||||
darkTheme: darkTheme,
|
darkTheme: darkTheme,
|
||||||
themeMode: ThemeMode.system,
|
themeMode: ThemeMode.system,
|
||||||
home: const MainPage(),
|
home: Focus(
|
||||||
|
// Using RawKeyboardListener despite deprecation because KeyboardListener
|
||||||
|
// and Shortcuts/Actions didn't reliably capture the Escape key press
|
||||||
|
// before the TextField handled it for unfocusing, requiring two presses.
|
||||||
|
// RawKeyboardListener intercepts the event earlier.
|
||||||
|
child: RawKeyboardListener(
|
||||||
|
// Revert to RawKeyboardListener
|
||||||
|
focusNode: FocusNode(),
|
||||||
|
onKey: (RawKeyEvent event) {
|
||||||
|
// Revert to onKey and RawKeyEvent
|
||||||
|
if (event is RawKeyDownEvent && // Revert to RawKeyDownEvent
|
||||||
|
event.logicalKey == LogicalKeyboardKey.escape) {
|
||||||
|
debugPrint("Escape pressed (RawKeyboardListener - Workaround)");
|
||||||
|
final state = _mainPageKey.currentState;
|
||||||
|
if (state != null) {
|
||||||
|
// Re-add unfocus, as it seemed necessary with Raw listener
|
||||||
|
FocusManager.instance.primaryFocus?.unfocus();
|
||||||
|
state.onWindowClose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: MainPage(key: _mainPageKey),
|
||||||
|
),
|
||||||
|
),
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -116,16 +147,18 @@ class MainPage extends StatefulWidget {
|
|||||||
const MainPage({super.key});
|
const MainPage({super.key});
|
||||||
|
|
||||||
@override
|
@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 SystemTray _systemTray = SystemTray();
|
||||||
|
final Menu _menu = Menu();
|
||||||
final AudioPlayer _audioPlayer = AudioPlayer();
|
final AudioPlayer _audioPlayer = AudioPlayer();
|
||||||
|
|
||||||
final TextEditingController _previousEntryController =
|
final TextEditingController _previousEntryController =
|
||||||
TextEditingController();
|
TextEditingController();
|
||||||
final TextEditingController _currentEntryController = TextEditingController();
|
final TextEditingController _currentEntryController = TextEditingController();
|
||||||
|
final FocusNode _currentEntryFocusNode = FocusNode();
|
||||||
final TextEditingController _todoController = TextEditingController();
|
final TextEditingController _todoController = TextEditingController();
|
||||||
|
|
||||||
Note? previousNote;
|
Note? previousNote;
|
||||||
@@ -151,6 +184,7 @@ class _MainPageState extends State<MainPage> with WindowListener {
|
|||||||
_debounceTimer?.cancel();
|
_debounceTimer?.cancel();
|
||||||
_previousEntryController.dispose();
|
_previousEntryController.dispose();
|
||||||
_currentEntryController.dispose();
|
_currentEntryController.dispose();
|
||||||
|
_currentEntryFocusNode.dispose();
|
||||||
_todoController.dispose();
|
_todoController.dispose();
|
||||||
_audioPlayer.dispose();
|
_audioPlayer.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
@@ -172,9 +206,22 @@ class _MainPageState extends State<MainPage> with WindowListener {
|
|||||||
|
|
||||||
await _systemTray.initSystemTray(iconPath: iconPath, toolTip: "Journaler");
|
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) {
|
_systemTray.registerSystemTrayEventHandler((eventName) {
|
||||||
debugPrint("System Tray Event: $eventName");
|
debugPrint("System Tray Event: $eventName");
|
||||||
|
if (eventName == kSystemTrayEventClick) {
|
||||||
_showWindow();
|
_showWindow();
|
||||||
|
} else if (eventName == kSystemTrayEventRightClick) {
|
||||||
|
_systemTray.popUpContextMenu();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,9 +239,11 @@ class _MainPageState extends State<MainPage> with WindowListener {
|
|||||||
await windowManager.center();
|
await windowManager.center();
|
||||||
await windowManager.show();
|
await windowManager.show();
|
||||||
await windowManager.focus();
|
await windowManager.focus();
|
||||||
|
_currentEntryFocusNode.requestFocus();
|
||||||
await _playSound();
|
await _playSound();
|
||||||
} else {
|
} else {
|
||||||
await windowManager.focus();
|
await windowManager.focus();
|
||||||
|
_currentEntryFocusNode.requestFocus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,17 +286,7 @@ class _MainPageState extends State<MainPage> with WindowListener {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return KeyboardListener(
|
return Scaffold(
|
||||||
focusNode: FocusNode(),
|
|
||||||
autofocus: true,
|
|
||||||
onKeyEvent: (event) {
|
|
||||||
if (event is KeyDownEvent &&
|
|
||||||
event.logicalKey == LogicalKeyboardKey.escape) {
|
|
||||||
debugPrint("Escape key pressed - hiding window.");
|
|
||||||
onWindowClose();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child: Scaffold(
|
|
||||||
appBar: AppBar(title: const Text('Journaler'), actions: const []),
|
appBar: AppBar(title: const Text('Journaler'), actions: const []),
|
||||||
body: Padding(
|
body: Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
@@ -274,6 +313,7 @@ class _MainPageState extends State<MainPage> with WindowListener {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: TextField(
|
child: TextField(
|
||||||
controller: _currentEntryController,
|
controller: _currentEntryController,
|
||||||
|
focusNode: _currentEntryFocusNode,
|
||||||
maxLines: null,
|
maxLines: null,
|
||||||
expands: true,
|
expands: true,
|
||||||
autofocus: true,
|
autofocus: true,
|
||||||
@@ -308,7 +348,8 @@ class _MainPageState extends State<MainPage> with WindowListener {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- End Actions and Shortcuts ---
|
||||||
|
Reference in New Issue
Block a user