Fix notification sound
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -1,3 +1,4 @@
|
|||||||
*.ico filter=lfs diff=lfs merge=lfs -text
|
*.ico filter=lfs diff=lfs merge=lfs -text
|
||||||
*.png filter=lfs diff=lfs merge=lfs -text
|
*.png filter=lfs diff=lfs merge=lfs -text
|
||||||
*.ogg filter=lfs diff=lfs merge=lfs -text
|
*.ogg filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.mp3 filter=lfs diff=lfs merge=lfs -text
|
||||||
|
BIN
assets/sounds/MGSSpot.mp3
(Stored with Git LFS)
Normal file
BIN
assets/sounds/MGSSpot.mp3
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
assets/sounds/MeetTheSniper.mp3
(Stored with Git LFS)
Normal file
BIN
assets/sounds/MeetTheSniper.mp3
(Stored with Git LFS)
Normal file
Binary file not shown.
@@ -1,5 +1,7 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:io'; // Required for Platform check
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart'; // Needed for LogicalKeyboardKey
|
||||||
import 'package:system_tray/system_tray.dart';
|
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';
|
||||||
@@ -7,7 +9,7 @@ import 'package:audioplayers/audioplayers.dart';
|
|||||||
|
|
||||||
// --- Configuration ---
|
// --- Configuration ---
|
||||||
const Duration popupInterval = Duration(hours: 1); // How often to pop up
|
const Duration popupInterval = Duration(hours: 1); // How often to pop up
|
||||||
const String notificationSound = 'MeetTheSniper.ogg';
|
const String notificationSound = 'MeetTheSniper.mp3';
|
||||||
// --------------------
|
// --------------------
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
@@ -141,6 +143,7 @@ class _MainPageState extends State<MainPage> with WindowListener {
|
|||||||
final TextEditingController _todoController = TextEditingController();
|
final TextEditingController _todoController = TextEditingController();
|
||||||
|
|
||||||
Timer? _popupTimer;
|
Timer? _popupTimer;
|
||||||
|
Timer? _debounceTimer; // Timer for debouncing Todo saves
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -161,6 +164,7 @@ class _MainPageState extends State<MainPage> with WindowListener {
|
|||||||
void dispose() {
|
void dispose() {
|
||||||
windowManager.removeListener(this);
|
windowManager.removeListener(this);
|
||||||
_popupTimer?.cancel();
|
_popupTimer?.cancel();
|
||||||
|
_debounceTimer?.cancel(); // Cancel debounce timer on dispose
|
||||||
_previousEntryController.dispose();
|
_previousEntryController.dispose();
|
||||||
_currentEntryController.dispose();
|
_currentEntryController.dispose();
|
||||||
_todoController.dispose();
|
_todoController.dispose();
|
||||||
@@ -251,11 +255,20 @@ class _MainPageState extends State<MainPage> with WindowListener {
|
|||||||
|
|
||||||
Future<void> _playSound() async {
|
Future<void> _playSound() async {
|
||||||
try {
|
try {
|
||||||
|
// Stop any previous playback before starting anew
|
||||||
|
await _audioPlayer.stop();
|
||||||
// Assumes the sound file is in assets/sounds/
|
// Assumes the sound file is in assets/sounds/
|
||||||
await _audioPlayer.play(AssetSource('sounds/$notificationSound'));
|
await _audioPlayer.play(AssetSource('sounds/$notificationSound'));
|
||||||
debugPrint("Played sound: $notificationSound");
|
debugPrint("Played sound: $notificationSound");
|
||||||
} catch (e) {
|
} catch (e, stackTrace) {
|
||||||
debugPrint("Error playing sound: $e");
|
// Catch stack trace for more details
|
||||||
|
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("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||||
// Handle error, e.g., show a notification or log
|
// Handle error, e.g., show a notification or log
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -303,15 +316,19 @@ class _MainPageState extends State<MainPage> with WindowListener {
|
|||||||
|
|
||||||
// --- Add a specific save function for Todo List --- //
|
// --- Add a specific save function for Todo List --- //
|
||||||
void _saveTodoList() {
|
void _saveTodoList() {
|
||||||
// TODO: Implement debounced logic to save the todo list
|
// Cancel any existing timer
|
||||||
// Avoid saving on every single keystroke - use a debounce mechanism
|
if (_debounceTimer?.isActive ?? false) _debounceTimer!.cancel();
|
||||||
// (e.g., wait 500ms after the last change before saving)
|
|
||||||
|
// Start a new timer
|
||||||
|
_debounceTimer = Timer(const Duration(milliseconds: 500), () {
|
||||||
|
// This code runs after 500ms of inactivity
|
||||||
String todoList = _todoController.text;
|
String todoList = _todoController.text;
|
||||||
print("Saving Todo list (placeholder)... [${todoList.length} chars]");
|
print("Debounced Save: Saving Todo list... [${todoList.length} chars]");
|
||||||
// --- Your actual todo list persistence logic goes here ---
|
// --- Your actual todo list persistence logic goes here ---
|
||||||
// Example:
|
// Example:
|
||||||
// await saveTodoListToFile(todoList);
|
// await saveTodoListToFile(todoList);
|
||||||
// --------------------------------------------------------
|
// --------------------------------------------------------
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper to set initial window config like aspect ratio
|
// Helper to set initial window config like aspect ratio
|
||||||
@@ -327,7 +344,17 @@ class _MainPageState extends State<MainPage> with WindowListener {
|
|||||||
// --- UI Build --- //
|
// --- UI Build --- //
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
// Listen for keyboard events to close on Escape
|
||||||
|
return RawKeyboardListener(
|
||||||
|
focusNode: FocusNode(), // Need a focus node to receive keys
|
||||||
|
autofocus: true, // Ensure it can receive focus
|
||||||
|
onKey: (event) {
|
||||||
|
if (event.logicalKey == LogicalKeyboardKey.escape) {
|
||||||
|
debugPrint("Escape key pressed - hiding window.");
|
||||||
|
windowManager.hide();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text('Journaler'),
|
title: const Text('Journaler'),
|
||||||
actions: const [
|
actions: const [
|
||||||
@@ -353,7 +380,6 @@ class _MainPageState extends State<MainPage> with WindowListener {
|
|||||||
controller: _previousEntryController,
|
controller: _previousEntryController,
|
||||||
maxLines: null, // Allows unlimited lines
|
maxLines: null, // Allows unlimited lines
|
||||||
expands: true, // Fills the available space
|
expands: true, // Fills the available space
|
||||||
readOnly: true, // Make it non-editable
|
|
||||||
style:
|
style:
|
||||||
Theme.of(
|
Theme.of(
|
||||||
context,
|
context,
|
||||||
@@ -416,6 +442,7 @@ class _MainPageState extends State<MainPage> with WindowListener {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user