mirror of
https://github.com/Dr-Blank/Vaani.git
synced 2025-12-10 04:59:29 +00:00
Fix Shake Detector not working when app in background (#40)
* feat: update shake detection settings to reduce cooldown and feedback options * fix: shake detector not detecting in background * enhance shake action handling to avoid unnecessary feedback * disable shake detector when player not playing anything * refactor: remove outdated TODO regarding shake detection optimization * refactor: comment out notifyListeners call in restartTimer method for clarity
This commit is contained in:
parent
6c0265fe5f
commit
67d6c9240b
10 changed files with 93 additions and 47 deletions
|
|
@ -28,6 +28,9 @@ class ShakeDetector {
|
|||
|
||||
DateTime _lastShakeTime = DateTime.now();
|
||||
|
||||
final StreamController<UserAccelerometerEvent>
|
||||
_detectedShakeStreamController = StreamController.broadcast();
|
||||
|
||||
void start() {
|
||||
if (_accelerometerSubscription != null) {
|
||||
_logger.warning('ShakeDetector is already running');
|
||||
|
|
@ -36,6 +39,7 @@ class ShakeDetector {
|
|||
_accelerometerSubscription =
|
||||
userAccelerometerEventStream(samplingPeriod: _settings.samplingPeriod)
|
||||
.listen((event) {
|
||||
_logger.finest('RMS: ${event.rms}');
|
||||
if (event.rms > _settings.threshold) {
|
||||
_currentShakeCount++;
|
||||
|
||||
|
|
@ -44,6 +48,7 @@ class ShakeDetector {
|
|||
_logger.fine('Shake detected $_currentShakeCount times');
|
||||
|
||||
onShakeDetected?.call();
|
||||
_detectedShakeStreamController.add(event);
|
||||
|
||||
_lastShakeTime = DateTime.now();
|
||||
_currentShakeCount = 0;
|
||||
|
|
@ -60,6 +65,7 @@ class ShakeDetector {
|
|||
_currentShakeCount = 0;
|
||||
_accelerometerSubscription?.cancel();
|
||||
_accelerometerSubscription = null;
|
||||
_detectedShakeStreamController.close();
|
||||
_logger.fine('ShakeDetector stopped');
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue