fix: termux compatibility (#495)

This commit is contained in:
lollipopkit🏳️‍⚧️
2024-07-26 22:31:17 +08:00
committed by GitHub
parent ceedd86310
commit 5db1253ab8
9 changed files with 41 additions and 34 deletions

View File

@@ -23,6 +23,7 @@ enum ShellFunc {
static const scriptPath = '$scriptDir/$scriptFile';
static const String installShellCmd = """
mkdir -p $scriptDir
cat > $scriptPath
chmod 744 $scriptPath
""";

View File

@@ -1,6 +1,5 @@
import 'dart:collection';
import 'package:fl_chart/fl_chart.dart';
import 'package:fl_lib/fl_lib.dart';
import 'package:server_box/data/model/server/time_seq.dart';
import 'package:server_box/data/res/status.dart';
@@ -26,10 +25,16 @@ class Cpus extends TimeSeq<List<SingleCpuCore>> {
double usedPercent({int coreIdx = 0}) {
if (now.length != pre.length) return 0;
final idleDelta = now[coreIdx].idle - pre[coreIdx].idle;
final totalDelta = now[coreIdx].total - pre[coreIdx].total;
final used = idleDelta / totalDelta;
return used.isNaN ? 0 : 100 - used * 100;
if (now.isEmpty) return 0;
try {
final idleDelta = now[coreIdx].idle - pre[coreIdx].idle;
final totalDelta = now[coreIdx].total - pre[coreIdx].total;
final used = idleDelta / totalDelta;
return used.isNaN ? 0 : 100 - used * 100;
} catch (e, s) {
Loggers.app.warning('Cpus.usedPercent()', e, s);
return 0;
}
}
int _coresCount = 0;

View File

@@ -316,7 +316,7 @@ class ServerProvider extends ChangeNotifier {
final scriptRaw = ShellFunc.allScript(spi.custom?.cmds).uint8List;
try {
await s.client?.runForOutput(
await s.client!.runForOutput(
ShellFunc.installShellCmd,
action: (session) async {
session.stdin.add(scriptRaw);

View File

@@ -2,6 +2,6 @@
class BuildData {
static const String name = "ServerBox";
static const int build = 1030;
static const int build = 1032;
static const int script = 54;
}

View File

@@ -94,6 +94,7 @@ abstract final class GithubIds {
'liwenjie119',
'logce',
'h-lyf',
'88484396',
};
}