chore: run dart format
Some checks are pending
Flutter CI & Release / Test (push) Waiting to run
Flutter CI & Release / Build Android APKs (push) Blocked by required conditions
Flutter CI & Release / build_linux (push) Blocked by required conditions
Flutter CI & Release / Create GitHub Release (push) Blocked by required conditions

This commit is contained in:
Dr.Blank 2026-01-10 16:51:05 +05:30
parent a520136e01
commit e23c0b6c5f
No known key found for this signature in database
GPG key ID: BA5F87FF0560C57B
84 changed files with 1565 additions and 1945 deletions

View file

@ -29,7 +29,7 @@ class ShakeDetector {
DateTime _lastShakeTime = DateTime.now();
final StreamController<UserAccelerometerEvent>
_detectedShakeStreamController = StreamController.broadcast();
_detectedShakeStreamController = StreamController.broadcast();
void start() {
if (_accelerometerSubscription != null) {
@ -37,26 +37,27 @@ class ShakeDetector {
return;
}
_accelerometerSubscription =
userAccelerometerEventStream(samplingPeriod: _settings.samplingPeriod)
.listen((event) {
_logger.finest('RMS: ${event.rms}');
if (event.rms > _settings.threshold) {
_currentShakeCount++;
userAccelerometerEventStream(
samplingPeriod: _settings.samplingPeriod,
).listen((event) {
_logger.finest('RMS: ${event.rms}');
if (event.rms > _settings.threshold) {
_currentShakeCount++;
if (_currentShakeCount >= _settings.shakeTriggerCount &&
!isCoolDownNeeded()) {
_logger.fine('Shake detected $_currentShakeCount times');
if (_currentShakeCount >= _settings.shakeTriggerCount &&
!isCoolDownNeeded()) {
_logger.fine('Shake detected $_currentShakeCount times');
onShakeDetected?.call();
_detectedShakeStreamController.add(event);
onShakeDetected?.call();
_detectedShakeStreamController.add(event);
_lastShakeTime = DateTime.now();
_currentShakeCount = 0;
}
} else {
_currentShakeCount = 0;
}
});
_lastShakeTime = DateTime.now();
_currentShakeCount = 0;
}
} else {
_currentShakeCount = 0;
}
});
_logger.fine('ShakeDetector started');
}

View file

@ -59,34 +59,29 @@ class ShakeDetector extends _$ShakeDetector {
final sleepTimer = ref.watch(sleepTimerProvider);
if (!shakeDetectionSettings.shakeAction.isPlaybackManagementEnabled &&
sleepTimer == null) {
_logger
.config('No playback management is enabled and sleep timer is off, '
'so shake detection is disabled');
_logger.config(
'No playback management is enabled and sleep timer is off, '
'so shake detection is disabled',
);
return null;
}
_logger.config('Creating shake detector');
final detector = core.ShakeDetector(
shakeDetectionSettings,
() {
final wasActionComplete = doShakeAction(
shakeDetectionSettings.shakeAction,
ref: ref,
);
if (wasActionComplete) {
shakeDetectionSettings.feedback.forEach(postShakeFeedback);
}
},
);
final detector = core.ShakeDetector(shakeDetectionSettings, () {
final wasActionComplete = doShakeAction(
shakeDetectionSettings.shakeAction,
ref: ref,
);
if (wasActionComplete) {
shakeDetectionSettings.feedback.forEach(postShakeFeedback);
}
});
ref.onDispose(detector.dispose);
return detector;
}
/// Perform the shake action and return whether the action was successful
bool doShakeAction(
ShakeAction shakeAction, {
required Ref ref,
}) {
bool doShakeAction(ShakeAction shakeAction, {required Ref ref}) {
final player = ref.read(simpleAudiobookPlayerProvider);
if (player.book == null && shakeAction.isPlaybackManagementEnabled) {
_logger.warning('No book is loaded');
@ -166,8 +161,11 @@ extension on ShakeAction {
}
bool get isPlaybackManagementEnabled {
return {ShakeAction.playPause, ShakeAction.fastForward, ShakeAction.rewind}
.contains(this);
return {
ShakeAction.playPause,
ShakeAction.fastForward,
ShakeAction.rewind,
}.contains(this);
}
bool get shouldActOnSleepTimer {