clipboard

This commit is contained in:
open-trade 2020-11-28 13:22:19 +08:00
parent 4d4d7673de
commit 6a5454f72a
2 changed files with 32 additions and 12 deletions

View File

@ -1,4 +1,5 @@
import 'package:ffi/ffi.dart';
import 'package:flutter/services.dart';
import 'package:flutter/gestures.dart';
import 'package:path_provider/path_provider.dart';
import 'package:device_info/device_info.dart';
@ -61,6 +62,10 @@ class FfiModel with ChangeNotifier {
_display = Display();
_decoding = false;
_waitForImage = false;
clearPermissions();
}
void clearPermissions() {
_permissions.clear();
}
@ -86,6 +91,8 @@ class FfiModel with ChangeNotifier {
FFI.cursorModel.updateCursorId(evt);
} else if (name == 'cursor_position') {
pos = evt;
} else if (name == 'clipboard') {
Clipboard.setData(ClipboardData(text: evt['content']));
} else if (name == 'permission') {
FFI.ffiModel.updatePermission(evt);
}
@ -438,6 +445,11 @@ class FFI {
json.encode(modify({'type': 'wheel', 'y': y2.toString()})));
}
static void reconnect() {
setByName('reconnect');
FFI.ffiModel.clearPermissions();
}
static void resetModifiers() {
shift = ctrl = alt = command = false;
}

View File

@ -104,7 +104,7 @@ class _RemotePageState extends State<RemotePage> {
if (hasRetry) {
_timer?.cancel();
_timer = Timer(Duration(seconds: _reconnects), () {
FFI.setByName('reconnect');
FFI.reconnect();
showLoading('Connecting...', context);
});
_reconnects *= 2;
@ -718,31 +718,39 @@ void showActions(BuildContext context) {
final size = MediaQuery.of(context).size;
final x = 120.0;
final y = size.height;
var more = <Widget>[];
if (FFI.ffiModel.pi.version.isNotEmpty) {
more.add(PopupMenuItem<String>(child: Text('Refresh'), value: 'refresh'));
}
if (FFI.ffiModel.permissions['keyboard'] != false &&
FFI.ffiModel.permissions['clipboard'] != false) {
more.add(PopupMenuItem<String>(child: Text('Paste'), value: 'paste'));
}
() async {
var value = await showMenu(
context: context,
position: RelativeRect.fromLTRB(x, y, x, y),
items: [
items: <Widget>[
PopupMenuItem<String>(
child: Text('Insert Ctrl + Alt + Del'), value: 'cad'),
PopupMenuItem<String>(child: Text('Insert Lock'), value: 'lock'),
] +
(FFI.ffiModel.pi.version.isEmpty
? []
: [
PopupMenuItem<String>(
child: Text('Refresh'), value: 'refresh'),
]),
more,
elevation: 8,
);
if (value == 'cad') {
FFI.setByName('ctrl_alt_del');
}
if (value == 'lock') {
} else if (value == 'lock') {
FFI.setByName('lock_screen');
}
if (value == 'refresh') {
} else if (value == 'refresh') {
FFI.setByName('refresh');
} else if (value == 'paste') {
() async {
ClipboardData data = await Clipboard.getData(Clipboard.kTextPlain);
if (data.text != null) {
FFI.setByName('input_string', '${data.text}');
}
}();
}
}();
}