From 0f029545a424dfecca142fce41b167dc1c88cfd1 Mon Sep 17 00:00:00 2001 From: rustdesk Date: Fri, 6 Aug 2021 21:18:06 +0800 Subject: [PATCH] refactor input_os_password --- flutter_hbb/lib/home_page.dart | 3 +++ flutter_hbb/lib/model.dart | 19 +++++++++++++++++++ flutter_hbb/lib/remote_page.dart | 17 ++++++++++++++++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/flutter_hbb/lib/home_page.dart b/flutter_hbb/lib/home_page.dart index 9fa515fda..86385855f 100644 --- a/flutter_hbb/lib/home_page.dart +++ b/flutter_hbb/lib/home_page.dart @@ -236,6 +236,9 @@ class _HomePageState extends State { ); if (value == 'remove') { setState(() => FFI.setByName('remove', '${p.id}')); + () async { + removePreference(p.id); + }(); } }(); }, diff --git a/flutter_hbb/lib/model.dart b/flutter_hbb/lib/model.dart index 6986a28ff..72687ecb4 100644 --- a/flutter_hbb/lib/model.dart +++ b/flutter_hbb/lib/model.dart @@ -711,6 +711,12 @@ Future> getPreference(String id) async { return m; } +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'); @@ -721,6 +727,19 @@ Future getPassword(String id) async { 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 ab79968f8..8c7acc503 100644 --- a/flutter_hbb/lib/remote_page.dart +++ b/flutter_hbb/lib/remote_page.dart @@ -233,6 +233,7 @@ class _RemotePageState extends State { setState(() { _mouseTools = !_mouseTools; resetTool(); + if (_mouseTools) _drag = true; }); }, )), @@ -300,6 +301,7 @@ class _RemotePageState extends State { _drag = false; _scroll = false; _right = false; + _mouseTools = false; }); } else if (_scroll) { var dy = (_yOffset - _yOffset0) / 10; @@ -837,13 +839,26 @@ void showActions(BuildContext context) { void showSetOSPassword(BuildContext context) async { final controller = TextEditingController(); var password = await getPassword(FFI.id); + var autoLogin = await getAutoLogin(FFI.id); controller.text = password; showAlertDialog( context, (setState) => Tuple3( - Text(translate('Password Required')), + Text(translate('OS Password')), Column(mainAxisSize: MainAxisSize.min, children: [ PasswordWidget(controller: controller), + CheckboxListTile( + contentPadding: const EdgeInsets.all(0), + dense: true, + controlAffinity: ListTileControlAffinity.leading, + title: Text( + translate('Auto Login'), + ), + value: autoLogin, + onChanged: (v) { + setState(() => autoLogin = v); + }, + ), ]), [ TextButton(