refactor
This commit is contained in:
parent
0f029545a4
commit
46e239dabe
@ -257,9 +257,9 @@ class _HomePageState extends State<HomePage> {
|
|||||||
|
|
||||||
void showServer(BuildContext context) {
|
void showServer(BuildContext context) {
|
||||||
final formKey = GlobalKey<FormState>();
|
final formKey = GlobalKey<FormState>();
|
||||||
final id0 = FFI.getByName('custom-rendezvous-server');
|
final id0 = FFI.getByName('option', 'custom-rendezvous-server');
|
||||||
final relay0 = FFI.getByName('relay-server');
|
final relay0 = FFI.getByName('option', 'relay-server');
|
||||||
final key0 = FFI.getByName('key');
|
final key0 = FFI.getByName('option', 'key');
|
||||||
var id = '';
|
var id = '';
|
||||||
var relay = '';
|
var relay = '';
|
||||||
var key = '';
|
var key = '';
|
||||||
@ -316,9 +316,14 @@ void showServer(BuildContext context) {
|
|||||||
if (formKey.currentState.validate()) {
|
if (formKey.currentState.validate()) {
|
||||||
formKey.currentState.save();
|
formKey.currentState.save();
|
||||||
if (id != id0)
|
if (id != id0)
|
||||||
FFI.setByName('custom-rendezvous-server', id);
|
FFI.setByName('option',
|
||||||
if (relay != relay0) FFI.setByName('relay-server', relay);
|
'{"name": "custom-rendezvous-server", "value": "${id}"}');
|
||||||
if (key != key0) FFI.setByName('key', key);
|
if (relay != relay0)
|
||||||
|
FFI.setByName('option',
|
||||||
|
'{"name": "relay-server", "value": "${relay}"}');
|
||||||
|
if (key != key0)
|
||||||
|
FFI.setByName(
|
||||||
|
'option', '{"name": "key", "value": "${key}"}');
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -714,32 +714,6 @@ Future<Map<String, dynamic>> getPreference(String id) async {
|
|||||||
void removePreference(String id) async {
|
void removePreference(String id) async {
|
||||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
prefs.remove('peer' + id);
|
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 {
|
void initializeCursorAndCanvas() async {
|
||||||
|
@ -782,8 +782,8 @@ void showActions(BuildContext context) {
|
|||||||
TextButton(
|
TextButton(
|
||||||
style: flatButtonStyle,
|
style: flatButtonStyle,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
showSetOSPassword(context);
|
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
|
showSetOSPassword(context, false);
|
||||||
},
|
},
|
||||||
child: Icon(Icons.edit),
|
child: Icon(Icons.edit),
|
||||||
)
|
)
|
||||||
@ -817,29 +817,20 @@ void showActions(BuildContext context) {
|
|||||||
}
|
}
|
||||||
}();
|
}();
|
||||||
} else if (value == 'enter_os_password') {
|
} else if (value == 'enter_os_password') {
|
||||||
() async {
|
var password = FFI.getByName('peer_option', "os-password");
|
||||||
var password = await getPassword(FFI.id);
|
|
||||||
if (password != "") {
|
if (password != "") {
|
||||||
var x = FFI.cursorModel.x;
|
FFI.setByName('input_os_password', password);
|
||||||
var y = FFI.cursorModel.y;
|
} else {
|
||||||
FFI.moveMouse(x + 3, y + 3);
|
showSetOSPassword(context, true);
|
||||||
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');
|
|
||||||
}
|
}
|
||||||
}();
|
|
||||||
}
|
}
|
||||||
}();
|
}();
|
||||||
}
|
}
|
||||||
|
|
||||||
void showSetOSPassword(BuildContext context) async {
|
void showSetOSPassword(BuildContext context, bool login) {
|
||||||
final controller = TextEditingController();
|
final controller = TextEditingController();
|
||||||
var password = await getPassword(FFI.id);
|
var password = FFI.getByName('peer_option', "os-password");
|
||||||
var autoLogin = await getAutoLogin(FFI.id);
|
var autoLogin = FFI.getByName('peer_option', "auto-login") != "";
|
||||||
controller.text = password;
|
controller.text = password;
|
||||||
showAlertDialog(
|
showAlertDialog(
|
||||||
context,
|
context,
|
||||||
@ -872,7 +863,14 @@ void showSetOSPassword(BuildContext context) async {
|
|||||||
style: flatButtonStyle,
|
style: flatButtonStyle,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
var text = controller.text.trim();
|
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);
|
Navigator.pop(context);
|
||||||
},
|
},
|
||||||
child: Text(translate('OK')),
|
child: Text(translate('OK')),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user