Skip to content

Commit 8065b6c

Browse files
Update UI from main thread
1 parent 9caa881 commit 8065b6c

2 files changed

Lines changed: 18 additions & 11 deletions

File tree

AppBox/ViewController/HomeViewController/HomeViewController.m

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,13 @@ - (void)viewWillAppear{
7575
[self performSegueWithIdentifier:@"DropBoxLogin" sender:self];
7676
} else {
7777
[[[DBClientsManager authorizedClient].usersRoutes getCurrentAccount] setResponseBlock:^(DBUSERSFullAccount * _Nullable result, DBNilObject * _Nullable routeError, DBRequestError * _Nullable networkError) {
78-
if (result) {
79-
[[Common currentDBManager] registerUserId:result.email];
80-
} else if (networkError.tag == DBRequestErrorAuth) {
81-
[[NSNotificationCenter defaultCenter] postNotificationName:abDropBoxLoggedOutNotification object:self];
82-
}
78+
dispatch_async(dispatch_get_main_queue(), ^{
79+
if (result) {
80+
[[Common currentDBManager] registerUserId:result.email];
81+
} else if (networkError.tag == DBRequestErrorAuth) {
82+
[[NSNotificationCenter defaultCenter] postNotificationName:abDropBoxLoggedOutNotification object:self];
83+
}
84+
});
8385
}];
8486
}
8587
[[AppDelegate appDelegate] setIsReadyToUpload:YES];

AppBox/ViewController/MenuHandler/NSApplication+MenuHandler.m

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ - (void)updateAccountsMenu{
4141
@try {
4242
[UserData setLoggedInUserEmail:result.email];
4343
[UserData setLoggedInUserDisplayName:result.name.displayName];
44-
[self updateDropboxButton];
44+
dispatch_async(dispatch_get_main_queue(), ^{
45+
[self updateDropboxButton];
46+
});
4547
} @catch (NSException *exception) {
4648
DDLogError(@"Exception %@",exception.abDescription);
4749
}
@@ -59,16 +61,19 @@ - (void)updateAccountsMenu{
5961
//save space usage in user default
6062
[UserData setDropboxUsedSpace:usage];
6163
[UserData setDropboxAvailableSpace:allocated];
62-
[self updateDropboxButton];
6364

6465
//log space usage
6566
DDLogInfo(@"DropBox Used Space : %@MB", usage);
6667
DDLogInfo(@"DropBox Available Space : %@MB", allocated);
6768

68-
//check if dopbox running out of space
69-
if ((allocated.integerValue - usage.integerValue) < abDropboxOutOfSpaceWarningSize){
70-
[Common showAlertWithTitle:@"Warning" andMessage:[NSString stringWithFormat:@"You're running out of Dropbox space\n\n %@MB of %@MB used.", usage, allocated]];
71-
}
69+
dispatch_async(dispatch_get_main_queue(), ^{
70+
[self updateDropboxButton];
71+
72+
//check if dopbox running out of space
73+
if ((allocated.integerValue - usage.integerValue) < abDropboxOutOfSpaceWarningSize){
74+
[Common showAlertWithTitle:@"Warning" andMessage:[NSString stringWithFormat:@"You're running out of Dropbox space\n\n %@MB of %@MB used.", usage, allocated]];
75+
}
76+
});
7277
} @catch (NSException *exception) {
7378
DDLogError(@"Exception %@",exception.abDescription);
7479
}

0 commit comments

Comments
 (0)