f655adfbea
Migrate app code into canonical feature slices, add phone-only AI digest scheduling and review, wire local notification/background task support, and cover the flow with tests.
41 lines
1.3 KiB
Dart
41 lines
1.3 KiB
Dart
import 'package:battery_plus/battery_plus.dart';
|
|
import 'package:connectivity_plus/connectivity_plus.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:relationship_saver/features/ai_digest/domain/ai_digest_models.dart';
|
|
|
|
abstract interface class LlmDigestEnvironment {
|
|
Future<bool> canRun(LlmDigestConfigState config);
|
|
}
|
|
|
|
class DeviceLlmDigestEnvironment implements LlmDigestEnvironment {
|
|
DeviceLlmDigestEnvironment({Connectivity? connectivity, Battery? battery})
|
|
: _connectivity = connectivity ?? Connectivity(),
|
|
_battery = battery ?? Battery();
|
|
|
|
final Connectivity _connectivity;
|
|
final Battery _battery;
|
|
|
|
@override
|
|
Future<bool> canRun(LlmDigestConfigState config) async {
|
|
if (config.requireWifi) {
|
|
final List<ConnectivityResult> results = await _connectivity
|
|
.checkConnectivity();
|
|
if (!results.contains(ConnectivityResult.wifi)) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if (config.requireCharging) {
|
|
final BatteryState state = await _battery.batteryState;
|
|
if (state != BatteryState.charging && state != BatteryState.full) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
final Provider<LlmDigestEnvironment> llmDigestEnvironmentProvider =
|
|
Provider<LlmDigestEnvironment>((Ref ref) => DeviceLlmDigestEnvironment());
|