mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
file connection permission
This commit is contained in:
@@ -255,3 +255,54 @@ class AccessibilityListener extends StatelessWidget {
|
||||
child: child);
|
||||
}
|
||||
}
|
||||
|
||||
class PermissionManager {
|
||||
static Completer<bool>? _completer;
|
||||
static Timer? _timer;
|
||||
static var _current = "";
|
||||
|
||||
static final permissions = ["audio", "file"];
|
||||
|
||||
static bool isWaitingFile() {
|
||||
if (_completer != null) {
|
||||
return !_completer!.isCompleted && _current == "file";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static Future<bool> check(String type) {
|
||||
if (!permissions.contains(type))
|
||||
return Future.error("Wrong permission!$type");
|
||||
return FFI.invokeMethod("check_permission", type);
|
||||
}
|
||||
|
||||
static Future<bool> request(String type) {
|
||||
if (!permissions.contains(type))
|
||||
return Future.error("Wrong permission!$type");
|
||||
|
||||
_current = type;
|
||||
_completer = Completer<bool>();
|
||||
FFI.invokeMethod("request_permission", type);
|
||||
|
||||
// timeout
|
||||
_timer?.cancel();
|
||||
_timer = Timer(Duration(seconds: 60), () {
|
||||
if (_completer == null) return;
|
||||
if (!_completer!.isCompleted) {
|
||||
_completer!.complete(false);
|
||||
}
|
||||
_completer = null;
|
||||
_current = "";
|
||||
});
|
||||
return _completer!.future;
|
||||
}
|
||||
|
||||
static complete(String type, bool res) {
|
||||
if (type != _current) {
|
||||
res = false;
|
||||
}
|
||||
_timer?.cancel();
|
||||
_completer?.complete(res);
|
||||
_current = "";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user