Skip to content

Commit

Permalink
Fix crash on first run
Browse files Browse the repository at this point in the history
  • Loading branch information
tbodt committed Jun 20, 2020
1 parent 298b0b3 commit 3477407
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/Roots.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ - (instancetype)init {
self.defaultRoot = [NSUserDefaults.standardUserDefaults stringForKey:kDefaultRoot];
[self addObserver:self forKeyPath:@"defaultRoot" options:0 context:nil];
if ((!self.defaultRoot || ![self.roots containsObject:self.defaultRoot]) && self.roots.count)
self.defaultRoot = self.roots[0];
self.defaultRoot = self.roots.firstObject;
}
return self;
}
Expand Down Expand Up @@ -142,9 +142,14 @@ - (BOOL)importRootFromArchive:(NSURL *)archive name:(NSString *)name error:(NSEr
}
if (![NSFileManager.defaultManager moveItemAtURL:tempDestination toURL:destination error:error])
return NO;
dispatch_async(dispatch_get_main_queue(), ^{

void (^addRoot)(void) = ^{
[[self mutableOrderedSetValueForKey:@"roots"] addObject:name];
});
};
if (!NSThread.isMainThread)
dispatch_sync(dispatch_get_main_queue(), addRoot);
else
addRoot();
return YES;
}

Expand Down

0 comments on commit 3477407

Please sign in to comment.