feat: flutter ui integration

This commit is contained in:
levi authored and monkeyWie committed 2022-10-27 13:58:43 +08:00
1 parent 0fc133e46d
commit c4a30dc4c2
170 files changed
+7783 -1

No files matched your search

+32
View File
@@ -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);
});
}
}