feat: new ui (#1455)

This commit is contained in:
Levi authored and GitHub committed 2026-09-05 19:53:41 +08:00
1 parent 3be8db664c
commit 177c225f16
742 files changed
+59951 -5934

No files matched your search

+29 -43
View File
@@ -8,6 +8,8 @@ import 'package:flutter/services.dart';
import 'package:path_provider/path_provider.dart';
import 'package:path/path.dart' as path;
import '../core/utils/byte_size_formatter.dart';
class Util {
static String? _storageDir;
@@ -30,32 +32,15 @@ class Util {
}
static String safePathJoin(List<String> paths) {
return paths
.where((e) => e.isNotEmpty)
.map((e) => safeDir(e))
.join("/")
.replaceAll(RegExp(r'//'), "/");
return paths.where((e) => e.isNotEmpty).map((e) => safeDir(e)).join("/").replaceAll(RegExp(r'//'), "/");
}
static String fmtByte(int byte) {
if (byte < 0) {
return "0 B";
} else if (byte < 1024) {
return "$byte B";
} else if (byte < 1024 * 1024) {
return "${(byte / 1024).toStringAsFixed(2)} KB";
} else if (byte < 1024 * 1024 * 1024) {
return "${(byte / 1024 / 1024).toStringAsFixed(2)} MB";
} else {
return "${(byte / 1024 / 1024 / 1024).toStringAsFixed(2)} GB";
}
}
static String fmtByte(int byte) => ByteSizeFormatter.format(byte);
static Future<void> initStorageDir() async {
var storageDir = "";
if (Util.isWindows()) {
storageDir =
path.join(File(Platform.resolvedExecutable).parent.path, "storage");
storageDir = path.join(File(Platform.resolvedExecutable).parent.path, "storage");
} else if (!Util.isWeb()) {
if (Util.isLinux()) {
storageDir = File(Platform.resolvedExecutable).parent.path;
@@ -78,42 +63,42 @@ class Util {
return _storageDir!;
}
static isAndroid() {
static bool isAndroid() {
return !kIsWeb && Platform.isAndroid;
}
static isIOS() {
static bool isIOS() {
return !kIsWeb && Platform.isIOS;
}
static isMobile() {
static bool isMobile() {
return !kIsWeb && (Platform.isAndroid || Platform.isIOS);
}
static isDesktop() {
static bool isDesktop() {
if (kIsWeb) {
return false;
}
return Platform.isWindows || Platform.isLinux || Platform.isMacOS;
}
static isWindows() {
static bool isWindows() {
return !kIsWeb && Platform.isWindows;
}
static isMacos() {
static bool isMacos() {
return !kIsWeb && Platform.isMacOS;
}
static isLinux() {
static bool isLinux() {
return !kIsWeb && Platform.isLinux;
}
static isWeb() {
static bool isWeb() {
return kIsWeb;
}
static supportUnixSocket() {
static bool supportUnixSocket() {
if (kIsWeb) {
return false;
}
@@ -129,22 +114,24 @@ class Util {
}
// if one future complete, return the result, only all future error, return the last error
static anyOk<T>(Iterable<Future<T>> futures) {
static Future<T> anyOk<T>(Iterable<Future<T>> futures) {
final completer = Completer<T>();
Object lastError;
var count = futures.length;
for (var future in futures) {
future.then((value) {
if (!completer.isCompleted) {
completer.complete(value);
}
}).catchError((e) {
lastError = e;
count--;
if (count == 0) {
completer.completeError(lastError);
}
});
future
.then((value) {
if (!completer.isCompleted) {
completer.complete(value);
}
})
.catchError((e) {
lastError = e;
count--;
if (count == 0) {
completer.completeError(lastError);
}
});
}
return completer.future;
}
@@ -168,8 +155,7 @@ class Util {
return path.join(dir.path, fileName);
}
static Future<void> installAsset(String assetPath, String targetPath,
{bool executable = false}) async {
static Future<void> installAsset(String assetPath, String targetPath, {bool executable = false}) async {
Future<List<int>> getAssetData() async {
final asset = await rootBundle.load(assetPath);
return asset.buffer.asUint8List(asset.offsetInBytes, asset.lengthInBytes);