From e18aea724978b86cb0c04853649aeb613ac225ce Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Sat, 29 May 2021 22:14:38 -0400 Subject: [PATCH] version checks for features not present in 10.11 --- Ample/AppDelegate.m | 11 ++++++-- Ample/AutocompleteControl.m | 7 +++-- Ample/Base.lproj/LaunchWindow.xib | 1 - Ample/DiskImagesWindowController.m | 24 +++++++++++++--- Ample/LogWindowController.m | 45 ++++++++++++++++++++++++------ 5 files changed, 69 insertions(+), 19 deletions(-) diff --git a/Ample/AppDelegate.m b/Ample/AppDelegate.m index 22c94bc..518f876 100644 --- a/Ample/AppDelegate.m +++ b/Ample/AppDelegate.m @@ -96,10 +96,15 @@ @"xfz", path ]; - [task setExecutableURL: [NSURL fileURLWithPath: @"/usr/bin/tar"]]; + if (@available(macOS 10.13, *)) { + [task setExecutableURL: [NSURL fileURLWithPath: @"/usr/bin/tar"]]; + [task setCurrentDirectoryURL: sd]; + } else { + [task setLaunchPath: @"/usr/bin/tar"]; + [task setCurrentDirectoryPath: SupportDirectoryPath()]; + } [task setArguments: argv]; - [task setCurrentDirectoryURL: sd]; - + dispatch_time_t when = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)); [task setTerminationHandler: ^(NSTask *task){ diff --git a/Ample/AutocompleteControl.m b/Ample/AutocompleteControl.m index b54876f..4bc23ae 100644 --- a/Ample/AutocompleteControl.m +++ b/Ample/AutocompleteControl.m @@ -411,8 +411,11 @@ Todo -- -(void)_init { _backgroundColor = [NSColor windowBackgroundColor]; - _selectedColor = [NSColor selectedContentBackgroundColor]; - + if (@available(macOS 10.14, *)) { + _selectedColor = [NSColor selectedContentBackgroundColor]; + } else { + _selectedColor = [NSColor selectedTextBackgroundColor]; + } NSTrackingAreaOptions options = NSTrackingMouseMoved | NSTrackingMouseEnteredAndExited | NSTrackingInVisibleRect | NSTrackingActiveInActiveApp; _trackingArea = [[NSTrackingArea alloc] initWithRect: NSZeroRect options: options diff --git a/Ample/Base.lproj/LaunchWindow.xib b/Ample/Base.lproj/LaunchWindow.xib index 5299d12..5cdd854 100644 --- a/Ample/Base.lproj/LaunchWindow.xib +++ b/Ample/Base.lproj/LaunchWindow.xib @@ -1,7 +1,6 @@ - diff --git a/Ample/DiskImagesWindowController.m b/Ample/DiskImagesWindowController.m index 3ac659b..fbd4ff3 100644 --- a/Ample/DiskImagesWindowController.m +++ b/Ample/DiskImagesWindowController.m @@ -67,8 +67,11 @@ [window setRestorable: YES]; [window setRestorationClass: [self class]]; - - [_tableView registerForDraggedTypes: @[NSPasteboardTypeFileURL]]; + if (@available(macOS 10.13, *)) { + [_tableView registerForDraggedTypes: @[NSPasteboardTypeFileURL]]; + } else { + [_tableView registerForDraggedTypes: @[NSURLPboardType]]; + } [_tableView setDraggingSourceOperationMask: NSDragOperationCopy forLocal: NO]; // enable drag/drop to othr apps. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file. @@ -95,6 +98,11 @@ [nc addObserver: self selector: @selector(willTerminate:) name: NSApplicationWillTerminateNotification object: nil]; } +-(void)timerCallback: (NSTimer *)timer { + _timer = nil; + [self saveFile]; +} + -(void)diskImageAdded: (NSNotification *)notification { NSURL *url = [notification object]; @@ -105,11 +113,15 @@ -(void)markDirty { _dirty = YES; if (_timer) [_timer invalidate]; + _timer = [NSTimer scheduledTimerWithTimeInterval: 5 * 60 target: self selector: @selector(timerCallback:) userInfo: nil repeats: NO]; +#if 0 + // 10.12+ _timer = [NSTimer scheduledTimerWithTimeInterval: 5 * 60 repeats: NO block: ^(NSTimer *t) { self->_timer = nil; [self saveFile]; }]; +#endif } -(void)saveFile { @@ -306,11 +318,15 @@ for (NSPasteboardItem *item in [pb pasteboardItems]) { // need to convert from a string to a url back to a file in case it's a file id url? - NSString *s = [item stringForType: NSPasteboardTypeFileURL]; + NSString *s; + if (@available(macOS 10.13, *)) { + s = [item stringForType: NSPasteboardTypeFileURL]; + } else { + s = [item stringForType: NSURLPboardType]; + } if (!s) continue; NSURL *url = [NSURL URLWithString: s]; if (!url) continue; - ok |= [self addFile: url]; } return ok; diff --git a/Ample/LogWindowController.m b/Ample/LogWindowController.m index d73d307..d7d53d5 100644 --- a/Ample/LogWindowController.m +++ b/Ample/LogWindowController.m @@ -53,9 +53,16 @@ static NSMutableSet *LogWindows; } NSTask *task = [NSTask new]; - [task setExecutableURL: url]; + + if (@available(macOS 10.13, *)) { + [task setExecutableURL: url]; + [task setCurrentDirectoryURL: MameWorkingDirectory()]; + } else { + [task setLaunchPath: MamePath()]; + [task setCurrentDirectoryPath: MameWorkingDirectoryPath()]; + } + [task setArguments: args]; - [task setCurrentDirectoryURL: MameWorkingDirectory()]; return [LogWindowController controllerForTask: task]; } @@ -84,20 +91,39 @@ static NSMutableSet *LogWindows; if (_task) return nil; - NSError *error = nil; NSPipe *pipe = [NSPipe pipe]; // window not yet loaded until [self window] called. - const char *path = [[task executableURL] fileSystemRepresentation]; -// if (cp) [self appendString: [NSString stringWithFormat: @"MAME path: %s", cp]]; - const char *wd = [[task currentDirectoryURL] fileSystemRepresentation]; -// if (cp) [self appendString: [NSString stringWithFormat: @"Working Directory: %s", cp]]; + + const char *path = nil; + const char *wd = nil; + [task setStandardError: pipe]; [task setStandardOutput: pipe]; - [task launchAndReturnError: &error]; - + if (@available(macOS 10.13, *)) { + NSError *error = nil; + path = [[task executableURL] fileSystemRepresentation]; + wd = [[task currentDirectoryURL] fileSystemRepresentation]; + [task launchAndReturnError: &error]; + if (error) { + NSLog(@"NSTask error. Path = %s error = %@", path, error); + } + return error; + } else { + path = [[task launchPath] fileSystemRepresentation]; + wd = [[task currentDirectoryPath] fileSystemRepresentation]; + @try { + [task launch]; + } @catch (NSException *exception) { + + NSLog(@"NSTask exception. Path = %s exception = %@", path, exception); + return nil; // ? + } + } + +#if 0 if (error) { // NSURL *url = [task executableURL]; // NSString *path = [NSString stringWithCString: [url fileSystemRepresentation] encoding: NSUTF8StringEncoding]; @@ -106,6 +132,7 @@ static NSMutableSet *LogWindows; // [self appendString: [error description]]; return error; } +#endif _task = task; NSString *title = [NSString stringWithFormat: @"Ample Log - %u", [task processIdentifier]]; [[self window] setTitle: title];