From 83622cffc6cc1022e3eccf65e2ff8b824bbfb032 Mon Sep 17 00:00:00 2001 From: open-trade Date: Fri, 20 Nov 2020 16:37:48 +0800 Subject: [PATCH] input key ffi --- flutter_hbb/lib/common.dart | 15 ++- flutter_hbb/lib/model.dart | 2 +- flutter_hbb/lib/remote_page.dart | 186 +++++++++++++++++++------------ 3 files changed, 127 insertions(+), 76 deletions(-) diff --git a/flutter_hbb/lib/common.dart b/flutter_hbb/lib/common.dart index 7c3d31f77..9b424aac4 100644 --- a/flutter_hbb/lib/common.dart +++ b/flutter_hbb/lib/common.dart @@ -16,6 +16,7 @@ class HexColor extends Color { } class MyTheme { + MyTheme._(); static const Color grayBg = Color(0xFFEEEEEE); static const Color white = Color(0xFFFFFFFF); static const Color accent = Color(0xFF0071FF); @@ -46,7 +47,7 @@ typedef BuildAlertDailog = Tuple3> Function( // https://material.io/develop/flutter/components/dialogs Future showAlertDialog(BuildContext context, BuildAlertDailog build, [WillPopCallback onWillPop, - bool barrierDismissible, + bool barrierDismissible = false, double contentPadding = 20]) async { dismissLoading(); if (_hasDialog) { @@ -73,10 +74,20 @@ Future showAlertDialog(BuildContext context, BuildAlertDailog build, return res; } -void msgbox(String type, String title, String text, BuildContext context) { +void msgbox(String type, String title, String text, BuildContext context, + [hasCancel = false]) { showAlertDialog( context, (_) => Tuple3(Text(title), Text(text), [ + hasCancel + ? Spacer() + : FlatButton( + textColor: MyTheme.accent, + onPressed: () { + Navigator.pop(context); + }, + child: Text('Cancel'), + ), FlatButton( textColor: MyTheme.accent, onPressed: () { diff --git a/flutter_hbb/lib/model.dart b/flutter_hbb/lib/model.dart index 2f73df63e..54a66b716 100644 --- a/flutter_hbb/lib/model.dart +++ b/flutter_hbb/lib/model.dart @@ -267,7 +267,7 @@ class FFI { FFI.ffiModel.clear(); } - static void setByName(String name, String value) { + static void setByName(String name, [String value = '']) { _setByName(Utf8.toUtf8(name), Utf8.toUtf8(value)); } diff --git a/flutter_hbb/lib/remote_page.dart b/flutter_hbb/lib/remote_page.dart index 2d1afadfd..84166d2fa 100644 --- a/flutter_hbb/lib/remote_page.dart +++ b/flutter_hbb/lib/remote_page.dart @@ -67,79 +67,92 @@ class _RemotePageState extends State { // Size size = MediaQueryData.fromWindow(ui.window).size; // MediaQuery.of(context).size.height; EasyLoading.instance.loadingStyle = EasyLoadingStyle.light; - return Scaffold( - floatingActionButton: _showBar - ? null - : FloatingActionButton( - mini: true, - child: Icon(Icons.expand_less), - backgroundColor: MyTheme.accent50, - onPressed: () { - setState(() => _showBar = !_showBar); - }), - bottomNavigationBar: _showBar - ? BottomAppBar( - color: MyTheme.accent, - child: Row( - mainAxisSize: MainAxisSize.max, - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Row(children: [ - IconButton( - color: Colors.white, - icon: Icon(Icons.clear), - onPressed: () {}, - ), - IconButton( - color: Colors.white, - icon: Icon(Icons.keyboard), - onPressed: () {}, - ), - Transform.rotate( - angle: 15 * math.pi / 180, - child: IconButton( + return WillPopScope( + onWillPop: () async { + close(); + return false; + }, + child: Scaffold( + floatingActionButton: _showBar + ? null + : FloatingActionButton( + mini: true, + child: Icon(Icons.expand_less), + backgroundColor: MyTheme.accent50, + onPressed: () { + setState(() => _showBar = !_showBar); + }), + bottomNavigationBar: _showBar + ? BottomAppBar( + color: MyTheme.accent, + child: Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Row(children: [ + IconButton( color: Colors.white, - icon: Icon(Icons.flash_on), + icon: Icon(Icons.clear), + onPressed: () { + close(); + }, + ), + IconButton( + color: Colors.white, + icon: Icon(Icons.keyboard), onPressed: () {}, - )), - IconButton( - color: Colors.white, - icon: Icon(Icons.tv), - onPressed: () { - showOptions(widget.id, context); - }, - ), - IconButton( - color: Colors.white, - icon: Icon(Icons.settings), - onPressed: () {}, - ) - ]), - IconButton( - color: Colors.white, - icon: Icon(Icons.expand_more), - onPressed: () { - setState(() => _showBar = !_showBar); - }), - ], - ), - ) - : null, - body: FlutterEasyLoading( - child: Container( - color: MyTheme.canvasColor, - child: InteractiveViewer( - constrained: false, - panEnabled: true, - onInteractionUpdate: (details) { - print('$details'); - }, - child: Stack(children: [ - ImagePaint(), - CursorPaint(), - ]), - ), - ))); + ), + Transform.rotate( + angle: 15 * math.pi / 180, + child: IconButton( + color: Colors.white, + icon: Icon(Icons.flash_on), + onPressed: () { + showActions(context); + }, + )), + IconButton( + color: Colors.white, + icon: Icon(Icons.tv), + onPressed: () { + showOptions(context); + }, + ), + IconButton( + color: Colors.white, + icon: Icon(Icons.settings), + onPressed: () {}, + ) + ]), + IconButton( + color: Colors.white, + icon: Icon(Icons.expand_more), + onPressed: () { + setState(() => _showBar = !_showBar); + }), + ], + ), + ) + : null, + body: FlutterEasyLoading( + child: Container( + color: MyTheme.canvasColor, + child: InteractiveViewer( + constrained: false, + panEnabled: true, + onInteractionUpdate: (details) { + print('$details'); + }, + child: Stack(children: [ + ImagePaint(), + CursorPaint(), + ]), + ), + )))); + } + + void close() { + msgbox('', 'Close', 'Are you sure to close the connection?', context); } } @@ -261,7 +274,7 @@ void wrongPasswordDialog(String id, BuildContext context) { ])); } -void showOptions(String id, BuildContext context) { +void showOptions(BuildContext context) { var showRemoteCursor = FFI.getByName('toggle_option', 'show-remote-cursor') == 'true'; var lockAfterSessionEnd = @@ -332,5 +345,32 @@ void showOptions(String id, BuildContext context) { null), () async => true, true, - 10); + 0); +} + +void showActions(BuildContext context) { + showAlertDialog( + context, + (setState) => Tuple3( + null, + Column(mainAxisSize: MainAxisSize.min, children: [ + ListTile( + onTap: () { + Navigator.pop(context); + FFI.setByName('ctrl_alt_del'); + }, + title: Text('Insert Ctrl + Alt + Del'), + ), + ListTile( + onTap: () { + Navigator.pop(context); + FFI.setByName('lock_screen'); + }, + title: Text('Insert Lock'), + ), + ]), + null), + () async => true, + true, + 0); }