From ca19246f301c674310083d891e390ab646b487cf Mon Sep 17 00:00:00 2001 From: 21pages Date: Sun, 18 Jun 2023 13:53:03 +0800 Subject: [PATCH] decode json with utf8 from names and show account info Signed-off-by: 21pages --- .../desktop/pages/desktop_setting_page.dart | 22 ++++++++++++++++++- flutter/lib/models/group_model.dart | 6 ++--- flutter/lib/models/user_model.dart | 4 ++-- src/lang/it.rs | 2 -- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/flutter/lib/desktop/pages/desktop_setting_page.dart b/flutter/lib/desktop/pages/desktop_setting_page.dart index a346548b2..578b63b20 100644 --- a/flutter/lib/desktop/pages/desktop_setting_page.dart +++ b/flutter/lib/desktop/pages/desktop_setting_page.dart @@ -1369,7 +1369,7 @@ class _AccountState extends State<_Account> { physics: DraggableNeverScrollableScrollPhysics(), controller: scrollController, children: [ - _Card(title: 'Account', children: [accountAction()]), + _Card(title: 'Account', children: [accountAction(), useInfo()]), ], ).marginOnly(bottom: _kListViewBottomMargin)); } @@ -1383,6 +1383,26 @@ class _AccountState extends State<_Account> { : gFFI.userModel.logOut() })); } + + Widget useInfo() { + text(String key, String value) { + return Align( + alignment: Alignment.centerLeft, + child: SelectionArea(child: Text('${translate(key)}: $value')) + .marginSymmetric(vertical: 4), + ); + } + + return Obx(() => Offstage( + offstage: gFFI.userModel.userName.value.isEmpty, + child: Column( + children: [ + text('Username', gFFI.userModel.userName.value), + text('Group', gFFI.groupModel.groupName.value), + ], + ), + )).marginOnly(left: 18, top: 16); + } } class _Checkbox extends StatefulWidget { diff --git a/flutter/lib/models/group_model.dart b/flutter/lib/models/group_model.dart index c7164c42d..5573d7361 100644 --- a/flutter/lib/models/group_model.dart +++ b/flutter/lib/models/group_model.dart @@ -76,7 +76,7 @@ class GroupModel { }); final resp = await http.get(uri, headers: getHttpHeaders()); if (resp.body.isNotEmpty && resp.body.toLowerCase() != "null") { - Map json = jsonDecode(resp.body); + Map json = jsonDecode(utf8.decode(resp.bodyBytes)); if (json.containsKey('error')) { throw json['error']; } else { @@ -119,7 +119,7 @@ class GroupModel { if (status == 401 || status == 400) { return false; } - final data = json.decode(response.body); + final data = json.decode(utf8.decode(response.bodyBytes)); final error = data['error']; if (error != null) { throw error; @@ -159,7 +159,7 @@ class GroupModel { }); final resp = await http.get(uri, headers: getHttpHeaders()); if (resp.body.isNotEmpty && resp.body.toLowerCase() != "null") { - Map json = jsonDecode(resp.body); + Map json = jsonDecode(utf8.decode(resp.bodyBytes)); if (json.containsKey('error')) { throw json['error']; } else { diff --git a/flutter/lib/models/user_model.dart b/flutter/lib/models/user_model.dart index e7159a4de..bbb805826 100644 --- a/flutter/lib/models/user_model.dart +++ b/flutter/lib/models/user_model.dart @@ -41,7 +41,7 @@ class UserModel { reset(); return; } - final data = json.decode(response.body); + final data = json.decode(utf8.decode(response.bodyBytes)); final error = data['error']; if (error != null) { throw error; @@ -105,7 +105,7 @@ class UserModel { final Map body; try { - body = jsonDecode(resp.body); + body = jsonDecode(utf8.decode(resp.bodyBytes)); } catch (e) { print("login: jsonDecode resp body failed: ${e.toString()}"); rethrow; diff --git a/src/lang/it.rs b/src/lang/it.rs index 0d0c22ecb..5007459e7 100644 --- a/src/lang/it.rs +++ b/src/lang/it.rs @@ -509,8 +509,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("resolution_fit_local_tip", "Adatta risoluzione locale"), ("resolution_custom_tip", "Risoluzione personalizzata"), ("Collapse toolbar", "Comprimi barra strumenti"), - ("Accept and Elevate", ""), - ("accept_and_elevate_btn_tooltip", ""), ("Accept and Elevate", "Accetta ed eleva"), ("accept_and_elevate_btn_tooltip", "Accetta la connessione ed eleva le autorizzazioni UAC."), ].iter().cloned().collect();