version checks for features not present in 10.11

This commit is contained in:
Kelvin Sherlock 2021-05-29 22:14:38 -04:00
parent 07dcf30f52
commit e18aea7249
5 changed files with 69 additions and 19 deletions

View File

@ -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){

View File

@ -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

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="15705" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15705"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>

View File

@ -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;

View File

@ -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];