Skip to content

Commit

Permalink
fix plugin install bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nate-parrott committed Nov 4, 2014
1 parent 12a5835 commit 9797d75
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions FlashlightApp/EasySIMBL/PluginListController.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ @interface PluginListController () <NSTableViewDelegate>
@property (nonatomic) dispatch_source_t dispatchSource;
@property (nonatomic) int fileDesc;

@property (nonatomic) BOOL needsReloadFromDisk;
@property (nonatomic) BOOL waitingToReloadFromDisk;

@end

Expand All @@ -33,8 +33,7 @@ - (void)awakeFromNib {
self.arrayController.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"installed" ascending:NO], [NSSortDescriptor sortDescriptorWithKey:@"displayName" ascending:YES]];

[self startWatchingPluginsDir];
self.needsReloadFromDisk = YES;
[self reloadFromDiskIfNeeded];
[self reloadFromDisk];
[self reloadPluginsFromWeb:nil];
}
- (void)dealloc {
Expand Down Expand Up @@ -102,6 +101,10 @@ - (void)updateArrayController {

#pragma mark Local plugin files
- (void)startWatchingPluginsDir {
if (![[NSFileManager defaultManager] fileExistsAtPath:[self localPluginsPath]]) {
[[NSFileManager defaultManager] createDirectoryAtPath:[self localPluginsPath] withIntermediateDirectories:YES attributes:nil error:nil];
}

self.fileDesc = open([[self localPluginsPath] fileSystemRepresentation], O_EVTONLY);

// watch the file descriptor for writes
Expand All @@ -111,10 +114,11 @@ - (void)startWatchingPluginsDir {
__weak PluginListController *weakSelf = self;
dispatch_source_set_event_handler(self.dispatchSource, ^{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ // work around some bug when reloading after install
if (!weakSelf.needsReloadFromDisk) {
weakSelf.needsReloadFromDisk = YES;
if (!weakSelf.waitingToReloadFromDisk) {
weakSelf.waitingToReloadFromDisk = YES;
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf reloadFromDiskIfNeeded];
self.waitingToReloadFromDisk = NO;
[weakSelf reloadFromDisk];
});
}
});
Expand All @@ -133,8 +137,7 @@ - (void)stopWatchingPluginsDir {
dispatch_cancel(self.dispatchSource);
}

- (void)reloadFromDiskIfNeeded {
self.needsReloadFromDisk = NO;
- (void)reloadFromDisk {
NSArray *contents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[self localPluginsPath] error:nil];
NSMutableArray *models = [NSMutableArray new];
for (NSString *itemName in contents) {
Expand Down

0 comments on commit 9797d75

Please sign in to comment.