From 6a5454f72ad8e680f4febd16b9db323cdebaeee1 Mon Sep 17 00:00:00 2001 From: open-trade Date: Sat, 28 Nov 2020 13:22:19 +0800 Subject: [PATCH] clipboard --- flutter_hbb/lib/model.dart | 12 ++++++++++++ flutter_hbb/lib/remote_page.dart | 32 ++++++++++++++++++++------------ 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/flutter_hbb/lib/model.dart b/flutter_hbb/lib/model.dart index f8e3dab49..0cfe97827 100644 --- a/flutter_hbb/lib/model.dart +++ b/flutter_hbb/lib/model.dart @@ -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; } diff --git a/flutter_hbb/lib/remote_page.dart b/flutter_hbb/lib/remote_page.dart index 562f3b5c9..b45099095 100644 --- a/flutter_hbb/lib/remote_page.dart +++ b/flutter_hbb/lib/remote_page.dart @@ -104,7 +104,7 @@ class _RemotePageState extends State { 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 = []; + if (FFI.ffiModel.pi.version.isNotEmpty) { + more.add(PopupMenuItem(child: Text('Refresh'), value: 'refresh')); + } + if (FFI.ffiModel.permissions['keyboard'] != false && + FFI.ffiModel.permissions['clipboard'] != false) { + more.add(PopupMenuItem(child: Text('Paste'), value: 'paste')); + } () async { var value = await showMenu( context: context, position: RelativeRect.fromLTRB(x, y, x, y), - items: [ + items: [ PopupMenuItem( child: Text('Insert Ctrl + Alt + Del'), value: 'cad'), PopupMenuItem(child: Text('Insert Lock'), value: 'lock'), ] + - (FFI.ffiModel.pi.version.isEmpty - ? [] - : [ - PopupMenuItem( - 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}'); + } + }(); } }(); }