remove calling refreshCurrentUser when connect status become ready (#8849)
When refreshCurrentUser throw error, show check network in ab and group tab. Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
parent
9750e1409c
commit
7e8d3bd2ac
@ -3490,3 +3490,20 @@ disableWindowMovable(int? windowId) {
|
||||
WindowController.fromWindowId(windowId).setMovable(false);
|
||||
}
|
||||
}
|
||||
|
||||
Widget netWorkErrorWidget() {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Text(translate("network_error_tip")),
|
||||
ElevatedButton(
|
||||
onPressed: gFFI.userModel.refreshCurrentUser,
|
||||
child: Text(translate("Retry")))
|
||||
.marginSymmetric(vertical: 16),
|
||||
Text(gFFI.userModel.networkError.value,
|
||||
style: TextStyle(fontSize: 11, color: Colors.red)),
|
||||
],
|
||||
));
|
||||
}
|
||||
|
@ -41,6 +41,8 @@ class _AddressBookState extends State<AddressBook> {
|
||||
return Center(
|
||||
child: ElevatedButton(
|
||||
onPressed: loginDialog, child: Text(translate("Login"))));
|
||||
} else if (gFFI.userModel.networkError.isNotEmpty) {
|
||||
return netWorkErrorWidget();
|
||||
} else {
|
||||
return Column(
|
||||
children: [
|
||||
|
@ -30,6 +30,8 @@ class _MyGroupState extends State<MyGroup> {
|
||||
return Center(
|
||||
child: ElevatedButton(
|
||||
onPressed: loginDialog, child: Text(translate("Login"))));
|
||||
} else if (gFFI.userModel.networkError.isNotEmpty) {
|
||||
return netWorkErrorWidget();
|
||||
} else if (gFFI.groupModel.groupLoading.value && gFFI.groupModel.emtpy) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
|
@ -34,7 +34,6 @@ class _OnlineStatusWidgetState extends State<OnlineStatusWidget> {
|
||||
final _svcStopped = Get.find<RxBool>(tag: 'stop-service');
|
||||
final _svcIsUsingPublicServer = true.obs;
|
||||
Timer? _updateTimer;
|
||||
final DateTime _appStartTime = DateTime.now();
|
||||
|
||||
double get em => 14.0;
|
||||
double? get height => bind.isIncomingOnly() ? null : em * 3;
|
||||
@ -170,17 +169,12 @@ class _OnlineStatusWidgetState extends State<OnlineStatusWidget> {
|
||||
final status =
|
||||
jsonDecode(await bind.mainGetConnectStatus()) as Map<String, dynamic>;
|
||||
final statusNum = status['status_num'] as int;
|
||||
final preStatus = stateGlobal.svcStatus.value;
|
||||
if (statusNum == 0) {
|
||||
stateGlobal.svcStatus.value = SvcStatus.connecting;
|
||||
} else if (statusNum == -1) {
|
||||
stateGlobal.svcStatus.value = SvcStatus.notReady;
|
||||
} else if (statusNum == 1) {
|
||||
stateGlobal.svcStatus.value = SvcStatus.ready;
|
||||
if (preStatus != SvcStatus.ready &&
|
||||
DateTime.now().difference(_appStartTime) > Duration(seconds: 5)) {
|
||||
gFFI.userModel.refreshCurrentUser();
|
||||
}
|
||||
} else {
|
||||
stateGlobal.svcStatus.value = SvcStatus.notReady;
|
||||
}
|
||||
|
@ -112,6 +112,7 @@ class AbModel {
|
||||
{required ForcePullAb? force, required bool quiet}) async {
|
||||
if (bind.isDisableAb()) return;
|
||||
if (!gFFI.userModel.isLogin) return;
|
||||
if (gFFI.userModel.networkError.isNotEmpty) return;
|
||||
if (force == null && listInitialized && current.initialized) return;
|
||||
debugPrint("pullAb, force: $force, quiet: $quiet");
|
||||
if (!listInitialized || force == ForcePullAb.listAndCurrent) {
|
||||
|
@ -28,6 +28,7 @@ class GroupModel {
|
||||
Future<void> pull({force = true, quiet = false}) async {
|
||||
if (bind.isDisableGroupPanel()) return;
|
||||
if (!gFFI.userModel.isLogin || groupLoading.value) return;
|
||||
if (gFFI.userModel.networkError.isNotEmpty) return;
|
||||
if (!force && initialized) return;
|
||||
if (!quiet) {
|
||||
groupLoading.value = true;
|
||||
|
@ -17,13 +17,23 @@ bool refreshingUser = false;
|
||||
class UserModel {
|
||||
final RxString userName = ''.obs;
|
||||
final RxBool isAdmin = false.obs;
|
||||
final RxString networkError = ''.obs;
|
||||
bool get isLogin => userName.isNotEmpty;
|
||||
WeakReference<FFI> parent;
|
||||
|
||||
UserModel(this.parent);
|
||||
UserModel(this.parent) {
|
||||
userName.listen((p0) {
|
||||
// When user name becomes empty, show login button
|
||||
// When user name becomes non-empty:
|
||||
// For _updateLocalUserInfo, network error will be set later
|
||||
// For login success, should clear network error
|
||||
networkError.value = '';
|
||||
});
|
||||
}
|
||||
|
||||
void refreshCurrentUser() async {
|
||||
if (bind.isDisableAccount()) return;
|
||||
networkError.value = '';
|
||||
final token = bind.mainGetLocalOption(key: 'access_token');
|
||||
if (token == '') {
|
||||
await updateOtherModels();
|
||||
@ -38,12 +48,18 @@ class UserModel {
|
||||
if (refreshingUser) return;
|
||||
try {
|
||||
refreshingUser = true;
|
||||
final response = await http.post(Uri.parse('$url/api/currentUser'),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer $token'
|
||||
},
|
||||
body: json.encode(body));
|
||||
final http.Response response;
|
||||
try {
|
||||
response = await http.post(Uri.parse('$url/api/currentUser'),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer $token'
|
||||
},
|
||||
body: json.encode(body));
|
||||
} catch (e) {
|
||||
networkError.value = e.toString();
|
||||
rethrow;
|
||||
}
|
||||
refreshingUser = false;
|
||||
final status = response.statusCode;
|
||||
if (status == 401 || status == 400) {
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", ""),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", ""),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", ""),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", ""),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", "确定要取消 Telegram 机器人吗?"),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", "请检查网络连接, 然后点击再试"),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", "Jste si jisti, že chcete zrušit bota Telegramu?"),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", ""),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", "Sind Sie sicher, dass Sie Telegram-Bot abbrechen möchten?"),
|
||||
("About RustDesk", "Über RustDesk"),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", "Είστε βέβαιοι ότι θέλετε να ακυρώσετε το Telegram bot;"),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -232,5 +232,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-2fa-confirm-tip", "Are you sure you want to cancel 2FA?"),
|
||||
("cancel-bot-confirm-tip", "Are you sure you want to cancel Telegram bot?"),
|
||||
("About RustDesk", ""),
|
||||
("network_error_tip", "Please check your network connection, then click retry.")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", ""),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", "¿Seguro que quieres cancelar el bot de Telegram?"),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", ""),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", ""),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", ""),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", ""),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", ""),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", ""),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", ""),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", ""),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", "Sei sicuro di voler annulare Telegram?"),
|
||||
("About RustDesk", "Info su RustDesk"),
|
||||
("Send clipboard keystrokes", "Invia sequenze tasti appunti"),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", "本当にTelegram Botをキャンセルしますか?"),
|
||||
("About RustDesk", "RustDeskについて"),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", ""),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", ""),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", ""),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", "Vai tiešām vēlaties atcelt Telegram robotu?"),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", ""),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", "Weet je zeker dat je de Telegram-bot wilt annuleren?"),
|
||||
("About RustDesk", "Over RustDesk"),
|
||||
("Send clipboard keystrokes", "Klembord toetsaanslagen verzenden"),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", ""),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", ""),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", ""),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", ""),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", "Отключить Telegram-бота?"),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", "Ste si istí, že chcete zrušiť bota Telegramu?"),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", ""),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", ""),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", ""),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", ""),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", ""),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", ""),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", ""),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", "確定要取消 Telegram 機器人嗎?"),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", ""),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -631,5 +631,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-bot-confirm-tip", ""),
|
||||
("About RustDesk", ""),
|
||||
("Send clipboard keystrokes", ""),
|
||||
("network_error_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user