From f42c6ffeaf6ec66101d7389586bab7fe906453aa Mon Sep 17 00:00:00 2001 From: fufesou Date: Mon, 29 Aug 2022 22:46:19 +0800 Subject: [PATCH] flutter_desktop: connection type icon, tested windows Signed-off-by: fufesou --- flutter/lib/common/shared_state.dart | 24 +++-- .../desktop/pages/connection_tab_page.dart | 90 +++++++++++-------- flutter/lib/desktop/pages/remote_page.dart | 2 - src/lang/cn.rs | 4 + src/lang/cs.rs | 4 + src/lang/da.rs | 4 + src/lang/de.rs | 4 + src/lang/eo.rs | 4 + src/lang/es.rs | 4 + src/lang/fr.rs | 4 + src/lang/hu.rs | 4 + src/lang/id.rs | 4 + src/lang/it.rs | 4 + src/lang/ja.rs | 4 + src/lang/ko.rs | 4 + src/lang/pl.rs | 4 + src/lang/pt_PT.rs | 4 + src/lang/ptbr.rs | 4 + src/lang/ru.rs | 4 + src/lang/sk.rs | 4 + src/lang/template.rs | 4 + src/lang/tr.rs | 4 + src/lang/tw.rs | 4 + src/lang/vn.rs | 4 + 24 files changed, 154 insertions(+), 46 deletions(-) diff --git a/flutter/lib/common/shared_state.dart b/flutter/lib/common/shared_state.dart index 8ff4e667e..7232cb6ad 100644 --- a/flutter/lib/common/shared_state.dart +++ b/flutter/lib/common/shared_state.dart @@ -45,12 +45,17 @@ class ConnectionType { Rx get secure => _secure; Rx get direct => _direct; + static String get strSecure => 'secure'; + static String get strInsecure => 'insecure'; + static String get strDirect => ''; + static String get strIndirect => '_relay'; + void setSecure(bool v) { - _secure.value = v ? 'secure' : 'insecure'; + _secure.value = v ? strSecure : strInsecure; } void setDirect(bool v) { - _direct.value = v ? '' : '_relay'; + _direct.value = v ? strDirect : strIndirect; } bool isValid() { @@ -63,11 +68,20 @@ class ConnectionTypeState { static String tag(String id) => 'connection_type_$id'; static void init(String id) { - final ConnectionType collectionType = ConnectionType(); - Get.put(collectionType, tag: tag(id)); + final key = tag(id); + if (!Get.isRegistered(tag: key)) { + final ConnectionType collectionType = ConnectionType(); + Get.put(collectionType, tag: key); + } + } + + static void delete(String id) { + final key = tag(id); + if (Get.isRegistered(tag: key)) { + Get.delete(tag: key); + } } - static void delete(String id) => Get.delete(tag: tag(id)); static ConnectionType find(String id) => Get.find(tag: tag(id)); } diff --git a/flutter/lib/desktop/pages/connection_tab_page.dart b/flutter/lib/desktop/pages/connection_tab_page.dart index 75471af0e..1b9e04ebf 100644 --- a/flutter/lib/desktop/pages/connection_tab_page.dart +++ b/flutter/lib/desktop/pages/connection_tab_page.dart @@ -28,15 +28,17 @@ class _ConnectionTabPageState extends State { _ConnectionTabPageState(Map params) { final RxBool fullscreen = Get.find(tag: 'fullscreen'); - if (params['id'] != null) { + final peerId = params['id']; + if (peerId != null) { + ConnectionTypeState.init(peerId); tabController.add(TabInfo( - key: params['id'], - label: params['id'], + key: peerId, + label: peerId, selectedIcon: selectedIcon, unselectedIcon: unselectedIcon, page: Obx(() => RemotePage( - key: ValueKey(params['id']), - id: params['id'], + key: ValueKey(peerId), + id: peerId, tabBarHeight: fullscreen.isTrue ? 0 : kDesktopRemoteTabBarHeight, )))); @@ -89,10 +91,10 @@ class _ConnectionTabPageState extends State { child: Scaffold( backgroundColor: MyTheme.color(context).bg, body: Obx(() => DesktopTab( - controller: tabController, - theme: theme, - isMainWindow: false, - showTabBar: fullscreen.isFalse, + controller: tabController, + theme: theme, + isMainWindow: false, + showTabBar: fullscreen.isFalse, onClose: () { tabController.clear(); }, @@ -104,36 +106,45 @@ class _ConnectionTabPageState extends State { .setFullscreen(fullscreen.isTrue); return pageView; }, - tabBuilder: (key, icon, label, themeConf) { - final connectionType = ConnectionTypeState.find(key); - if (!connectionType.isValid()) { - return Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - icon, - label, - ], - ); - } else { - final iconName = - '${connectionType.secure.value}${connectionType.direct.value}'; - final connectionIcon = Image.asset( - 'assets/$iconName.png', - width: themeConf.iconSize, - height: themeConf.iconSize, - color: theme.selectedtabIconColor, - ); - //.paddingOnly(right: 5); - return Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - icon, - connectionIcon, - label, - ], - ); - } - }))), + tabBuilder: (key, icon, label, themeConf) => Obx(() { + final connectionType = ConnectionTypeState.find(key); + if (!ConnectionTypeState.find(key).isValid()) { + return Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + icon, + label, + ], + ); + } else { + final msgDirect = translate( + connectionType.direct.value == + ConnectionType.strDirect + ? 'Direct Connection' + : 'Relay Connection'); + final msgSecure = translate( + connectionType.secure.value == + ConnectionType.strSecure + ? 'Secure Connection' + : 'Insecure Connection'); + return Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + icon, + Tooltip( + message: '$msgDirect\n$msgSecure', + child: Image.asset( + 'assets/${connectionType.secure.value}${connectionType.direct.value}.png', + width: themeConf.iconSize, + height: themeConf.iconSize, + ).paddingOnly(right: 5), + ), + label, + ], + ); + } + }), + ))), ), )); } @@ -142,6 +153,7 @@ class _ConnectionTabPageState extends State { if (tabController.state.value.tabs.isEmpty) { WindowController.fromWindowId(windowId()).hide(); } + ConnectionTypeState.delete(id); } int windowId() { diff --git a/flutter/lib/desktop/pages/remote_page.dart b/flutter/lib/desktop/pages/remote_page.dart index 14635e5a1..f723b17d0 100644 --- a/flutter/lib/desktop/pages/remote_page.dart +++ b/flutter/lib/desktop/pages/remote_page.dart @@ -58,14 +58,12 @@ class _RemotePageState extends State PrivacyModeState.init(id); BlockInputState.init(id); CurrentDisplayState.init(id); - ConnectionTypeState.init(id); } void _removeStates(String id) { PrivacyModeState.delete(id); BlockInputState.delete(id); CurrentDisplayState.delete(id); - ConnectionTypeState.delete(id); } @override diff --git a/src/lang/cn.rs b/src/lang/cn.rs index 3e50396e6..fdb23f88e 100644 --- a/src/lang/cn.rs +++ b/src/lang/cn.rs @@ -313,5 +313,9 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Scroll Style", "滚屏方式"), ("Show Menubar", "显示菜单栏"), ("Hide Menubar", "隐藏菜单栏"), + ("Direct Connection", "直接连接"), + ("Relay Connection", "中继连接"), + ("Secure Connection", "安全连接"), + ("Insecure Connection", "非安全连接"), ].iter().cloned().collect(); } diff --git a/src/lang/cs.rs b/src/lang/cs.rs index f94df1ceb..d9ddf78cc 100644 --- a/src/lang/cs.rs +++ b/src/lang/cs.rs @@ -313,5 +313,9 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Scroll Style", "Štýl posúvania"), ("Show Menubar", "Zobrazit panel nabídek"), ("Hide Menubar", "skrýt panel nabídek"), + ("Direct Connection", "Přímé spojení"), + ("Relay Connection", "Připojení relé"), + ("Secure Connection", "Zabezpečené připojení"), + ("Insecure Connection", "Nezabezpečené připojení"), ].iter().cloned().collect(); } diff --git a/src/lang/da.rs b/src/lang/da.rs index c0f7abf91..0e2d99425 100644 --- a/src/lang/da.rs +++ b/src/lang/da.rs @@ -313,5 +313,9 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Scroll Style", "Rulstil"), ("Show Menubar", "Vis menulinje"), ("Hide Menubar", "skjul menulinjen"), + ("Direct Connection", "Direkte forbindelse"), + ("Relay Connection", "Relæforbindelse"), + ("Secure Connection", "Sikker forbindelse"), + ("Insecure Connection", "Usikker forbindelse"), ].iter().cloned().collect(); } diff --git a/src/lang/de.rs b/src/lang/de.rs index e411a751d..20cd9330e 100644 --- a/src/lang/de.rs +++ b/src/lang/de.rs @@ -313,5 +313,9 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Scroll Style", "Scroll-Stil"), ("Show Menubar", "Menüleiste anzeigen"), ("Hide Menubar", "Menüleiste ausblenden"), + ("Direct Connection", "Direkte Verbindung"), + ("Relay Connection", "Relaisverbindung"), + ("Secure Connection", "Sichere Verbindung"), + ("Insecure Connection", "Unsichere Verbindung"), ].iter().cloned().collect(); } diff --git a/src/lang/eo.rs b/src/lang/eo.rs index 211e6728d..fe12e2d24 100644 --- a/src/lang/eo.rs +++ b/src/lang/eo.rs @@ -313,5 +313,9 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Scroll Style", "Ruluma Stilo"), ("Show Menubar", "Montru menubreton"), ("Hide Menubar", "kaŝi menubreton"), + ("Direct Connection", "Rekta Konekto"), + ("Relay Connection", "Relajsa Konekto"), + ("Secure Connection", "Sekura Konekto"), + ("Insecure Connection", "Nesekura Konekto"), ].iter().cloned().collect(); } diff --git a/src/lang/es.rs b/src/lang/es.rs index 068442bf4..313ea8cac 100644 --- a/src/lang/es.rs +++ b/src/lang/es.rs @@ -313,5 +313,9 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Scroll Style", "Estilo de desplazamiento"), ("Show Menubar", "ajustes de pantalla"), ("Hide Menubar", "ocultar barra de menú"), + ("Direct Connection", "Conexión directa"), + ("Relay Connection", "Conexión de relé"), + ("Secure Connection", "Conexión segura"), + ("Insecure Connection", "Conexión insegura"), ].iter().cloned().collect(); } diff --git a/src/lang/fr.rs b/src/lang/fr.rs index d568f050b..c8b12243f 100644 --- a/src/lang/fr.rs +++ b/src/lang/fr.rs @@ -313,5 +313,9 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Scroll Style", "Style de défilement"), ("Show Menubar", "Afficher la barre de menus"), ("Hide Menubar", "masquer la barre de menus"), + ("Direct Connection", "Connexion directe"), + ("Relay Connection", "Connexion relais"), + ("Secure Connection", "Connexion sécurisée"), + ("Insecure Connection", "Connexion non sécurisée"), ].iter().cloned().collect(); } diff --git a/src/lang/hu.rs b/src/lang/hu.rs index 1fe693248..a6356b000 100644 --- a/src/lang/hu.rs +++ b/src/lang/hu.rs @@ -313,5 +313,9 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Scroll Style", "Görgetési stílus"), ("Show Menubar", "Menüsor megjelenítése"), ("Hide Menubar", "menüsor elrejtése"), + ("Direct Connection", "Közvetlen kapcsolat"), + ("Relay Connection", "Relé csatlakozás"), + ("Secure Connection", "Biztonságos kapcsolat"), + ("Insecure Connection", "Nem biztonságos kapcsolat"), ].iter().cloned().collect(); } diff --git a/src/lang/id.rs b/src/lang/id.rs index d5d6ed920..8548eb6bc 100644 --- a/src/lang/id.rs +++ b/src/lang/id.rs @@ -313,5 +313,9 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Scroll Style", "Gaya Gulir"), ("Show Menubar", "Tampilkan bilah menu"), ("Hide Menubar", "sembunyikan bilah menu"), + ("Direct Connection", "Koneksi langsung"), + ("Relay Connection", "Koneksi Relay"), + ("Secure Connection", "Koneksi aman"), + ("Insecure Connection", "Koneksi Tidak Aman"), ].iter().cloned().collect(); } diff --git a/src/lang/it.rs b/src/lang/it.rs index 26e7d4073..fdf8d27d9 100644 --- a/src/lang/it.rs +++ b/src/lang/it.rs @@ -312,5 +312,9 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Scroll Style", "Stile di scorrimento"), ("Show Menubar", "Mostra la barra dei menu"), ("Hide Menubar", "nascondi la barra dei menu"), + ("Direct Connection", "Connessione diretta"), + ("Relay Connection", "Collegamento a relè"), + ("Secure Connection", "Connessione sicura"), + ("Insecure Connection", "Connessione insicura"), ].iter().cloned().collect(); } diff --git a/src/lang/ja.rs b/src/lang/ja.rs index f1331b01d..1d031f2f2 100644 --- a/src/lang/ja.rs +++ b/src/lang/ja.rs @@ -310,5 +310,9 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Scroll Style", "スクロール スタイル"), ("Show Menubar", "メニューバーを表示"), ("Hide Menubar", "メニューバーを隠す"), + ("Direct Connection", "直接接続"), + ("Relay Connection", "リレー接続"), + ("Secure Connection", "安全な接続"), + ("Insecure Connection", "安全でない接続"), ].iter().cloned().collect(); } diff --git a/src/lang/ko.rs b/src/lang/ko.rs index 7a0d8dbdf..19d4c7ddf 100644 --- a/src/lang/ko.rs +++ b/src/lang/ko.rs @@ -310,5 +310,9 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Scroll Style", "스크롤 스타일"), ("Show Menubar", "메뉴 표시줄 표시"), ("Hide Menubar", "메뉴 표시줄 숨기기"), + ("Direct Connection", "직접 연결"), + ("Relay Connection", "릴레이 연결"), + ("Secure Connection", "보안 연결"), + ("Insecure Connection", "안전하지 않은 연결"), ].iter().cloned().collect(); } \ No newline at end of file diff --git a/src/lang/pl.rs b/src/lang/pl.rs index 6f6326121..251c349a2 100644 --- a/src/lang/pl.rs +++ b/src/lang/pl.rs @@ -314,5 +314,9 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Scroll Style", "Styl przewijania"), ("Show Menubar", "Pokaż pasek menu"), ("Hide Menubar", "ukryj pasek menu"), + ("Direct Connection", "Bezpośrednie połączenie"), + ("Relay Connection", "Połączenie przekaźnika"), + ("Secure Connection", "Bezpieczne połączenie"), + ("Insecure Connection", "Niepewne połączenie"), ].iter().cloned().collect(); } diff --git a/src/lang/pt_PT.rs b/src/lang/pt_PT.rs index 2df6c63dc..fd4384767 100644 --- a/src/lang/pt_PT.rs +++ b/src/lang/pt_PT.rs @@ -310,5 +310,9 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Scroll Style", "Estilo de rolagem"), ("Show Menubar", "Mostrar barra de menus"), ("Hide Menubar", "ocultar barra de menu"), + ("Direct Connection", "Conexão direta"), + ("Relay Connection", "Conexão de relé"), + ("Secure Connection", "Conexão segura"), + ("Insecure Connection", "Conexão insegura"), ].iter().cloned().collect(); } diff --git a/src/lang/ptbr.rs b/src/lang/ptbr.rs index a0981f867..85eda60e6 100644 --- a/src/lang/ptbr.rs +++ b/src/lang/ptbr.rs @@ -313,5 +313,9 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Scroll Style", ""), ("Show Menubar", ""), ("Hide Menubar", ""), + ("Direct Connection", ""), + ("Relay Connection", ""), + ("Secure Connection", ""), + ("Insecure Connection", ""), ].iter().cloned().collect(); } diff --git a/src/lang/ru.rs b/src/lang/ru.rs index eed658dfd..def560217 100644 --- a/src/lang/ru.rs +++ b/src/lang/ru.rs @@ -313,5 +313,9 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Scroll Style", "Стиль прокрутки"), ("Show Menubar", "Показать строку меню"), ("Hide Menubar", "скрыть строку меню"), + ("Direct Connection", "Прямая связь"), + ("Relay Connection", "Релейное соединение"), + ("Secure Connection", "Безопасное соединение"), + ("Insecure Connection", "Небезопасное соединение"), ].iter().cloned().collect(); } diff --git a/src/lang/sk.rs b/src/lang/sk.rs index b4e61e83f..4c04618aa 100644 --- a/src/lang/sk.rs +++ b/src/lang/sk.rs @@ -313,5 +313,9 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Scroll Style", "Štýl posúvania"), ("Show Menubar", "Zobraziť panel s ponukami"), ("Hide Menubar", "skryť panel s ponukami"), + ("Direct Connection", "Priame pripojenie"), + ("Relay Connection", "Reléové pripojenie"), + ("Secure Connection", "Zabezpečené pripojenie"), + ("Insecure Connection", "Nezabezpečené pripojenie"), ].iter().cloned().collect(); } diff --git a/src/lang/template.rs b/src/lang/template.rs index 2e5c67cd8..081b7bf55 100644 --- a/src/lang/template.rs +++ b/src/lang/template.rs @@ -313,5 +313,9 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Scroll Style", ""), ("Show Menubar", ""), ("Hide Menubar", ""), + ("Direct Connection", ""), + ("Relay Connection", ""), + ("Secure Connection", ""), + ("Insecure Connection", ""), ].iter().cloned().collect(); } diff --git a/src/lang/tr.rs b/src/lang/tr.rs index 829659954..9738ed469 100644 --- a/src/lang/tr.rs +++ b/src/lang/tr.rs @@ -313,5 +313,9 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Scroll Style", "Kaydırma Stili"), ("Show Menubar", "Menü çubuğunu göster"), ("Hide Menubar", "menü çubuğunu gizle"), + ("Direct Connection", "Doğrudan Bağlantı"), + ("Relay Connection", "Röle Bağlantısı"), + ("Secure Connection", "Güvenli bağlantı"), + ("Insecure Connection", "Güvenli Bağlantı"), ].iter().cloned().collect(); } diff --git a/src/lang/tw.rs b/src/lang/tw.rs index f7d7cbe1d..46276dd2a 100644 --- a/src/lang/tw.rs +++ b/src/lang/tw.rs @@ -313,5 +313,9 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Scroll Style", "滾動樣式"), ("Show Menubar", "顯示菜單欄"), ("Hide Menubar", "隱藏菜單欄"), + ("Direct Connection", "直接連接"), + ("Relay Connection", "中繼連接"), + ("Secure Connection", "安全連接"), + ("Insecure Connection", "非安全連接"), ].iter().cloned().collect(); } diff --git a/src/lang/vn.rs b/src/lang/vn.rs index 1c77139b3..474e57337 100644 --- a/src/lang/vn.rs +++ b/src/lang/vn.rs @@ -313,5 +313,9 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Scroll Style", "Kiểu cuộn"), ("Show Menubar", "Hiển thị thanh menu"), ("Hide Menubar", "ẩn thanh menu"), + ("Direct Connection", "Kết nối trực tiếp"), + ("Relay Connection", "Kết nối chuyển tiếp"), + ("Secure Connection", "Kết nối an toàn"), + ("Insecure Connection", "Kết nối không an toàn"), ].iter().cloned().collect(); }