refactor input_os_password

This commit is contained in:
rustdesk 2021-08-06 21:18:06 +08:00
parent 799df2d77a
commit 0f029545a4
3 changed files with 38 additions and 1 deletions

View File

@ -236,6 +236,9 @@ class _HomePageState extends State<HomePage> {
); );
if (value == 'remove') { if (value == 'remove') {
setState(() => FFI.setByName('remove', '${p.id}')); setState(() => FFI.setByName('remove', '${p.id}'));
() async {
removePreference(p.id);
}();
} }
}(); }();
}, },

View File

@ -711,6 +711,12 @@ Future<Map<String, dynamic>> getPreference(String id) async {
return m; return m;
} }
void removePreference(String id) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.remove('peer' + id);
prefs.remove('peer' + id + '-password');
}
Future<String> getPassword(String id) async { Future<String> getPassword(String id) async {
SharedPreferences prefs = await SharedPreferences.getInstance(); SharedPreferences prefs = await SharedPreferences.getInstance();
var p = prefs.getString('peer' + id + '-password'); var p = prefs.getString('peer' + id + '-password');
@ -721,6 +727,19 @@ Future<String> getPassword(String id) async {
void savePassword(String id, String password) async { void savePassword(String id, String password) async {
SharedPreferences prefs = await SharedPreferences.getInstance(); SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setString('peer' + id + '-password', password); prefs.setString('peer' + id + '-password', password);
prefs.setString('peer' + id + '-autologin', password);
}
Future<bool> 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 { void initializeCursorAndCanvas() async {

View File

@ -233,6 +233,7 @@ class _RemotePageState extends State<RemotePage> {
setState(() { setState(() {
_mouseTools = !_mouseTools; _mouseTools = !_mouseTools;
resetTool(); resetTool();
if (_mouseTools) _drag = true;
}); });
}, },
)), )),
@ -300,6 +301,7 @@ class _RemotePageState extends State<RemotePage> {
_drag = false; _drag = false;
_scroll = false; _scroll = false;
_right = false; _right = false;
_mouseTools = false;
}); });
} else if (_scroll) { } else if (_scroll) {
var dy = (_yOffset - _yOffset0) / 10; var dy = (_yOffset - _yOffset0) / 10;
@ -837,13 +839,26 @@ void showActions(BuildContext context) {
void showSetOSPassword(BuildContext context) async { void showSetOSPassword(BuildContext context) async {
final controller = TextEditingController(); final controller = TextEditingController();
var password = await getPassword(FFI.id); var password = await getPassword(FFI.id);
var autoLogin = await getAutoLogin(FFI.id);
controller.text = password; controller.text = password;
showAlertDialog( showAlertDialog(
context, context,
(setState) => Tuple3( (setState) => Tuple3(
Text(translate('Password Required')), Text(translate('OS Password')),
Column(mainAxisSize: MainAxisSize.min, children: [ Column(mainAxisSize: MainAxisSize.min, children: [
PasswordWidget(controller: controller), 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( TextButton(