diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart index 799894f7e..938be7888 100644 --- a/flutter/lib/common.dart +++ b/flutter/lib/common.dart @@ -1422,7 +1422,7 @@ Future saveWindowPosition(WindowType type, {int? windowId}) async { debugPrint( "Saving frame: $windowId: ${pos.width}/${pos.height}, offset:${pos.offsetWidth}/${pos.offsetHeight}"); - await bind.setLocalFlutterConfig( + await bind.setLocalFlutterOption( k: kWindowPrefix + type.name, v: pos.toString()); if (type == WindowType.RemoteDesktop && windowId != null) { @@ -1436,7 +1436,7 @@ Future _saveSessionWindowPosition( windowId, kWindowEventGetRemoteList, null); if (remoteList != null) { for (final peerId in remoteList.split(',')) { - bind.sessionSetFlutterConfigByPeerId( + bind.mainSetPeerFlutterOptionSync( id: peerId, k: kWindowPrefix + windowType.name, v: pos.toString()); } } @@ -1551,15 +1551,15 @@ Future restoreWindowPosition(WindowType type, // then we may need to get the position by reading the peer config. // Because the session may not be read at this time. if (desktopType == DesktopType.main) { - pos = bind.mainGetPeerFlutterConfigSync( + pos = bind.mainGetPeerFlutterOptionSync( id: peerId, k: kWindowPrefix + type.name); } else { - pos = await bind.sessionGetFlutterConfigByPeerId( + pos = await bind.sessionGetFlutterOptionByPeerId( id: peerId, k: kWindowPrefix + type.name); } isRemotePeerPos = pos != null; } - pos ??= bind.getLocalFlutterConfig(k: kWindowPrefix + type.name); + pos ??= bind.getLocalFlutterOption(k: kWindowPrefix + type.name); var lpos = LastWindowPosition.loadFromString(pos); if (lpos == null) { diff --git a/flutter/lib/common/widgets/peer_tab_page.dart b/flutter/lib/common/widgets/peer_tab_page.dart index 761a37011..daf81d231 100644 --- a/flutter/lib/common/widgets/peer_tab_page.dart +++ b/flutter/lib/common/widgets/peer_tab_page.dart @@ -64,7 +64,7 @@ class _PeerTabPageState extends State @override void initState() { - final uiType = bind.getLocalFlutterConfig(k: 'peer-card-ui-type'); + final uiType = bind.getLocalFlutterOption(k: 'peer-card-ui-type'); if (uiType != '') { peerCardUiType.value = int.parse(uiType) == PeerUiType.list.index ? PeerUiType.list @@ -174,7 +174,7 @@ class _PeerTabPageState extends State ).paddingSymmetric(horizontal: 4), onTap: () async { await handleTabSelection(t); - await bind.setLocalFlutterConfig( + await bind.setLocalFlutterOption( k: 'peer-tab-index', v: t.toString()); }, onHover: (value) => hover.value = value, @@ -244,7 +244,7 @@ class _PeerTabPageState extends State onTap: () async { final type = types.elementAt( peerCardUiType.value == types.elementAt(0) ? 1 : 0); - await bind.setLocalFlutterConfig( + await bind.setLocalFlutterOption( k: 'peer-card-ui-type', v: type.index.toString()); peerCardUiType.value = type; }, @@ -562,7 +562,7 @@ class _PeerSortDropdownState extends State { void initState() { if (!PeerSortType.values.contains(peerSort.value)) { peerSort.value = PeerSortType.remoteId; - bind.setLocalFlutterConfig( + bind.setLocalFlutterOption( k: "peer-sorting", v: peerSort.value, ); @@ -592,7 +592,7 @@ class _PeerSortDropdownState extends State { dense: true, (String? v) async { if (v != null) { peerSort.value = v; - await bind.setLocalFlutterConfig( + await bind.setLocalFlutterOption( k: "peer-sorting", v: peerSort.value, ); diff --git a/flutter/lib/common/widgets/peers_view.dart b/flutter/lib/common/widgets/peers_view.dart index c34299fd6..b4fd8e1d4 100644 --- a/flutter/lib/common/widgets/peers_view.dart +++ b/flutter/lib/common/widgets/peers_view.dart @@ -41,7 +41,7 @@ class LoadEvent { final peerSearchText = "".obs; /// for peer sort, global obs value -final peerSort = bind.getLocalFlutterConfig(k: 'peer-sorting').obs; +final peerSort = bind.getLocalFlutterOption(k: 'peer-sorting').obs; // list for listener final obslist = [peerSearchText, peerSort].obs; @@ -264,7 +264,7 @@ class _PeersViewState extends State<_PeersView> with WindowListener { // fallback to id sorting if (!PeerSortType.values.contains(sortedBy)) { sortedBy = PeerSortType.remoteId; - bind.setLocalFlutterConfig( + bind.setLocalFlutterOption( k: "peer-sorting", v: sortedBy, ); diff --git a/flutter/lib/desktop/widgets/remote_toolbar.dart b/flutter/lib/desktop/widgets/remote_toolbar.dart index dcf78b27b..d049804e2 100644 --- a/flutter/lib/desktop/widgets/remote_toolbar.dart +++ b/flutter/lib/desktop/widgets/remote_toolbar.dart @@ -36,7 +36,7 @@ class ToolbarState { late RxBool _pin; ToolbarState() { - final s = bind.getLocalFlutterConfig(k: kStoreKey); + final s = bind.getLocalFlutterOption(k: kStoreKey); if (s.isEmpty) { _initSet(false, false); return; @@ -89,7 +89,7 @@ class ToolbarState { } _savePin() async { - bind.setLocalFlutterConfig( + bind.setLocalFlutterOption( k: kStoreKey, v: jsonEncode({'pin': _pin.value})); } diff --git a/flutter/lib/models/model.dart b/flutter/lib/models/model.dart index 4b481dfe6..4dc17f9c2 100644 --- a/flutter/lib/models/model.dart +++ b/flutter/lib/models/model.dart @@ -1863,14 +1863,14 @@ Future setCanvasConfig( p['yCanvas'] = yCanvas; p['scale'] = scale; p['currentDisplay'] = currentDisplay; - await bind.sessionSetFlutterConfig( + await bind.sessionSetFlutterOption( sessionId: sessionId, k: canvasKey, v: jsonEncode(p)); } Future?> getCanvasConfig(SessionID sessionId) async { if (!isWebDesktop) return null; var p = - await bind.sessionGetFlutterConfig(sessionId: sessionId, k: canvasKey); + await bind.sessionGetFlutterOption(sessionId: sessionId, k: canvasKey); if (p == null || p.isEmpty) return null; try { Map m = json.decode(p); diff --git a/flutter/lib/models/peer_tab_model.dart b/flutter/lib/models/peer_tab_model.dart index e7f4192cd..2e65e64bd 100644 --- a/flutter/lib/models/peer_tab_model.dart +++ b/flutter/lib/models/peer_tab_model.dart @@ -51,7 +51,7 @@ class PeerTabModel with ChangeNotifier { PeerTabModel(this.parent) { // init currentTab _currentTab = - int.tryParse(bind.getLocalFlutterConfig(k: 'peer-tab-index')) ?? 0; + int.tryParse(bind.getLocalFlutterOption(k: 'peer-tab-index')) ?? 0; if (_currentTab < 0 || _currentTab >= tabNames.length) { _currentTab = 0; } diff --git a/libs/hbb_common/src/config.rs b/libs/hbb_common/src/config.rs index 56ffa9a01..c3aa2cfd9 100644 --- a/libs/hbb_common/src/config.rs +++ b/libs/hbb_common/src/config.rs @@ -1290,7 +1290,7 @@ impl LocalConfig { } } - pub fn get_flutter_config(k: &str) -> String { + pub fn get_flutter_option(k: &str) -> String { if let Some(v) = LOCAL_CONFIG.read().unwrap().ui_flutter.get(k) { v.clone() } else { @@ -1298,7 +1298,7 @@ impl LocalConfig { } } - pub fn set_flutter_config(k: String, v: String) { + pub fn set_flutter_option(k: String, v: String) { let mut config = LOCAL_CONFIG.write().unwrap(); let v2 = if v.is_empty() { None } else { Some(&v) }; if v2 != config.ui_flutter.get(&k) { diff --git a/src/client.rs b/src/client.rs index e9d319685..b71668a33 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1214,7 +1214,11 @@ impl LoginConfigHandler { /// * `v` - value of option pub fn save_ui_flutter(&mut self, k: String, v: String) { let mut config = self.load_config(); - config.ui_flutter.insert(k, v); + if v.is_empty() { + config.ui_flutter.remove(&k); + } else { + config.ui_flutter.insert(k, v); + } self.save_config(config); } diff --git a/src/flutter_ffi.rs b/src/flutter_ffi.rs index ef4c9e2ba..7f7af71b4 100644 --- a/src/flutter_ffi.rs +++ b/src/flutter_ffi.rs @@ -197,50 +197,39 @@ pub fn session_toggle_option(session_id: SessionID, value: String) { } } -pub fn session_get_flutter_config(session_id: SessionID, k: String) -> Option { +pub fn session_get_flutter_option(session_id: SessionID, k: String) -> Option { if let Some(session) = SESSIONS.read().unwrap().get(&session_id) { - Some(session.get_flutter_config(k)) + Some(session.get_flutter_option(k)) } else { None } } -pub fn session_set_flutter_config(session_id: SessionID, k: String, v: String) { +pub fn session_set_flutter_option(session_id: SessionID, k: String, v: String) { if let Some(session) = SESSIONS.write().unwrap().get_mut(&session_id) { - session.save_flutter_config(k, v); + session.save_flutter_option(k, v); } } -pub fn session_get_flutter_config_by_peer_id(id: String, k: String) -> Option { +pub fn session_get_flutter_option_by_peer_id(id: String, k: String) -> Option { if let Some((_, session)) = SESSIONS.read().unwrap().iter().find(|(_, s)| s.id == id) { - Some(session.get_flutter_config(k)) + Some(session.get_flutter_option(k)) } else { None } } -pub fn session_set_flutter_config_by_peer_id(id: String, k: String, v: String) { - if let Some((_, session)) = SESSIONS - .write() - .unwrap() - .iter_mut() - .find(|(_, s)| s.id == id) - { - session.save_flutter_config(k, v); - } -} - pub fn get_next_texture_key() -> SyncReturn { let k = TEXTURE_RENDER_KEY.fetch_add(1, Ordering::SeqCst) + 1; SyncReturn(k) } -pub fn get_local_flutter_config(k: String) -> SyncReturn { - SyncReturn(ui_interface::get_local_flutter_config(k)) +pub fn get_local_flutter_option(k: String) -> SyncReturn { + SyncReturn(ui_interface::get_local_flutter_option(k)) } -pub fn set_local_flutter_config(k: String, v: String) { - ui_interface::set_local_flutter_config(k, v); +pub fn set_local_flutter_option(k: String, v: String) { + ui_interface::set_local_flutter_option(k, v); } pub fn get_local_kb_layout_type() -> SyncReturn { @@ -806,10 +795,15 @@ pub fn main_get_peer_option_sync(id: String, key: String) -> SyncReturn SyncReturn(get_peer_option(id, key)) } -// Sometimes we need to get the flutter config of a peer by reading the file. +// Sometimes we need to get the flutter option of a peer by reading the file. // Because the session may not be established yet. -pub fn main_get_peer_flutter_config_sync(id: String, k: String) -> SyncReturn { - SyncReturn(get_peer_flutter_config(id, k)) +pub fn main_get_peer_flutter_option_sync(id: String, k: String) -> SyncReturn { + SyncReturn(get_peer_flutter_option(id, k)) +} + +pub fn main_set_peer_flutter_option_sync(id: String, k: String, v: String) -> SyncReturn<()> { + set_peer_flutter_option(id, k, v); + SyncReturn(()) } pub fn main_set_peer_option(id: String, key: String, value: String) { diff --git a/src/ui_interface.rs b/src/ui_interface.rs index b5f0cdb18..51f848457 100644 --- a/src/ui_interface.rs +++ b/src/ui_interface.rs @@ -168,14 +168,14 @@ pub fn set_local_option(key: String, value: String) { #[cfg(any(target_os = "android", target_os = "ios", feature = "flutter"))] #[inline] -pub fn get_local_flutter_config(key: String) -> String { - LocalConfig::get_flutter_config(&key) +pub fn get_local_flutter_option(key: String) -> String { + LocalConfig::get_flutter_option(&key) } #[cfg(any(target_os = "android", target_os = "ios", feature = "flutter"))] #[inline] -pub fn set_local_flutter_config(key: String, value: String) { - LocalConfig::set_flutter_config(key, value); +pub fn set_local_flutter_option(key: String, value: String) { + LocalConfig::set_flutter_option(key, value); } #[cfg(feature = "flutter")] @@ -210,11 +210,23 @@ pub fn get_peer_option(id: String, name: String) -> String { #[inline] #[cfg(feature = "flutter")] -pub fn get_peer_flutter_config(id: String, name: String) -> String { +pub fn get_peer_flutter_option(id: String, name: String) -> String { let c = PeerConfig::load(&id); c.ui_flutter.get(&name).unwrap_or(&"".to_owned()).to_owned() } +#[inline] +#[cfg(feature = "flutter")] +pub fn set_peer_flutter_option(id: String, name: String, value: String) { + let mut c = PeerConfig::load(&id); + if value.is_empty() { + c.ui_flutter.remove(&name); + } else { + c.ui_flutter.insert(name, value); + } + c.store(&id); +} + #[inline] pub fn set_peer_option(id: String, name: String, value: String) { let mut c = PeerConfig::load(&id); diff --git a/src/ui_session_interface.rs b/src/ui_session_interface.rs index 7ffcaac6d..bbf6d0aec 100644 --- a/src/ui_session_interface.rs +++ b/src/ui_session_interface.rs @@ -197,11 +197,11 @@ impl Session { self.lc.write().unwrap().save_scroll_style(value); } - pub fn save_flutter_config(&mut self, k: String, v: String) { + pub fn save_flutter_option(&mut self, k: String, v: String) { self.lc.write().unwrap().save_ui_flutter(k, v); } - pub fn get_flutter_config(&self, k: String) -> String { + pub fn get_flutter_option(&self, k: String) -> String { self.lc.read().unwrap().get_ui_flutter(&k) }