From 87072398916b3d5cef15a7056337130caad96027 Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Sat, 2 May 2015 15:35:06 +0200 Subject: [PATCH] Fix a hang when opening a dragged file. --- Classes/SBAppDelegate.m | 6 ++++-- Classes/SBDocument.m | 14 ++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Classes/SBAppDelegate.m b/Classes/SBAppDelegate.m index 72622e2..a92aa3b 100755 --- a/Classes/SBAppDelegate.m +++ b/Classes/SBAppDelegate.m @@ -185,13 +185,15 @@ } - (id)openDocumentWithContentsOfURL:(NSURL *)absoluteURL display:(BOOL)displayDocument error:(NSError **)outError { - SBDocument *doc = nil; + __block SBDocument *doc = nil; if ([[[absoluteURL path] pathExtension] caseInsensitiveCompare: @"mkv"] == NSOrderedSame || [[[absoluteURL path] pathExtension] caseInsensitiveCompare: @"mka"] == NSOrderedSame || [[[absoluteURL path] pathExtension] caseInsensitiveCompare: @"mks"] == NSOrderedSame || [[[absoluteURL path] pathExtension] caseInsensitiveCompare: @"mov"] == NSOrderedSame) { - doc = [self openUntitledDocumentAndDisplay:displayDocument error:outError]; + dispatch_sync(dispatch_get_main_queue(), ^{ + doc = [self openUntitledDocumentAndDisplay:displayDocument error:outError]; + }); [doc performSelectorOnMainThread:@selector(showImportSheet:) withObject:[NSArray arrayWithObject:absoluteURL] waitUntilDone:NO]; return doc; } diff --git a/Classes/SBDocument.m b/Classes/SBDocument.m index 4ed38b9..cdc495c 100755 --- a/Classes/SBDocument.m +++ b/Classes/SBDocument.m @@ -73,10 +73,11 @@ return nil; } -- (id)initWithType:(NSString *)typeName error:(NSError **)outError +- (instancetype)initWithType:(NSString *)typeName error:(NSError **)outError { - if (self = [super initWithType:typeName error:outError]) + if (self = [super initWithType:typeName error:outError]) { self.mp4 = [[[MP42File alloc] initWithDelegate:self] autorelease]; + } return self; } @@ -177,8 +178,6 @@ - (BOOL)writeSafelyToURL:(NSURL *)absoluteURL ofType:(NSString *)typeName forSaveOperation:(NSSaveOperationType)saveOperation error:(NSError **)outError; { - NSError *inError = nil; - NSMutableDictionary * attributes = [[NSMutableDictionary alloc] init]; if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"chaptersPreviewTrack"] boolValue]) [attributes setObject:@YES forKey:MP42GenerateChaptersPreviewTrack]; @@ -201,6 +200,7 @@ IOReturn io_success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, reasonForActivity, &assertionID); BOOL success = NO; + NSError *inError = nil; switch (saveOperation) { case NSSaveOperation: @@ -218,6 +218,8 @@ break; } + [attributes release]; + if (success && _optimize) { dispatch_async(dispatch_get_main_queue(), ^{ [saveOperationName setStringValue:@"Optimizing…"]; @@ -226,13 +228,10 @@ _optimize = NO; } - if (io_success == kIOReturnSuccess) { IOPMAssertionRelease(assertionID); } - [attributes release]; - dispatch_async(dispatch_get_main_queue(), ^{ [self saveDidComplete:inError URL:absoluteURL]; }); @@ -965,4 +964,3 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn } @end -