From 46e239dabe864a838f5315abb80d18cf13c51f79 Mon Sep 17 00:00:00 2001 From: rustdesk Date: Fri, 6 Aug 2021 22:29:11 +0800 Subject: [PATCH] refactor --- flutter_hbb/lib/home_page.dart | 17 +++++++++----- flutter_hbb/lib/model.dart | 26 ---------------------- flutter_hbb/lib/remote_page.dart | 38 +++++++++++++++----------------- 3 files changed, 29 insertions(+), 52 deletions(-) diff --git a/flutter_hbb/lib/home_page.dart b/flutter_hbb/lib/home_page.dart index 86385855f..a7fe87852 100644 --- a/flutter_hbb/lib/home_page.dart +++ b/flutter_hbb/lib/home_page.dart @@ -257,9 +257,9 @@ class _HomePageState extends State { void showServer(BuildContext context) { final formKey = GlobalKey(); - final id0 = FFI.getByName('custom-rendezvous-server'); - final relay0 = FFI.getByName('relay-server'); - final key0 = FFI.getByName('key'); + final id0 = FFI.getByName('option', 'custom-rendezvous-server'); + final relay0 = FFI.getByName('option', 'relay-server'); + final key0 = FFI.getByName('option', 'key'); var id = ''; var relay = ''; var key = ''; @@ -316,9 +316,14 @@ void showServer(BuildContext context) { if (formKey.currentState.validate()) { formKey.currentState.save(); if (id != id0) - FFI.setByName('custom-rendezvous-server', id); - if (relay != relay0) FFI.setByName('relay-server', relay); - if (key != key0) FFI.setByName('key', key); + FFI.setByName('option', + '{"name": "custom-rendezvous-server", "value": "${id}"}'); + if (relay != relay0) + FFI.setByName('option', + '{"name": "relay-server", "value": "${relay}"}'); + if (key != key0) + FFI.setByName( + 'option', '{"name": "key", "value": "${key}"}'); Navigator.pop(context); } }, diff --git a/flutter_hbb/lib/model.dart b/flutter_hbb/lib/model.dart index 72687ecb4..13caa06c1 100644 --- a/flutter_hbb/lib/model.dart +++ b/flutter_hbb/lib/model.dart @@ -714,32 +714,6 @@ Future> getPreference(String id) async { void removePreference(String id) async { SharedPreferences prefs = await SharedPreferences.getInstance(); prefs.remove('peer' + id); - prefs.remove('peer' + id + '-password'); -} - -Future getPassword(String id) async { - SharedPreferences prefs = await SharedPreferences.getInstance(); - var p = prefs.getString('peer' + id + '-password'); - if (p == null) return ""; - return p; -} - -void savePassword(String id, String password) async { - SharedPreferences prefs = await SharedPreferences.getInstance(); - prefs.setString('peer' + id + '-password', password); - prefs.setString('peer' + id + '-autologin', password); -} - -Future getAutoLogin(String id) async { - SharedPreferences prefs = await SharedPreferences.getInstance(); - var p = prefs.getString('peer' + id + '-autologin'); - if (p == null) return false; - return p != ""; -} - -void saveAutoLogin(String id, bool a) async { - SharedPreferences prefs = await SharedPreferences.getInstance(); - prefs.setString('peer' + id + '-autologin', a ? 'Y' : ''); } void initializeCursorAndCanvas() async { diff --git a/flutter_hbb/lib/remote_page.dart b/flutter_hbb/lib/remote_page.dart index 8c7acc503..721ae01f4 100644 --- a/flutter_hbb/lib/remote_page.dart +++ b/flutter_hbb/lib/remote_page.dart @@ -782,8 +782,8 @@ void showActions(BuildContext context) { TextButton( style: flatButtonStyle, onPressed: () { - showSetOSPassword(context); Navigator.pop(context); + showSetOSPassword(context, false); }, child: Icon(Icons.edit), ) @@ -817,29 +817,20 @@ void showActions(BuildContext context) { } }(); } else if (value == 'enter_os_password') { - () async { - var password = await getPassword(FFI.id); - if (password != "") { - var x = FFI.cursorModel.x; - var y = FFI.cursorModel.y; - FFI.moveMouse(x + 3, y + 3); - await Future.delayed(Duration(milliseconds: 50)); - FFI.moveMouse(x, y); - await Future.delayed(Duration(milliseconds: 50)); - FFI.tap(true); - await Future.delayed(Duration(milliseconds: 300)); - FFI.setByName('input_string', password); - FFI.inputKey('VK_RETURN'); - } - }(); + var password = FFI.getByName('peer_option', "os-password"); + if (password != "") { + FFI.setByName('input_os_password', password); + } else { + showSetOSPassword(context, true); + } } }(); } -void showSetOSPassword(BuildContext context) async { +void showSetOSPassword(BuildContext context, bool login) { final controller = TextEditingController(); - var password = await getPassword(FFI.id); - var autoLogin = await getAutoLogin(FFI.id); + var password = FFI.getByName('peer_option', "os-password"); + var autoLogin = FFI.getByName('peer_option', "auto-login") != ""; controller.text = password; showAlertDialog( context, @@ -872,7 +863,14 @@ void showSetOSPassword(BuildContext context) async { style: flatButtonStyle, onPressed: () { var text = controller.text.trim(); - savePassword(FFI.id, text); + FFI.setByName('peer_option', + '{"name": "os-password", "value": "${text}"}'); + FFI.setByName('peer_option', + '{"name": "auto-login", "value": "${autoLogin ? 'Y' : ''}"}'); + print(text); + if (text != "") { + FFI.setByName('input_os_password', text); + } Navigator.pop(context); }, child: Text(translate('OK')),