1.开始录制、结束录制增加

2. 增加电量检测、内存检查,是否低于 10%
This commit is contained in:
2026-06-04 18:25:58 +08:00
parent 124b4c1882
commit f49d208042
9 changed files with 267 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
import 'dart:io';
import 'package:flutter/services.dart';
import 'package:recording_tool/core/platform/device_health_snapshot.dart';
class AppPackageInfo {
const AppPackageInfo({
@@ -75,4 +76,11 @@ class AppPlatformInfo {
);
return AppDeviceInfo.fromMap(result ?? const <Object?, Object?>{});
}
static Future<DeviceHealthSnapshot> deviceHealth() async {
final result = await _channel.invokeMapMethod<Object?, Object?>(
'deviceHealth',
);
return DeviceHealthSnapshot.fromMap(result ?? const <Object?, Object?>{});
}
}

View File

@@ -0,0 +1,25 @@
import 'package:recording_tool/core/platform/device_health_snapshot.dart';
class DeviceHealthChecker {
DeviceHealthChecker._();
static const int thresholdPercent = 10;
static const String lowBatteryMessage = '电量低于10%,请充电';
static const String lowStorageMessage = '内存低于10%,请清理内存';
static List<String> warningLines(DeviceHealthSnapshot snapshot) {
final lines = <String>[];
final battery = snapshot.batteryLevelPercent;
if (battery != null && battery < thresholdPercent) {
lines.add(lowBatteryMessage);
}
if (snapshot.storageAvailablePercent < thresholdPercent) {
lines.add(lowStorageMessage);
}
return lines;
}
}

View File

@@ -0,0 +1,30 @@
class DeviceHealthSnapshot {
const DeviceHealthSnapshot({
this.batteryLevelPercent,
required this.storageAvailablePercent,
});
factory DeviceHealthSnapshot.fromMap(Map<Object?, Object?> map) {
final batteryRaw = map['batteryLevelPercent'];
int? batteryLevelPercent;
if (batteryRaw is int) {
batteryLevelPercent = batteryRaw;
} else if (batteryRaw is num) {
batteryLevelPercent = batteryRaw.round();
}
final storageRaw = map['storageAvailablePercent'];
final storageAvailablePercent = switch (storageRaw) {
final num value => value.toDouble(),
_ => 100.0,
};
return DeviceHealthSnapshot(
batteryLevelPercent: batteryLevelPercent,
storageAvailablePercent: storageAvailablePercent,
);
}
final int? batteryLevelPercent;
final double storageAvailablePercent;
}