From 20db4bed01d1c0bcd87daf5ca2b53254b6313231 Mon Sep 17 00:00:00 2001 From: rustdesk Date: Thu, 22 Jun 2023 23:19:26 +0800 Subject: [PATCH] avoid currentUser call more than once when initializing app --- flutter/lib/desktop/pages/connection_page.dart | 3 ++- flutter/lib/main.dart | 6 +----- flutter/lib/models/user_model.dart | 6 ++++++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/flutter/lib/desktop/pages/connection_page.dart b/flutter/lib/desktop/pages/connection_page.dart index 94f55cb7f..096dd069e 100644 --- a/flutter/lib/desktop/pages/connection_page.dart +++ b/flutter/lib/desktop/pages/connection_page.dart @@ -253,7 +253,8 @@ class _ConnectionPageState extends State width: 8, decoration: BoxDecoration( borderRadius: BorderRadius.circular(4), - color: svcStopped.value || stateGlobal.svcStatus.value == SvcStatus.connecting + color: svcStopped.value || + stateGlobal.svcStatus.value == SvcStatus.connecting ? kColorWarn : (stateGlobal.svcStatus.value == SvcStatus.ready ? Color.fromARGB(255, 50, 190, 166) diff --git a/flutter/lib/main.dart b/flutter/lib/main.dart index 9c032ffa1..14534613a 100644 --- a/flutter/lib/main.dart +++ b/flutter/lib/main.dart @@ -33,9 +33,6 @@ int? kWindowId; WindowType? kWindowType; late List kBootArgs; -/// Uni links. -StreamSubscription? _uniLinkSubscription; - Future main(List args) async { WidgetsFlutterBinding.ensureInitialized(); debugPrint("launch args: $args"); @@ -123,7 +120,6 @@ void runMainApp(bool startService) async { // trigger connection status updater await bind.mainCheckConnectStatus(); if (startService) { - // await windowManager.ensureInitialized(); gFFI.serverModel.startService(); bind.pluginSyncUi(syncTo: kAppTypeMain); bind.pluginListReload(); @@ -229,7 +225,7 @@ void runConnectionManagerScreen(bool hide) async { await showCmWindow(isStartup: true); } // Start the uni links handler and redirect links to Native, not for Flutter. - _uniLinkSubscription = listenUniLinks(handleByFlutter: false); + listenUniLinks(handleByFlutter: false); } showCmWindow({bool isStartup = false}) async { diff --git a/flutter/lib/models/user_model.dart b/flutter/lib/models/user_model.dart index 5865f45e9..39e440364 100644 --- a/flutter/lib/models/user_model.dart +++ b/flutter/lib/models/user_model.dart @@ -10,6 +10,8 @@ import '../common.dart'; import 'model.dart'; import 'platform_model.dart'; +bool refresing_user = false; + class UserModel { final RxString userName = ''.obs; final RxBool isAdmin = false.obs; @@ -29,13 +31,16 @@ class UserModel { 'id': await bind.mainGetMyId(), 'uuid': await bind.mainGetUuid() }; + if (refresing_user) return; try { + refresing_user = true; final response = await http.post(Uri.parse('$url/api/currentUser'), headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer $token' }, body: json.encode(body)); + refresing_user = false; final status = response.statusCode; if (status == 401 || status == 400) { reset(); @@ -52,6 +57,7 @@ class UserModel { } catch (e) { debugPrint('Failed to refreshCurrentUser: $e'); } finally { + refresing_user = false; await updateOtherModels(); } }