mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
refactor all [setByName] [getByName] to async bridge function
This commit is contained in:
@@ -54,8 +54,9 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
||||
}();
|
||||
}
|
||||
if (isAndroid) {
|
||||
Timer(Duration(seconds: 5), () {
|
||||
_updateUrl = gFFI.getByName('software_update_url');
|
||||
Timer(Duration(seconds: 5), () async {
|
||||
_updateUrl = await bind.mainGetSoftwareUpdateUrl();
|
||||
;
|
||||
if (_updateUrl.isNotEmpty) setState(() {});
|
||||
});
|
||||
}
|
||||
@@ -299,7 +300,7 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
||||
elevation: 8,
|
||||
);
|
||||
if (value == 'remove') {
|
||||
setState(() => gFFI.setByName('remove', '$id'));
|
||||
setState(() => bind.mainRemovePeer(id: id));
|
||||
() async {
|
||||
removePreference(id);
|
||||
}();
|
||||
@@ -315,10 +316,34 @@ class WebMenu extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _WebMenuState extends State<WebMenu> {
|
||||
String? username;
|
||||
String url = "";
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
() async {
|
||||
final usernameRes = await getUsername();
|
||||
final urlRes = await getUrl();
|
||||
var update = false;
|
||||
if (usernameRes != username) {
|
||||
username = usernameRes;
|
||||
update = true;
|
||||
}
|
||||
if (urlRes != url) {
|
||||
url = urlRes;
|
||||
update = true;
|
||||
}
|
||||
|
||||
if (update) {
|
||||
setState(() {});
|
||||
}
|
||||
}();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Provider.of<FfiModel>(context);
|
||||
final username = getUsername();
|
||||
return PopupMenuButton<String>(
|
||||
icon: Icon(Icons.more_vert),
|
||||
itemBuilder: (context) {
|
||||
@@ -336,7 +361,7 @@ class _WebMenuState extends State<WebMenu> {
|
||||
value: "server",
|
||||
)
|
||||
] +
|
||||
(getUrl().contains('admin.rustdesk.com')
|
||||
(url.contains('admin.rustdesk.com')
|
||||
? <PopupMenuItem<String>>[]
|
||||
: [
|
||||
PopupMenuItem(
|
||||
|
||||
@@ -330,8 +330,9 @@ class _RemotePageState extends State<RemotePage> {
|
||||
if (dy > 0)
|
||||
dy = -1;
|
||||
else if (dy < 0) dy = 1;
|
||||
gFFI.setByName(
|
||||
'send_mouse', '{"type": "wheel", "x": "$dx", "y": "$dy"}');
|
||||
bind.sessionSendMouse(
|
||||
id: widget.id,
|
||||
msg: '{"type": "wheel", "x": "$dx", "y": "$dy"}');
|
||||
}
|
||||
},
|
||||
child: MouseRegion(
|
||||
@@ -1124,7 +1125,7 @@ void showRestartRemoteDevice(PeerInfo pi, String id) async {
|
||||
onPressed: () => close(true), child: Text(translate("OK"))),
|
||||
],
|
||||
));
|
||||
if (res == true) gFFI.setByName('restart_remote_device');
|
||||
if (res == true) bind.sessionRestartRemoteDevice(id: id);
|
||||
}
|
||||
|
||||
void showSetOSPassword(String id, bool login) async {
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hbb/mobile/widgets/dialog.dart';
|
||||
import 'package:flutter_hbb/models/model.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../common.dart';
|
||||
import '../../models/model.dart';
|
||||
import '../../models/platform_model.dart';
|
||||
import '../../models/server_model.dart';
|
||||
import 'home_page.dart';
|
||||
|
||||
@@ -99,10 +96,7 @@ class ServerPage extends StatelessWidget implements PageShape {
|
||||
} else if (value == kUsePermanentPassword ||
|
||||
value == kUseTemporaryPassword ||
|
||||
value == kUseBothPasswords) {
|
||||
Map<String, String> msg = Map()
|
||||
..["name"] = "verification-method"
|
||||
..["value"] = value;
|
||||
gFFI.setByName('option', jsonEncode(msg));
|
||||
bind.mainSetOption(key: "verification-method", value: value);
|
||||
gFFI.serverModel.updatePasswordModel();
|
||||
}
|
||||
})
|
||||
@@ -183,9 +177,8 @@ class ServerInfo extends StatelessWidget {
|
||||
? null
|
||||
: IconButton(
|
||||
icon: const Icon(Icons.refresh),
|
||||
onPressed: () {
|
||||
gFFI.setByName("temporary_password");
|
||||
})),
|
||||
onPressed: () =>
|
||||
bind.mainUpdateTemporaryPassword())),
|
||||
onSaved: (String? value) {},
|
||||
),
|
||||
],
|
||||
@@ -406,8 +399,7 @@ class ConnectionManager extends StatelessWidget {
|
||||
MaterialStateProperty.all(Colors.red)),
|
||||
icon: Icon(Icons.close),
|
||||
onPressed: () {
|
||||
gFFI.setByName(
|
||||
"close_conn", entry.key.toString());
|
||||
bind.serverCloseConnection(connId: entry.key);
|
||||
gFFI.invokeMethod(
|
||||
"cancel_notification", entry.key);
|
||||
},
|
||||
|
||||
@@ -31,15 +31,38 @@ class SettingsPage extends StatefulWidget implements PageShape {
|
||||
const url = 'https://rustdesk.com/';
|
||||
final _hasIgnoreBattery = androidVersion >= 26;
|
||||
var _ignoreBatteryOpt = false;
|
||||
var _enableAbr = false;
|
||||
|
||||
class _SettingsState extends State<SettingsPage> with WidgetsBindingObserver {
|
||||
String? username;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
if (_hasIgnoreBattery) {
|
||||
updateIgnoreBatteryStatus();
|
||||
}
|
||||
|
||||
() async {
|
||||
var update = false;
|
||||
if (_hasIgnoreBattery) {
|
||||
update = await updateIgnoreBatteryStatus();
|
||||
}
|
||||
|
||||
final usernameRes = await getUsername();
|
||||
if (usernameRes != username) {
|
||||
update = true;
|
||||
username = usernameRes;
|
||||
}
|
||||
|
||||
final enableAbrRes = await bind.mainGetOption(key: "enable-abr") != "N";
|
||||
if (enableAbrRes != _enableAbr) {
|
||||
update = true;
|
||||
_enableAbr = enableAbrRes;
|
||||
}
|
||||
|
||||
if (update) {
|
||||
setState(() {});
|
||||
}
|
||||
}();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -51,16 +74,18 @@ class _SettingsState extends State<SettingsPage> with WidgetsBindingObserver {
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
if (state == AppLifecycleState.resumed) {
|
||||
updateIgnoreBatteryStatus();
|
||||
() async {
|
||||
if (await updateIgnoreBatteryStatus()) {
|
||||
setState(() {});
|
||||
}
|
||||
}();
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> updateIgnoreBatteryStatus() async {
|
||||
final res = await PermissionManager.check("ignore_battery_optimizations");
|
||||
if (_ignoreBatteryOpt != res) {
|
||||
setState(() {
|
||||
_ignoreBatteryOpt = res;
|
||||
});
|
||||
_ignoreBatteryOpt = res;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@@ -70,21 +95,15 @@ class _SettingsState extends State<SettingsPage> with WidgetsBindingObserver {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Provider.of<FfiModel>(context);
|
||||
final username = getUsername();
|
||||
final enableAbr = gFFI.getByName("option", "enable-abr") != 'N';
|
||||
final enhancementsTiles = [
|
||||
SettingsTile.switchTile(
|
||||
title: Text(translate('Adaptive Bitrate') + '(beta)'),
|
||||
initialValue: enableAbr,
|
||||
title: Text(translate('Adaptive Bitrate') + ' (beta)'),
|
||||
initialValue: _enableAbr,
|
||||
onToggle: (v) {
|
||||
final msg = Map()
|
||||
..["name"] = "enable-abr"
|
||||
..["value"] = "";
|
||||
if (!v) {
|
||||
msg["value"] = "N";
|
||||
}
|
||||
gFFI.setByName("option", json.encode(msg));
|
||||
setState(() {});
|
||||
bind.mainSetOption(key: "enable-abr", value: v ? "" : "N");
|
||||
setState(() {
|
||||
_enableAbr = !_enableAbr;
|
||||
});
|
||||
},
|
||||
)
|
||||
];
|
||||
@@ -196,7 +215,7 @@ void showServerSettings() async {
|
||||
|
||||
void showLanguageSettings() async {
|
||||
try {
|
||||
final langs = json.decode(gFFI.getByName('langs')) as List<dynamic>;
|
||||
final langs = json.decode(await bind.mainGetLangs()) as List<dynamic>;
|
||||
var lang = await bind.mainGetLocalOption(key: "lang");
|
||||
DialogManager.show((setState, close) {
|
||||
final setLang = (v) {
|
||||
@@ -297,20 +316,19 @@ String parseResp(String body) {
|
||||
}
|
||||
final token = data['access_token'];
|
||||
if (token != null) {
|
||||
gFFI.setByName('option', '{"name": "access_token", "value": "$token"}');
|
||||
bind.mainSetOption(key: "access_token", value: token);
|
||||
}
|
||||
final info = data['user'];
|
||||
if (info != null) {
|
||||
final value = json.encode(info);
|
||||
gFFI.setByName(
|
||||
'option', json.encode({"name": "user_info", "value": value}));
|
||||
bind.mainSetOption(key: "user_info", value: value);
|
||||
gFFI.ffiModel.updateUser();
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
void refreshCurrentUser() async {
|
||||
final token = gFFI.getByName("option", "access_token");
|
||||
final token = await bind.mainGetOption(key: "access_token");
|
||||
if (token == '') return;
|
||||
final url = getUrl();
|
||||
final body = {'id': bind.mainGetMyId(), 'uuid': bind.mainGetUuid()};
|
||||
@@ -333,7 +351,7 @@ void refreshCurrentUser() async {
|
||||
}
|
||||
|
||||
void logout() async {
|
||||
final token = gFFI.getByName("option", "access_token");
|
||||
final token = await bind.mainGetOption(key: "access_token");
|
||||
if (token == '') return;
|
||||
final url = getUrl();
|
||||
final body = {'id': bind.mainGetMyId(), 'uuid': bind.mainGetUuid()};
|
||||
@@ -350,16 +368,16 @@ void logout() async {
|
||||
resetToken();
|
||||
}
|
||||
|
||||
void resetToken() {
|
||||
gFFI.setByName('option', '{"name": "access_token", "value": ""}');
|
||||
gFFI.setByName('option', '{"name": "user_info", "value": ""}');
|
||||
void resetToken() async {
|
||||
await bind.mainSetOption(key: "access_token", value: "");
|
||||
await bind.mainSetOption(key: "user_info", value: "");
|
||||
gFFI.ffiModel.updateUser();
|
||||
}
|
||||
|
||||
String getUrl() {
|
||||
var url = gFFI.getByName('option', 'api-server');
|
||||
Future<String> getUrl() async {
|
||||
var url = await bind.mainGetOption(key: "api-server");
|
||||
if (url == '') {
|
||||
url = gFFI.getByName('option', 'custom-rendezvous-server');
|
||||
url = await bind.mainGetOption(key: "custom-rendezvous-server");
|
||||
if (url != '') {
|
||||
if (url.contains(':')) {
|
||||
final tmp = url.split(':');
|
||||
@@ -448,11 +466,11 @@ void showLogin() {
|
||||
});
|
||||
}
|
||||
|
||||
String? getUsername() {
|
||||
final token = gFFI.getByName("option", "access_token");
|
||||
Future<String?> getUsername() async {
|
||||
final token = await bind.mainGetOption(key: "access_token");
|
||||
String? username;
|
||||
if (token != "") {
|
||||
final info = gFFI.getByName("option", "user_info");
|
||||
final info = await bind.mainGetOption(key: "user_info");
|
||||
if (info != "") {
|
||||
try {
|
||||
Map<String, dynamic> tmp = json.decode(info);
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
|
||||
import '../../common.dart';
|
||||
import '../../models/model.dart';
|
||||
import '../../models/platform_model.dart';
|
||||
|
||||
void clientClose() {
|
||||
msgBox('', 'Close', 'Are you sure to close the connection?');
|
||||
@@ -22,8 +20,8 @@ void showError({Duration duration = SEC1}) {
|
||||
showToast(translate("Error"), duration: SEC1);
|
||||
}
|
||||
|
||||
void setPermanentPasswordDialog() {
|
||||
final pw = gFFI.getByName("permanent_password");
|
||||
void setPermanentPasswordDialog() async {
|
||||
final pw = await bind.mainGetPermanentPassword();
|
||||
final p0 = TextEditingController(text: pw);
|
||||
final p1 = TextEditingController(text: pw);
|
||||
var validateLength = false;
|
||||
@@ -103,9 +101,9 @@ void setPermanentPasswordDialog() {
|
||||
});
|
||||
}
|
||||
|
||||
void setTemporaryPasswordLengthDialog() {
|
||||
void setTemporaryPasswordLengthDialog() async {
|
||||
List<String> lengths = ['6', '8', '10'];
|
||||
String length = gFFI.getByName('option', 'temporary-password-length');
|
||||
String length = await bind.mainGetOption(key: "temporary-password-length");
|
||||
var index = lengths.indexOf(length);
|
||||
if (index < 0) index = 0;
|
||||
length = lengths[index];
|
||||
@@ -116,11 +114,8 @@ void setTemporaryPasswordLengthDialog() {
|
||||
setState(() {
|
||||
length = newValue;
|
||||
});
|
||||
Map<String, String> msg = Map()
|
||||
..["name"] = "temporary-password-length"
|
||||
..["value"] = newValue;
|
||||
gFFI.setByName("option", jsonEncode(msg));
|
||||
gFFI.setByName("temporary_password");
|
||||
bind.mainSetOption(key: "temporary-password-length", value: newValue);
|
||||
bind.mainUpdateTemporaryPassword();
|
||||
Future.delayed(Duration(milliseconds: 200), () {
|
||||
close();
|
||||
showSuccess();
|
||||
@@ -138,9 +133,9 @@ void setTemporaryPasswordLengthDialog() {
|
||||
}, backDismiss: true, clickMaskDismiss: true);
|
||||
}
|
||||
|
||||
void enterPasswordDialog(String id) {
|
||||
void enterPasswordDialog(String id) async {
|
||||
final controller = TextEditingController();
|
||||
var remember = gFFI.getByName('remember', id) == 'true';
|
||||
var remember = await bind.getSessionRemember(id: id) ?? false;
|
||||
DialogManager.show((setState, close) {
|
||||
return CustomAlertDialog(
|
||||
title: Text(translate('Password Required')),
|
||||
|
||||
Reference in New Issue
Block a user