refactor all [setByName] [getByName] to async bridge function

This commit is contained in:
csf
2022-08-08 22:27:27 +08:00
parent c5d0628291
commit e420178750
18 changed files with 332 additions and 470 deletions

View File

@@ -825,10 +825,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) {
@@ -846,7 +870,7 @@ class _WebMenuState extends State<WebMenu> {
value: "server",
)
] +
(getUrl().contains('admin.rustdesk.com')
(url.contains('admin.rustdesk.com')
? <PopupMenuItem<String>>[]
: [
PopupMenuItem(

View File

@@ -275,9 +275,7 @@ class _DesktopHomePageState extends State<DesktopHomePage> with TrayListener {
),
IconButton(
icon: Icon(Icons.refresh),
onPressed: () {
gFFI.setByName("temporary_password");
},
onPressed: () => bind.mainUpdateTemporaryPassword(),
),
FutureBuilder<Widget>(
future: buildPasswordPopupMenu(context),
@@ -360,7 +358,7 @@ class _DesktopHomePageState extends State<DesktopHomePage> with TrayListener {
if (gFFI.serverModel.temporaryPasswordLength !=
e) {
gFFI.serverModel.temporaryPasswordLength = e;
gFFI.setByName("temporary_password");
bind.mainUpdateTemporaryPassword();
}
},
))
@@ -1336,8 +1334,8 @@ Future<bool> loginDialog() async {
return completer.future;
}
void setPasswordDialog() {
final pw = gFFI.getByName("permanent_password");
void setPasswordDialog() async {
final pw = await bind.mainGetPermanentPassword();
final p0 = TextEditingController(text: pw);
final p1 = TextEditingController(text: pw);
var errMsg0 = "";
@@ -1427,7 +1425,7 @@ void setPasswordDialog() {
});
return;
}
gFFI.setByName("permanent_password", pass);
bind.mainSetPermanentPassword(password: pass);
close();
},
child: Text(translate("OK"))),

View File

@@ -348,8 +348,9 @@ class _RemotePageState extends State<RemotePage>
if (dy > 0)
dy = -1;
else if (dy < 0) dy = 1;
_ffi.setByName('send_mouse',
'{"id": "${widget.id}", "type": "wheel", "x": "$dx", "y": "$dy"}');
bind.sessionSendMouse(
id: widget.id,
msg: '{"type": "wheel", "x": "$dx", "y": "$dy"}');
}
},
child: MouseRegion(

View File

@@ -187,7 +187,7 @@ class _PeerCardState extends State<_PeerCard>
elevation: 8,
);
if (value == 'remove') {
setState(() => gFFI.setByName('remove', '$id'));
setState(() => bind.mainRemovePeer(id: id));
() async {
removePreference(id);
}();