mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-14 20:33:41 +00:00
feat: flutter ui integration
This commit is contained in:
1 parent
0fc133e46d
commit
c4a30dc4c2
170 files changed
+7783
-1
No files matched your search
@@ -0,0 +1,32 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:macos_secure_bookmarks/macos_secure_bookmarks.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class MacSecureUtil {
|
||||
static const _bookmarkKey = "bookmark:";
|
||||
|
||||
static Future<void> saveBookmark(String dir) async {
|
||||
if (!Platform.isMacOS) {
|
||||
return;
|
||||
}
|
||||
final secureBookmarks = SecureBookmarks();
|
||||
final bookmark = await secureBookmarks.bookmark(Directory(dir));
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString(_bookmarkKey + dir, bookmark);
|
||||
}
|
||||
|
||||
static Future<void> loadBookmark() async {
|
||||
if (!Platform.isMacOS) {
|
||||
return;
|
||||
}
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final keys = prefs.getKeys();
|
||||
final secureBookmarks = SecureBookmarks();
|
||||
keys.where((k) => k.startsWith(_bookmarkKey)).forEach((k) async {
|
||||
final resolvedFile = await secureBookmarks
|
||||
.resolveBookmark(prefs.getString(k)!, isDirectory: true);
|
||||
await secureBookmarks.startAccessingSecurityScopedResource(resolvedFile);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import 'dart:io';
|
||||
|
||||
class Util {
|
||||
static String fmtByte(int byte) {
|
||||
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 buildPath(String path, String name) {
|
||||
return (path == "" ? "" : "$path/") + name;
|
||||
}
|
||||
|
||||
static String buildAbsPath(String dir, String path, String name) {
|
||||
return (dir == "" ? "" : "$dir/") + buildPath(path, name);
|
||||
}
|
||||
|
||||
static isDesktop() {
|
||||
return Platform.isWindows || Platform.isLinux || Platform.isMacOS;
|
||||
}
|
||||
|
||||
static isUnix() {
|
||||
return !Platform.isWindows;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user