An open-source remote desktop application designed for self-hosting, as an alternative to TeamViewer.
Rust androidanydeskdartflatpakflutterflutter-appsioslinuxmacosp2prdpremote-controlremote-desktoprustrust-langteamviewervncwaylandwindows
fix: flutter remove setState in initState (#8807)
dignow79a1f888d651
diff --git a/flutter/lib/common/widgets/peer_tab_page.dart b/flutter/lib/common/widgets/peer_tab_page.dartindex 3b92ab1eb..66fba2312 100644--- a/flutter/lib/common/widgets/peer_tab_page.dart+++ b/flutter/lib/common/widgets/peer_tab_page.dart@@ -78,6 +78,13 @@ class _PeerTabPageState extends State<PeerTabPage>@overridevoid initState() {+ WidgetsBinding.instance.addPostFrameCallback((_) {+ _loadLocalOptions();+ });+ super.initState();+ }++ Future<void> _loadLocalOptions() async {final uiType = bind.getLocalFlutterOption(k: kOptionPeerCardUiType);if (uiType != '') {peerCardUiType.value = int.parse(uiType) == 0@@ -88,7 +95,6 @@ class _PeerTabPageState extends State<PeerTabPage>}hideAbTagsPanel.value =bind.mainGetLocalOption(key: kOptionHideAbTagsPanel) == 'Y';- super.initState();}Future<void> handleTabSelection(int tabIndex) async {@@ -875,18 +881,22 @@ class _PeerSortDropdownState extends State<PeerSortDropdown> {@overridevoid initState() {if (!PeerSortType.values.contains(peerSort.value)) {- Future.delayed(Duration.zero, () {- // do not change obx directly in initState, so do in future.- peerSort.value = PeerSortType.remoteId;- bind.setLocalFlutterOption(- k: kOptionPeerSorting,- v: peerSort.value,- );+ // do not change obx directly in initState, so do in future.+ WidgetsBinding.instance.addPostFrameCallback((_) {+ _loadLocalOptions();});}super.initState();}+ Future<void> _loadLocalOptions() async {+ peerSort.value = PeerSortType.remoteId;+ bind.setLocalFlutterOption(+ k: kOptionPeerSorting,+ v: peerSort.value,+ );+ }+@overrideWidget build(BuildContext context) {final style = TextStyle(diff --git a/flutter/lib/desktop/pages/file_manager_page.dart b/flutter/lib/desktop/pages/file_manager_page.dartindex 29ab0f806..3b4428f99 100644--- a/flutter/lib/desktop/pages/file_manager_page.dart+++ b/flutter/lib/desktop/pages/file_manager_page.dart@@ -98,7 +98,10 @@ class _FileManagerPageState extends State<FileManagerPage>}debugPrint("File manager page init success with id ${widget.id}");_ffi.dialogManager.setOverlayState(_overlayKeyState);- widget.tabController.onSelected?.call(widget.id);+ // Call onSelected in post frame callback, since we cannot guarantee that the callback will not call setState.+ WidgetsBinding.instance.addPostFrameCallback((_) {+ widget.tabController.onSelected?.call(widget.id);+ });}@overridediff --git a/flutter/lib/desktop/pages/port_forward_page.dart b/flutter/lib/desktop/pages/port_forward_page.dartindex 99f8df340..5541cb8b3 100644--- a/flutter/lib/desktop/pages/port_forward_page.dart+++ b/flutter/lib/desktop/pages/port_forward_page.dart@@ -65,7 +65,10 @@ class _PortForwardPageState extends State<PortForwardPage>isRdp: widget.isRDP);Get.put<FFI>(_ffi, tag: 'pf_${widget.id}');debugPrint("Port forward page init success with id ${widget.id}");- widget.tabController.onSelected?.call(widget.id);+ // Call onSelected in post frame callback, since we cannot guarantee that the callback will not call setState.+ WidgetsBinding.instance.addPostFrameCallback((_) {+ widget.tabController.onSelected?.call(widget.id);+ });}@overridediff --git a/flutter/lib/desktop/pages/remote_page.dart b/flutter/lib/desktop/pages/remote_page.dartindex f108f7444..08656a4df 100644--- a/flutter/lib/desktop/pages/remote_page.dart+++ b/flutter/lib/desktop/pages/remote_page.dart@@ -135,11 +135,13 @@ class _RemotePageState extends State<RemotePage>if (!isWeb) bind.pluginSyncUi(syncTo: kAppTypeDesktopRemote);_ffi.qualityMonitorModel.checkShowQualityMonitor(sessionId);_ffi.dialogManager.loadMobileActionsOverlayVisible();- // Session option should be set after models.dart/FFI.start- _showRemoteCursor.value = bind.sessionGetToggleOptionSync(- sessionId: sessionId, arg: 'show-remote-cursor');- _zoomCursor.value = bind.sessionGetToggleOptionSync(- sessionId: sessionId, arg: kOptionZoomCursor);+ WidgetsBinding.instance.addPostFrameCallback((_) {+ // Session option should be set after models.dart/FFI.start+ _showRemoteCursor.value = bind.sessionGetToggleOptionSync(+ sessionId: sessionId, arg: 'show-remote-cursor');+ _zoomCursor.value = bind.sessionGetToggleOptionSync(+ sessionId: sessionId, arg: kOptionZoomCursor);+ });DesktopMultiWindow.addListener(this);// if (!_isCustomCursorInited) {// customCursorController.registerNeedUpdateCursorCallback(@@ -154,7 +156,10 @@ class _RemotePageState extends State<RemotePage>// }_blockableOverlayState.applyFfi(_ffi);- widget.tabController?.onSelected?.call(widget.id);+ // Call onSelected in post frame callback, since we cannot guarantee that the callback will not call setState.+ WidgetsBinding.instance.addPostFrameCallback((_) {+ widget.tabController?.onSelected?.call(widget.id);+ });}@overridediff --git a/flutter/lib/desktop/pages/server_page.dart b/flutter/lib/desktop/pages/server_page.dartindex 1cac2706e..9701ca409 100644--- a/flutter/lib/desktop/pages/server_page.dart+++ b/flutter/lib/desktop/pages/server_page.dart@@ -129,7 +129,7 @@ class ConnectionManagerState extends State<ConnectionManager>if (client != null) {gFFI.chatModel.changeCurrentKey(MessageKey(client.peerId, client.id));if (client.unreadChatMessageCount.value > 0) {- Future.delayed(Duration.zero, () {+ WidgetsBinding.instance.addPostFrameCallback((_) {client.unreadChatMessageCount.value = 0;gFFI.chatModel.showChatPage(MessageKey(client.peerId, client.id));});@@ -399,7 +399,10 @@ class _CmHeaderState extends State<_CmHeader>_time.value = _time.value + 1;}});- gFFI.serverModel.tabController.onSelected?.call(client.id.toString());+ // Call onSelected in post frame callback, since we cannot guarantee that the callback will not call setState.+ WidgetsBinding.instance.addPostFrameCallback((_) {+ gFFI.serverModel.tabController.onSelected?.call(client.id.toString());+ });}@override@@ -732,7 +735,8 @@ class _CmControlPanel extends StatelessWidget {child: buildButton(context,color: MyTheme.accent,onClick: null, onTapDown: (details) async {- final devicesInfo = await AudioInput.getDevicesInfo(true, true);+ final devicesInfo =+ await AudioInput.getDevicesInfo(true, true);List<String> devices = devicesInfo['devices'] as List<String>;if (devices.isEmpty) {msgBox(@@ -764,7 +768,8 @@ class _CmControlPanel extends StatelessWidget {value: d,groupValue: currentDevice,onChanged: (v) {- if (v != null) AudioInput.setDevice(v, true, true);+ if (v != null)+ AudioInput.setDevice(v, true, true);},child: Container(child: Text(diff --git a/flutter/lib/desktop/widgets/popup_menu.dart b/flutter/lib/desktop/widgets/popup_menu.dartindex 7d8f7c78c..003979a70 100644--- a/flutter/lib/desktop/widgets/popup_menu.dart+++ b/flutter/lib/desktop/widgets/popup_menu.dart@@ -48,6 +48,12 @@ class MyPopupMenuItemState<T, W extends PopupMenuChildrenItem<T>>@overridevoid initState() {super.initState();+ WidgetsBinding.instance.addPostFrameCallback((_) {+ _initEnabled();+ });+ }++ Future<void> _initEnabled() async {if (widget.enabled != null) {enabled.value = widget.enabled!.value;}diff --git a/flutter/lib/desktop/widgets/remote_toolbar.dart b/flutter/lib/desktop/widgets/remote_toolbar.dartindex 9db65e072..cfc52c777 100644--- a/flutter/lib/desktop/widgets/remote_toolbar.dart+++ b/flutter/lib/desktop/widgets/remote_toolbar.dart@@ -372,7 +372,7 @@ class _RemoteToolbarState extends State<RemoteToolbar> {initState() {super.initState();- Future.delayed(Duration.zero, () async {+ WidgetsBinding.instance.addPostFrameCallback((_) async {_fractionX.value = double.tryParse(await bind.sessionGetOption(sessionId: widget.ffi.sessionId,arg: 'remote-menubar-drag-x') ??@@ -1278,7 +1278,9 @@ class _ResolutionsMenuState extends State<_ResolutionsMenu> {@overridevoid initState() {super.initState();- _getLocalResolutionWayland();+ WidgetsBinding.instance.addPostFrameCallback((_) {+ _getLocalResolutionWayland();+ });}Rect? scaledRect() {diff --git a/flutter/lib/desktop/widgets/tabbar_widget.dart b/flutter/lib/desktop/widgets/tabbar_widget.dartindex 513441113..a19ce105b 100644--- a/flutter/lib/desktop/widgets/tabbar_widget.dart+++ b/flutter/lib/desktop/widgets/tabbar_widget.dart@@ -1271,12 +1271,14 @@ class ActionIcon extends StatefulWidget {}class _ActionIconState extends State<ActionIcon> {- var hover = false.obs;+ final hover = false.obs;@overridevoid initState() {super.initState();- hover.value = false;+ WidgetsBinding.instance.addPostFrameCallback((_) {+ hover.value = false;+ });}@overridediff --git a/flutter/lib/mobile/pages/connection_page.dart b/flutter/lib/mobile/pages/connection_page.dartindex 4a2bb8b55..914fdec34 100644--- a/flutter/lib/mobile/pages/connection_page.dart+++ b/flutter/lib/mobile/pages/connection_page.dart@@ -55,14 +55,14 @@ class _ConnectionPageState extends State<ConnectionPage> {super.initState();if (!isWeb) _uniLinksSubscription = listenUniLinks();if (_idController.text.isEmpty) {- () async {+ WidgetsBinding.instance.addPostFrameCallback((_) async {final lastRemoteId = await bind.mainGetLastRemoteId();if (lastRemoteId != _idController.id) {setState(() {_idController.id = lastRemoteId;});}- }();+ });}if (isAndroid) {if (!bind.isCustomClient()) {diff --git a/flutter/lib/mobile/pages/remote_page.dart b/flutter/lib/mobile/pages/remote_page.dartindex 30598085f..3b962a1c3 100644--- a/flutter/lib/mobile/pages/remote_page.dart+++ b/flutter/lib/mobile/pages/remote_page.dart@@ -83,9 +83,11 @@ class _RemotePageState extends State<RemotePage> {initSharedStates(widget.id);gFFI.chatModel.changeCurrentKey(MessageKey(widget.id, ChatModel.clientModeID));- gFFI.chatModel.voiceCallStatus.value = VoiceCallStatus.notStarted;+ WidgetsBinding.instance.addPostFrameCallback((_) {+ gFFI.chatModel.voiceCallStatus.value = VoiceCallStatus.notStarted;+ gFFI.dialogManager.loadMobileActionsOverlayVisible();+ });_blockableOverlayState.applyFfi(gFFI);- gFFI.dialogManager.loadMobileActionsOverlayVisible();}@overridediff --git a/flutter/lib/mobile/pages/settings_page.dart b/flutter/lib/mobile/pages/settings_page.dartindex dd95c4275..72e48c6f5 100644--- a/flutter/lib/mobile/pages/settings_page.dart+++ b/flutter/lib/mobile/pages/settings_page.dart@@ -118,7 +118,7 @@ class _SettingsState extends State<SettingsPage> with WidgetsBindingObserver {_hideNetwork =bind.mainGetBuildinOption(key: kOptionHideNetworkSetting) == 'Y';- () async {+ WidgetsBinding.instance.addPostFrameCallback((_) async {var update = false;if (_hasIgnoreBattery) {@@ -177,7 +177,7 @@ class _SettingsState extends State<SettingsPage> with WidgetsBindingObserver {if (update) {setState(() {});}- }();+ });}@overridediff --git a/src/virtual_display_manager.rs b/src/virtual_display_manager.rsindex af5eda973..7807bd3d5 100644--- a/src/virtual_display_manager.rs+++ b/src/virtual_display_manager.rs@@ -2,7 +2,7 @@ use hbb_common::{bail, platform::windows::is_windows_version_or_greater, ResultTuse std::sync::atomic;// This string is defined here.-// https://github.com/rustdesk/RustDeskIddDriver/blob/b370aad3f50028b039aad211df60c8051c4a64d6/RustDeskIddDriver/RustDeskIddDriver.inf#LL73C1-L73C40+// https://github.com/rustdesk-org/RustDeskIddDriver/blob/b370aad3f50028b039aad211df60c8051c4a64d6/RustDeskIddDriver/RustDeskIddDriver.inf#LL73C1-L73C40pub const RUSTDESK_IDD_DEVICE_STRING: &'static str = "RustDeskIddDriver Device\0";pub const AMYUNI_IDD_DEVICE_STRING: &'static str = "USB Mobile Monitor Virtual Display\0";