mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-12-12 11:06:57 +00:00
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user