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
|
||||
*.png 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:io'; // Required for Platform check
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart'; // Needed for LogicalKeyboardKey
|
||||
import 'package:system_tray/system_tray.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
import 'package:audioplayers/audioplayers.dart';
|
||||
@@ -7,7 +9,7 @@ import 'package:audioplayers/audioplayers.dart';
|
||||
|
||||
// --- Configuration ---
|
||||
const Duration popupInterval = Duration(hours: 1); // How often to pop up
|
||||
const String notificationSound = 'MeetTheSniper.ogg';
|
||||
const String notificationSound = 'MeetTheSniper.mp3';
|
||||
// --------------------
|
||||
|
||||
void main() async {
|
||||
@@ -141,6 +143,7 @@ class _MainPageState extends State<MainPage> with WindowListener {
|
||||
final TextEditingController _todoController = TextEditingController();
|
||||
|
||||
Timer? _popupTimer;
|
||||
Timer? _debounceTimer; // Timer for debouncing Todo saves
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -161,6 +164,7 @@ class _MainPageState extends State<MainPage> with WindowListener {
|
||||
void dispose() {
|
||||
windowManager.removeListener(this);
|
||||
_popupTimer?.cancel();
|
||||
_debounceTimer?.cancel(); // Cancel debounce timer on dispose
|
||||
_previousEntryController.dispose();
|
||||
_currentEntryController.dispose();
|
||||
_todoController.dispose();
|
||||
@@ -251,11 +255,20 @@ class _MainPageState extends State<MainPage> with WindowListener {
|
||||
|
||||
Future<void> _playSound() async {
|
||||
try {
|
||||
// Stop any previous playback before starting anew
|
||||
await _audioPlayer.stop();
|
||||
// Assumes the sound file is in assets/sounds/
|
||||
await _audioPlayer.play(AssetSource('sounds/$notificationSound'));
|
||||
debugPrint("Played sound: $notificationSound");
|
||||
} catch (e) {
|
||||
debugPrint("Error playing sound: $e");
|
||||
} catch (e, stackTrace) {
|
||||
// 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
|
||||
}
|
||||
}
|
||||
@@ -303,15 +316,19 @@ class _MainPageState extends State<MainPage> with WindowListener {
|
||||
|
||||
// --- Add a specific save function for Todo List --- //
|
||||
void _saveTodoList() {
|
||||
// TODO: Implement debounced logic to save the todo list
|
||||
// Avoid saving on every single keystroke - use a debounce mechanism
|
||||
// (e.g., wait 500ms after the last change before saving)
|
||||
// Cancel any existing timer
|
||||
if (_debounceTimer?.isActive ?? false) _debounceTimer!.cancel();
|
||||
|
||||
// Start a new timer
|
||||
_debounceTimer = Timer(const Duration(milliseconds: 500), () {
|
||||
// This code runs after 500ms of inactivity
|
||||
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 ---
|
||||
// Example:
|
||||
// await saveTodoListToFile(todoList);
|
||||
// --------------------------------------------------------
|
||||
});
|
||||
}
|
||||
|
||||
// Helper to set initial window config like aspect ratio
|
||||
@@ -327,7 +344,17 @@ class _MainPageState extends State<MainPage> with WindowListener {
|
||||
// --- UI Build --- //
|
||||
@override
|
||||
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(
|
||||
title: const Text('Journaler'),
|
||||
actions: const [
|
||||
@@ -353,7 +380,6 @@ class _MainPageState extends State<MainPage> with WindowListener {
|
||||
controller: _previousEntryController,
|
||||
maxLines: null, // Allows unlimited lines
|
||||
expands: true, // Fills the available space
|
||||
readOnly: true, // Make it non-editable
|
||||
style:
|
||||
Theme.of(
|
||||
context,
|
||||
@@ -416,6 +442,7 @@ class _MainPageState extends State<MainPage> with WindowListener {
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user