Fixed an hang when opening a document while one was being saved
This commit is contained in:
1 parent
d0ed7de340
commit
f53f64e262
3 files changed
+47
-33
No files matched your search
+30
-12
@@ -142,6 +142,7 @@
|
||||
|
||||
- (IBAction)openInQueue:(id)sender
|
||||
{
|
||||
[[SBQueueController sharedManager] showWindow:self];
|
||||
[[SBQueueController sharedManager] open:sender];
|
||||
}
|
||||
|
||||
@@ -184,27 +185,44 @@
|
||||
|
||||
@implementation SBDocumentController
|
||||
|
||||
- (id) init
|
||||
- (instancetype)init
|
||||
{
|
||||
return [super init];
|
||||
}
|
||||
|
||||
- (id)openDocumentWithContentsOfURL:(NSURL *)absoluteURL display:(BOOL)displayDocument error:(NSError **)outError {
|
||||
__block SBDocument *doc = nil;
|
||||
- (void)openDocumentWithContentsOfURL:(NSURL * _Nonnull)url
|
||||
display:(BOOL)displayDocument
|
||||
completionHandler:(void (^ _Nonnull)(NSDocument * _Nullable document,
|
||||
BOOL documentWasAlreadyOpen,
|
||||
NSError * _Nullable error))completionHandler
|
||||
{
|
||||
NSString *extension = url.pathExtension;
|
||||
if ([extension caseInsensitiveCompare: @"mkv"] == NSOrderedSame ||
|
||||
[extension caseInsensitiveCompare: @"mka"] == NSOrderedSame ||
|
||||
[extension caseInsensitiveCompare: @"mks"] == NSOrderedSame ||
|
||||
[extension caseInsensitiveCompare: @"mov"] == NSOrderedSame) {
|
||||
|
||||
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) {
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||
doc = [self openUntitledDocumentAndDisplay:displayDocument error:outError];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
NSError *outError;
|
||||
|
||||
SBDocument *doc = [self openUntitledDocumentAndDisplay:displayDocument error:&outError];
|
||||
[doc performSelectorOnMainThread:@selector(showImportSheet:) withObject:[NSArray arrayWithObject:url] waitUntilDone:NO];
|
||||
});
|
||||
[doc performSelectorOnMainThread:@selector(showImportSheet:) withObject:[NSArray arrayWithObject:absoluteURL] waitUntilDone:NO];
|
||||
return doc;
|
||||
|
||||
}
|
||||
else {
|
||||
return [super openDocumentWithContentsOfURL:absoluteURL display:displayDocument error:outError];
|
||||
[super openDocumentWithContentsOfURL:url display:displayDocument completionHandler:completionHandler];
|
||||
}
|
||||
}
|
||||
|
||||
- (nullable __kindof NSDocument *)documentForURL:(NSURL *)url
|
||||
{
|
||||
for (NSDocument *doc in self.documents) {
|
||||
if ([doc.fileURL isEqualTo:url.filePathURL]) {
|
||||
return doc;
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
@class MP42File;
|
||||
|
||||
@interface SBDocument : NSDocument <NSTableViewDelegate> {
|
||||
@interface SBDocument : NSDocument {
|
||||
@private
|
||||
MP42File *_mp4File;
|
||||
IBOutlet NSWindow *documentWindow;
|
||||
@@ -71,6 +71,4 @@
|
||||
|
||||
- (void)showImportSheet:(NSArray *)fileURLs;
|
||||
|
||||
- (void)setMp4File:(MP42File *)mp4;
|
||||
|
||||
@end
|
||||
+16
-18
@@ -26,7 +26,7 @@
|
||||
|
||||
#define SublerTableViewDataType @"SublerTableViewDataType"
|
||||
|
||||
@interface SBDocument () <MP42FileDelegate, SBFileImportDelegate, SBMetadataSearchControllerDelegate>
|
||||
@interface SBDocument () <NSTableViewDelegate, MP42FileDelegate, SBFileImportDelegate, SBMetadataSearchControllerDelegate>
|
||||
|
||||
@property (nonatomic, retain) MP42File *mp4;
|
||||
|
||||
@@ -70,7 +70,11 @@
|
||||
|
||||
- (instancetype)initWithMP4:(MP42File *)mp4File error:(NSError **)outError
|
||||
{
|
||||
return nil;
|
||||
if (self = [super initWithType:@"Video-MPEG4" error:outError]) {
|
||||
self.mp4 = mp4File;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithType:(NSString *)typeName error:(NSError **)outError
|
||||
@@ -136,11 +140,6 @@
|
||||
return YES;
|
||||
}
|
||||
|
||||
+ (BOOL)autosavesInPlace
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
#pragma mark Save methods
|
||||
|
||||
- (BOOL)canAsynchronouslyWriteToURL:(NSURL *)url
|
||||
@@ -175,8 +174,12 @@
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)writeSafelyToURL:(NSURL *)absoluteURL ofType:(NSString *)typeName
|
||||
forSaveOperation:(NSSaveOperationType)saveOperation error:(NSError **)outError;
|
||||
- (void)saveToURL:(NSURL *)url ofType:(NSString *)typeName forSaveOperation:(NSSaveOperationType)saveOperation completionHandler:(void (^)(NSError * _Nullable))completionHandler
|
||||
{
|
||||
[super saveToURL:url ofType:typeName forSaveOperation:saveOperation completionHandler:completionHandler];
|
||||
}
|
||||
|
||||
- (BOOL)writeSafelyToURL:(NSURL *)url ofType:(NSString *)typeName forSaveOperation:(NSSaveOperationType)saveOperation error:(NSError * _Nullable *)outError
|
||||
{
|
||||
NSMutableDictionary * attributes = [[NSMutableDictionary alloc] init];
|
||||
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"chaptersPreviewTrack"] boolValue])
|
||||
@@ -184,6 +187,8 @@
|
||||
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"SBOrganizeAlternateGroups"] boolValue])
|
||||
[attributes setObject:@YES forKey:MP42OrganizeAlternateGroups];
|
||||
|
||||
[self unblockUserInteraction];
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[optBar setIndeterminate:YES];
|
||||
[optBar startAnimation:self];
|
||||
@@ -192,7 +197,6 @@
|
||||
modalDelegate:nil didEndSelector:NULL contextInfo:nil];
|
||||
});
|
||||
|
||||
[self unblockUserInteraction];
|
||||
|
||||
IOPMAssertionID assertionID;
|
||||
// Enable sleep assertion
|
||||
@@ -211,7 +215,7 @@
|
||||
case NSSaveAsOperation:
|
||||
if ([_64bit_data state]) [attributes setObject:@YES forKey:MP4264BitData];
|
||||
if ([_64bit_time state]) [attributes setObject:@YES forKey:MP4264BitTime];
|
||||
success = [self.mp4 writeToUrl:absoluteURL withAttributes:attributes error:&inError];
|
||||
success = [self.mp4 writeToUrl:url withAttributes:attributes error:&inError];
|
||||
break;
|
||||
default:
|
||||
NSAssert(NO, @"Unhandled save operation");
|
||||
@@ -233,7 +237,7 @@
|
||||
}
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self saveDidComplete:inError URL:absoluteURL];
|
||||
[self saveDidComplete:inError URL:url];
|
||||
});
|
||||
|
||||
return success;
|
||||
@@ -943,12 +947,6 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)setMp4File:(MP42File *)mp4 {
|
||||
self.mp4 = mp4;
|
||||
[fileTracksTable reloadData];
|
||||
[self tableViewSelectionDidChange:nil];
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[propertyView release];
|
||||
|
||||
Reference in new issue
Block a user