mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-01-19 08:23:01 +08:00
refactor
This commit is contained in:
parent
0f029545a4
commit
46e239dabe
@ -257,9 +257,9 @@ class _HomePageState extends State<HomePage> {
|
||||
|
||||
void showServer(BuildContext context) {
|
||||
final formKey = GlobalKey<FormState>();
|
||||
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);
|
||||
}
|
||||
},
|
||||
|
@ -714,32 +714,6 @@ Future<Map<String, dynamic>> getPreference(String id) async {
|
||||
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 {
|
||||
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<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 {
|
||||
|
@ -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')),
|
||||
|
Loading…
Reference in New Issue
Block a user