From 0451a1c45f911d46cbb7bcdf5c5a8b857314edac Mon Sep 17 00:00:00 2001 From: dignow <136106582+dignow@users.noreply.github.com> Date: Thu, 25 Jul 2024 00:13:22 +0800 Subject: [PATCH] fix: mobile, server page, jumps on loading (#8819) Signed-off-by: dignow --- flutter/lib/common.dart | 63 +++++++++++++---------- flutter/lib/mobile/pages/server_page.dart | 2 +- src/flutter_ffi.rs | 6 +++ 3 files changed, 44 insertions(+), 27 deletions(-) diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart index 328d53c38..5db9d10f1 100644 --- a/flutter/lib/common.dart +++ b/flutter/lib/common.dart @@ -3326,6 +3326,42 @@ bool isInHomePage() { return controller.state.value.selected == 0; } +Widget _buildPresetPasswordWarning() { + if (bind.mainGetBuildinOption(key: kOptionRemovePresetPasswordWarning) != + 'N') { + return SizedBox.shrink(); + } + return Container( + color: Colors.yellow, + child: Column( + children: [ + Align( + child: Text( + translate("Security Alert"), + style: TextStyle( + color: Colors.red, + fontSize: + 18, // https://github.com/rustdesk/rustdesk-server-pro/issues/261 + fontWeight: FontWeight.bold, + ), + )).paddingOnly(bottom: 8), + Text( + translate("preset_password_warning"), + style: TextStyle(color: Colors.red), + ) + ], + ).paddingAll(8), + ); // Show a warning message if the Future completed with true +} + +Widget buildPresetPasswordWarningMobile() { + if (bind.isPresetPasswordMobileOnly()) { + return _buildPresetPasswordWarning(); + } else { + return SizedBox.shrink(); + } +} + Widget buildPresetPasswordWarning() { return FutureBuilder( future: bind.isPresetPassword(), @@ -3336,32 +3372,7 @@ Widget buildPresetPasswordWarning() { return Text( 'Error: ${snapshot.error}'); // Show an error message if the Future completed with an error } else if (snapshot.hasData && snapshot.data == true) { - if (bind.mainGetBuildinOption( - key: kOptionRemovePresetPasswordWarning) != - 'N') { - return SizedBox.shrink(); - } - return Container( - color: Colors.yellow, - child: Column( - children: [ - Align( - child: Text( - translate("Security Alert"), - style: TextStyle( - color: Colors.red, - fontSize: - 18, // https://github.com/rustdesk/rustdesk-server-pro/issues/261 - fontWeight: FontWeight.bold, - ), - )).paddingOnly(bottom: 8), - Text( - translate("preset_password_warning"), - style: TextStyle(color: Colors.red), - ) - ], - ).paddingAll(8), - ); // Show a warning message if the Future completed with true + return _buildPresetPasswordWarning(); } else { return SizedBox .shrink(); // Show nothing if the Future completed with false or null diff --git a/flutter/lib/mobile/pages/server_page.dart b/flutter/lib/mobile/pages/server_page.dart index 664496176..06258e5a5 100644 --- a/flutter/lib/mobile/pages/server_page.dart +++ b/flutter/lib/mobile/pages/server_page.dart @@ -187,7 +187,7 @@ class _ServerPageState extends State { child: Column( mainAxisAlignment: MainAxisAlignment.start, children: [ - buildPresetPasswordWarning(), + buildPresetPasswordWarningMobile(), gFFI.serverModel.isStart ? ServerInfo() : ServiceNotRunningNotification(), diff --git a/src/flutter_ffi.rs b/src/flutter_ffi.rs index 870a65912..08e79cbea 100644 --- a/src/flutter_ffi.rs +++ b/src/flutter_ffi.rs @@ -1966,6 +1966,12 @@ pub fn is_preset_password() -> bool { }) } +// Don't call this function for desktop version. +// We need this function because we want a sync return for mobile version. +pub fn is_preset_password_mobile_only() -> SyncReturn { + SyncReturn(is_preset_password()) +} + /// Send a url scheme through the ipc. /// /// * macOS only