diff --git a/Shuttle.xcodeproj/project.pbxproj b/Shuttle.xcodeproj/project.pbxproj index d174fef..189c124 100644 --- a/Shuttle.xcodeproj/project.pbxproj +++ b/Shuttle.xcodeproj/project.pbxproj @@ -12,6 +12,12 @@ 0ADB3B0E178EF8DB004E9BB9 /* StatusIcon@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 0ADB3B0A178EF8DB004E9BB9 /* StatusIcon@2x.png */; }; 0ADB3B0F178EF8DB004E9BB9 /* StatusIconAlt@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 0ADB3B0B178EF8DB004E9BB9 /* StatusIconAlt@2x.png */; }; 0ADB3B13178F3DE4004E9BB9 /* LaunchAtLoginController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0ADB3B12178F3DE4004E9BB9 /* LaunchAtLoginController.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; + 18F7A8C5224A80AA000CDCA9 /* CoreSpotlight.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 18F7A8C4224A80AA000CDCA9 /* CoreSpotlight.framework */; }; + 18F7A8CC224A8129000CDCA9 /* Quartz.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 18F7A8CB224A8129000CDCA9 /* Quartz.framework */; }; + 18F7A8D0224A8129000CDCA9 /* PreviewViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 18F7A8CF224A8129000CDCA9 /* PreviewViewController.m */; }; + 18F7A8D3224A8129000CDCA9 /* PreviewViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 18F7A8D1224A8129000CDCA9 /* PreviewViewController.xib */; }; + 18F7A8D8224A8129000CDCA9 /* ShuttleSpotlightPreview.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 18F7A8CA224A8129000CDCA9 /* ShuttleSpotlightPreview.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; + 18F7A8DE224A8207000CDCA9 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 18F7A8DD224A8207000CDCA9 /* Images.xcassets */; }; 24399FE6219CD0F700C8658F /* virtual-with-screen.scpt in Resources */ = {isa = PBXBuildFile; fileRef = 24399FE5219CD0F700C8658F /* virtual-with-screen.scpt */; }; 6FC541A31D45CF7F00A896E3 /* AboutWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6FC541A51D45CF7F00A896E3 /* AboutWindowController.xib */; }; 7E74A7C61789CE2F0079E0D2 /* shuttle.default.json in Resources */ = {isa = PBXBuildFile; fileRef = 7E74A7C51789CE2F0079E0D2 /* shuttle.default.json */; }; @@ -35,6 +41,30 @@ C159DC2815D5DE8000F5DE24 /* shuttle.icns in Resources */ = {isa = PBXBuildFile; fileRef = C159DC2715D5DE7F00F5DE24 /* shuttle.icns */; }; /* End PBXBuildFile section */ +/* Begin PBXContainerItemProxy section */ + 18F7A8D6224A8129000CDCA9 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = C149EBF015D5214600B1F558 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 18F7A8C9224A8129000CDCA9; + remoteInfo = ShuttleSpotlightPreview; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 18F7A8DC224A8129000CDCA9 /* Embed App Extensions */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 13; + files = ( + 18F7A8D8224A8129000CDCA9 /* ShuttleSpotlightPreview.appex in Embed App Extensions */, + ); + name = "Embed App Extensions"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + /* Begin PBXFileReference section */ 0ADB3B08178EF8DB004E9BB9 /* StatusIconAlt.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = StatusIconAlt.png; sourceTree = ""; }; 0ADB3B09178EF8DB004E9BB9 /* StatusIcon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = StatusIcon.png; sourceTree = ""; }; @@ -42,6 +72,15 @@ 0ADB3B0B178EF8DB004E9BB9 /* StatusIconAlt@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "StatusIconAlt@2x.png"; sourceTree = ""; }; 0ADB3B11178F3DE4004E9BB9 /* LaunchAtLoginController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LaunchAtLoginController.h; sourceTree = ""; }; 0ADB3B12178F3DE4004E9BB9 /* LaunchAtLoginController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LaunchAtLoginController.m; sourceTree = ""; }; + 18F7A8C4224A80AA000CDCA9 /* CoreSpotlight.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreSpotlight.framework; path = System/Library/Frameworks/CoreSpotlight.framework; sourceTree = SDKROOT; }; + 18F7A8CA224A8129000CDCA9 /* ShuttleSpotlightPreview.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = ShuttleSpotlightPreview.appex; sourceTree = BUILT_PRODUCTS_DIR; }; + 18F7A8CB224A8129000CDCA9 /* Quartz.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quartz.framework; path = System/Library/Frameworks/Quartz.framework; sourceTree = SDKROOT; }; + 18F7A8CE224A8129000CDCA9 /* PreviewViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PreviewViewController.h; sourceTree = ""; }; + 18F7A8CF224A8129000CDCA9 /* PreviewViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PreviewViewController.m; sourceTree = ""; }; + 18F7A8D2224A8129000CDCA9 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/PreviewViewController.xib; sourceTree = ""; }; + 18F7A8D4224A8129000CDCA9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 18F7A8D5224A8129000CDCA9 /* ShuttleSpotlightPreview.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = ShuttleSpotlightPreview.entitlements; sourceTree = ""; }; + 18F7A8DD224A8207000CDCA9 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 24399FE5219CD0F700C8658F /* virtual-with-screen.scpt */ = {isa = PBXFileReference; lastKnownFileType = file; path = "virtual-with-screen.scpt"; sourceTree = ""; }; 7E72D21E178003ED00A6389C /* Shuttle.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = Shuttle.entitlements; sourceTree = ""; }; 7E74A7C51789CE2F0079E0D2 /* shuttle.default.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = shuttle.default.json; sourceTree = ""; }; @@ -91,10 +130,19 @@ /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ + 18F7A8C7224A8129000CDCA9 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 18F7A8CC224A8129000CDCA9 /* Quartz.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; C149EBF615D5214600B1F558 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 18F7A8C5224A80AA000CDCA9 /* CoreSpotlight.framework in Frameworks */, C149EBFE15D5214600B1F558 /* Cocoa.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -113,6 +161,19 @@ name = Images; sourceTree = ""; }; + 18F7A8CD224A8129000CDCA9 /* ShuttleSpotlightPreview */ = { + isa = PBXGroup; + children = ( + 18F7A8CE224A8129000CDCA9 /* PreviewViewController.h */, + 18F7A8CF224A8129000CDCA9 /* PreviewViewController.m */, + 18F7A8D1224A8129000CDCA9 /* PreviewViewController.xib */, + 18F7A8D4224A8129000CDCA9 /* Info.plist */, + 18F7A8D5224A8129000CDCA9 /* ShuttleSpotlightPreview.entitlements */, + 18F7A8DD224A8207000CDCA9 /* Images.xcassets */, + ); + path = ShuttleSpotlightPreview; + sourceTree = ""; + }; A12D9BE61BCF2C72004F52A6 /* apple-scpt */ = { isa = PBXGroup; children = ( @@ -134,6 +195,7 @@ isa = PBXGroup; children = ( C149EC0315D5214600B1F558 /* Shuttle */, + 18F7A8CD224A8129000CDCA9 /* ShuttleSpotlightPreview */, C149EBFC15D5214600B1F558 /* Frameworks */, C149EBFA15D5214600B1F558 /* Products */, ); @@ -143,6 +205,7 @@ isa = PBXGroup; children = ( C149EBF915D5214600B1F558 /* Shuttle.app */, + 18F7A8CA224A8129000CDCA9 /* ShuttleSpotlightPreview.appex */, ); name = Products; sourceTree = ""; @@ -150,7 +213,9 @@ C149EBFC15D5214600B1F558 /* Frameworks */ = { isa = PBXGroup; children = ( + 18F7A8C4224A80AA000CDCA9 /* CoreSpotlight.framework */, C149EBFD15D5214600B1F558 /* Cocoa.framework */, + 18F7A8CB224A8129000CDCA9 /* Quartz.framework */, C149EBFF15D5214600B1F558 /* Other Frameworks */, ); name = Frameworks; @@ -203,6 +268,23 @@ /* End PBXGroup section */ /* Begin PBXNativeTarget section */ + 18F7A8C9224A8129000CDCA9 /* ShuttleSpotlightPreview */ = { + isa = PBXNativeTarget; + buildConfigurationList = 18F7A8D9224A8129000CDCA9 /* Build configuration list for PBXNativeTarget "ShuttleSpotlightPreview" */; + buildPhases = ( + 18F7A8C6224A8129000CDCA9 /* Sources */, + 18F7A8C7224A8129000CDCA9 /* Frameworks */, + 18F7A8C8224A8129000CDCA9 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = ShuttleSpotlightPreview; + productName = ShuttleSpotlightPreview; + productReference = 18F7A8CA224A8129000CDCA9 /* ShuttleSpotlightPreview.appex */; + productType = "com.apple.product-type.app-extension"; + }; C149EBF815D5214600B1F558 /* Shuttle */ = { isa = PBXNativeTarget; buildConfigurationList = C149EC1715D5214600B1F558 /* Build configuration list for PBXNativeTarget "Shuttle" */; @@ -210,10 +292,12 @@ C149EBF515D5214600B1F558 /* Sources */, C149EBF615D5214600B1F558 /* Frameworks */, C149EBF715D5214600B1F558 /* Resources */, + 18F7A8DC224A8129000CDCA9 /* Embed App Extensions */, ); buildRules = ( ); dependencies = ( + 18F7A8D7224A8129000CDCA9 /* PBXTargetDependency */, ); name = Shuttle; productName = Shuttle; @@ -228,12 +312,19 @@ attributes = { LastUpgradeCheck = 1010; ORGANIZATIONNAME = fitztrev; + TargetAttributes = { + 18F7A8C9224A8129000CDCA9 = { + CreatedOnToolsVersion = 10.2; + ProvisioningStyle = Automatic; + }; + }; }; buildConfigurationList = C149EBF315D5214600B1F558 /* Build configuration list for PBXProject "Shuttle" */; compatibilityVersion = "Xcode 3.2"; developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, "zh-Hans", Base, @@ -246,11 +337,21 @@ projectRoot = ""; targets = ( C149EBF815D5214600B1F558 /* Shuttle */, + 18F7A8C9224A8129000CDCA9 /* ShuttleSpotlightPreview */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ + 18F7A8C8224A8129000CDCA9 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 18F7A8D3224A8129000CDCA9 /* PreviewViewController.xib in Resources */, + 18F7A8DE224A8207000CDCA9 /* Images.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; C149EBF715D5214600B1F558 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -282,6 +383,14 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ + 18F7A8C6224A8129000CDCA9 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 18F7A8D0224A8129000CDCA9 /* PreviewViewController.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; C149EBF515D5214600B1F558 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -295,7 +404,23 @@ }; /* End PBXSourcesBuildPhase section */ +/* Begin PBXTargetDependency section */ + 18F7A8D7224A8129000CDCA9 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 18F7A8C9224A8129000CDCA9 /* ShuttleSpotlightPreview */; + targetProxy = 18F7A8D6224A8129000CDCA9 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + /* Begin PBXVariantGroup section */ + 18F7A8D1224A8129000CDCA9 /* PreviewViewController.xib */ = { + isa = PBXVariantGroup; + children = ( + 18F7A8D2224A8129000CDCA9 /* Base */, + ); + name = PreviewViewController.xib; + sourceTree = ""; + }; 6FC541A51D45CF7F00A896E3 /* AboutWindowController.xib */ = { isa = PBXVariantGroup; children = ( @@ -355,6 +480,71 @@ /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ + 18F7A8DA224A8129000CDCA9 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CODE_SIGN_ENTITLEMENTS = ShuttleSpotlightPreview/ShuttleSpotlightPreview.entitlements; + CODE_SIGN_IDENTITY = "-"; + CODE_SIGN_STYLE = Automatic; + DEBUG_INFORMATION_FORMAT = dwarf; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + INFOPLIST_FILE = ShuttleSpotlightPreview/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @executable_path/../../../../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.14; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + PRODUCT_BUNDLE_IDENTIFIER = shuttle.Shuttle.ShuttleSpotlightPreview; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + }; + name = Debug; + }; + 18F7A8DB224A8129000CDCA9 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CODE_SIGN_ENTITLEMENTS = ShuttleSpotlightPreview/ShuttleSpotlightPreview.entitlements; + CODE_SIGN_IDENTITY = "-"; + CODE_SIGN_STYLE = Automatic; + COPY_PHASE_STRIP = NO; + ENABLE_NS_ASSERTIONS = NO; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + INFOPLIST_FILE = ShuttleSpotlightPreview/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @executable_path/../../../../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.14; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + PRODUCT_BUNDLE_IDENTIFIER = shuttle.Shuttle.ShuttleSpotlightPreview; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + }; + name = Release; + }; C149EC1515D5214600B1F558 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -449,7 +639,7 @@ isa = XCBuildConfiguration; buildSettings = { CODE_SIGN_ENTITLEMENTS = Shuttle/Shuttle.entitlements; - CODE_SIGN_IDENTITY = ""; + CODE_SIGN_IDENTITY = "-"; COMBINE_HIDPI_IMAGES = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "Shuttle/Shuttle-Prefix.pch"; @@ -465,7 +655,7 @@ isa = XCBuildConfiguration; buildSettings = { CODE_SIGN_ENTITLEMENTS = Shuttle/Shuttle.entitlements; - CODE_SIGN_IDENTITY = ""; + CODE_SIGN_IDENTITY = "-"; COMBINE_HIDPI_IMAGES = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "Shuttle/Shuttle-Prefix.pch"; @@ -480,6 +670,15 @@ /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ + 18F7A8D9224A8129000CDCA9 /* Build configuration list for PBXNativeTarget "ShuttleSpotlightPreview" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 18F7A8DA224A8129000CDCA9 /* Debug */, + 18F7A8DB224A8129000CDCA9 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; C149EBF315D5214600B1F558 /* Build configuration list for PBXProject "Shuttle" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/Shuttle/AppDelegate.h b/Shuttle/AppDelegate.h index 5bc763c..fdea4ec 100644 --- a/Shuttle/AppDelegate.h +++ b/Shuttle/AppDelegate.h @@ -44,6 +44,9 @@ NSMutableArray* ignoreHosts; NSMutableArray* ignoreKeywords; + //Dictionary to hold all Leafs for indexing + NSMutableDictionary *spotlightIndex; + LaunchAtLoginController *launchAtLoginController; } diff --git a/Shuttle/AppDelegate.m b/Shuttle/AppDelegate.m index aa38207..1f43c4d 100644 --- a/Shuttle/AppDelegate.m +++ b/Shuttle/AppDelegate.m @@ -5,9 +5,46 @@ #import "AppDelegate.h" #import "AboutWindowController.h" +#import @implementation AppDelegate +- (BOOL)application:(NSApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray> * _Nonnull))restorationHandler { + NSArray *objectsFromJSON = [userActivity.userInfo[@"kCSSearchableItemActivityIdentifier"] componentsSeparatedByString:(@"¬_¬")]; + + [self openHost:objectsFromJSON]; + + return YES; +} + +- (void)indexForSpotlight { + [[CSSearchableIndex defaultSearchableIndex] deleteSearchableItemsWithDomainIdentifiers:[NSArray arrayWithObjects: @"spotlight.shuttle", nil] completionHandler:^(NSError * _Nullable error) { + + NSMutableArray *items = [[NSMutableArray alloc]init]; + + for(id key in self->spotlightIndex){ + + NSDictionary *cfg = [self->spotlightIndex objectForKey:key]; + + CSSearchableItemAttributeSet *attributeSet = [[CSSearchableItemAttributeSet alloc] initWithItemContentType:(NSString*)kUTTypeApplication]; + + attributeSet.title = [NSString stringWithFormat:@"%@", cfg[@"title"]]; + attributeSet.contentDescription = [NSString stringWithFormat:@"%@", cfg[@"cmd"]]; + + CSSearchableItem *item = [[CSSearchableItem alloc] initWithUniqueIdentifier:key domainIdentifier:@"spotlight.shuttle" attributeSet:attributeSet]; + + [items addObject:item]; + } + + [[CSSearchableIndex defaultSearchableIndex] indexSearchableItems:items completionHandler:^(NSError * __nullable error){ + if(error){ + NSLog(@"Indexing failed: %@", error); + return; + } + }]; + }]; +} + - (void) awakeFromNib { // The location for the JSON path file. This is a simple file that contains the hard path to the *.json settings file. @@ -89,13 +126,13 @@ - (void) awakeFromNib { launchAtLoginController = [[LaunchAtLoginController alloc] init]; // Needed to trigger the menuWillOpen event [menu setDelegate:self]; + + [self refresh]; } - (BOOL) needUpdateFor: (NSString*) file with: (NSDate*) old { - if (![[NSFileManager defaultManager] fileExistsAtPath:[file stringByExpandingTildeInPath]]) return false; - if (old == NULL) return true; @@ -109,7 +146,7 @@ - (NSDate*) getMTimeFor: (NSString*) file { return [attributes fileModificationDate]; } -- (void)menuWillOpen:(NSMenu *)menu { +- (void)refresh { // Check when the config was last modified if ( [self needUpdateFor:shuttleConfigFile with:configModified] || [self needUpdateFor:shuttleAltConfigFile with:configModified2] || @@ -118,13 +155,21 @@ - (void)menuWillOpen:(NSMenu *)menu { configModified = [self getMTimeFor:shuttleConfigFile]; configModified2 = [self getMTimeFor:shuttleAltConfigFile]; - sshConfigSystem = [self getMTimeFor: @"/etc/ssh_config"]; + sshConfigSystem = [self getMTimeFor: @"/etc/ssh/ssh_config"]; sshConfigUser = [self getMTimeFor: @"~/.ssh/config"]; + spotlightIndex = [[NSMutableDictionary alloc] init]; + [self loadMenu]; + + [self indexForSpotlight]; } } +- (void)menuWillOpen:(NSMenu *)menu { + [self refresh]; +} + // Parsing of the SSH Config File // Courtesy of https://gist.github.com/geeksunny/3376694 - (NSDictionary *)parseSSHConfigFile { @@ -194,8 +239,8 @@ - (void)menuWillOpen:(NSMenu *)menu { if ([first isEqualToString:@"Include"]) { // Support for ssh_config Include directive. NSString *includePath = ([second isAbsolutePath]) - ? [second stringByExpandingTildeInPath] - : [[filepath stringByDeletingLastPathComponent] stringByAppendingPathComponent:second]; + ? [second stringByExpandingTildeInPath] + : [[filepath stringByDeletingLastPathComponent] stringByAppendingPathComponent:second]; [servers addEntriesFromDictionary:[self parseSSHConfig:includePath]]; } @@ -418,9 +463,13 @@ - (void) buildMenu:(NSArray*)data addToMenu:(NSMenu *)m { //Place the terminal command, theme, and title into an comma delimited string NSString *menuRepObj = [NSString stringWithFormat:@"%@¬_¬%@¬_¬%@¬_¬%@¬_¬%@", menuCmd, termTheme, termTitle, termWindow, menuName]; + spotlightIndex[menuRepObj] = cfg; + + //[self indexTitle: termTitle command: menuCmd theme: termTheme window:termWindow name: menuName menuRepObj: menuRepObj]; + [menuItem setTitle:menuName]; [menuItem setRepresentedObject:menuRepObj]; - [menuItem setAction:@selector(openHost:)]; + [menuItem setAction:@selector(openHostFromMenu:)]; [m insertItem:menuItem atIndex:pos++]; if (addSeparator) { [m insertItem:[NSMenuItem separatorItem] atIndex:pos++]; @@ -463,7 +512,7 @@ - (void) separatorSortRemoval:(NSString *)currentName { } } -- (void) openHost:(NSMenuItem *) sender { +- (void) openHost:(NSArray *) objectsFromJSON { //NSLog(@"sender: %@", sender); //NSLog(@"Command: %@",[sender representedObject]); @@ -472,7 +521,7 @@ - (void) openHost:(NSMenuItem *) sender { //Place the comma delimited string of menu item settings into an array - NSArray *objectsFromJSON = [[sender representedObject] componentsSeparatedByString:(@"¬_¬")]; + //NSArray *objectsFromJSON = [[sender representedObject] componentsSeparatedByString:(@"¬_¬")]; //This is our command that will be run in the terminal window NSString *escapedObject; @@ -565,10 +614,10 @@ - (void) openHost:(NSMenuItem *) sender { } // Check if Url if (url) - { - [[NSWorkspace sharedWorkspace] openURL:url]; - - } + { + [[NSWorkspace sharedWorkspace] openURL:url]; + + } //If the JSON file is set to use iTerm else if ( [terminalPref rangeOfString: @"iterm"].location !=NSNotFound ) { @@ -649,6 +698,13 @@ - (void) openHost:(NSMenuItem *) sender { } } +- (void) openHostFromMenu:(NSMenuItem *) sender { + + NSArray *objectsFromJSON = [[sender representedObject] componentsSeparatedByString:(@"¬_¬")]; + + [self openHost:objectsFromJSON]; +} + - (void) runScript:(NSString *)scriptPath handler:(NSString*)handlerName parameters:(NSArray*)parametersInArray { //special thanks to stackoverflow.com/users/316866/leandro for pointing me the right direction. //see http://goo.gl/olcpaX @@ -699,14 +755,24 @@ - (void) runScript:(NSString *)scriptPath handler:(NSString*)handlerName paramet [containerEvent setParamDescriptor:arguments forKeyword:keyDirectObject]; } + NSDictionary * executionError = nil; //Execute the event - [appleScript executeAppleEvent:containerEvent error:nil]; + NSAppleEventDescriptor *result = [appleScript executeAppleEvent:containerEvent error:&executionError]; + + if (executionError != nil) { + NSLog(@"error while executing script. Error %@", executionError); + + } else { + NSLog(@"Script execution has succeed. Result(%@)", result); + + } + } } - (IBAction)showImportPanel:(id)sender { - NSOpenPanel * openPanelObj = [NSOpenPanel openPanel]; - NSInteger tvarNSInteger = [openPanelObj runModal]; + NSOpenPanel * openPanelObj = [NSOpenPanel openPanel]; + NSInteger tvarNSInteger = [openPanelObj runModal]; if(tvarNSInteger == NSOKButton){ //Backup the current configuration [[NSFileManager defaultManager] moveItemAtPath:shuttleConfigFile toPath: [NSHomeDirectory() stringByAppendingPathComponent:@".shuttle.json.backup"] error: nil]; @@ -743,9 +809,9 @@ -(void) throwError:(NSString*)errorMessage additionalInfo:(NSString*)errorInfo c } - (IBAction)showExportPanel:(id)sender { - NSSavePanel * savePanelObj = [NSSavePanel savePanel]; + NSSavePanel * savePanelObj = [NSSavePanel savePanel]; //Display the Save Panel - NSInteger result = [savePanelObj runModal]; + NSInteger result = [savePanelObj runModal]; if (result == NSFileHandlingPanelOKButton) { NSURL *saveURL = [savePanelObj URL]; // then copy a previous file to the new location @@ -767,14 +833,14 @@ - (IBAction)configure:(id)sender { //build the reprensented object. It's expecting menuCmd, termTheme, termTitle, termWindow, menuName NSString *editorRepObj = [NSString stringWithFormat:@"%@¬_¬%@¬_¬%@¬_¬%@¬_¬%@", editorCommand, nil, @"Editing shuttle JSON", nil, nil]; - //make a menu item for the command selector(openHost:) runs in a new terminal window. - NSMenuItem *editorMenu = [[NSMenuItem alloc] initWithTitle:@"editJSONconfig" action:@selector(openHost:) keyEquivalent:(@"")]; + //make a menu item for the command selector(openHostFromMenu:) runs in a new terminal window. + NSMenuItem *editorMenu = [[NSMenuItem alloc] initWithTitle:@"editJSONconfig" action:@selector(openHostFromMenu:) keyEquivalent:(@"")]; //set the command for the menu item [editorMenu setRepresentedObject:editorRepObj]; //open the JSON file in the terminal editor. - [self openHost:editorMenu]; + [self openHostFromMenu:editorMenu]; } } diff --git a/ShuttleSpotlightPreview/Base.lproj/PreviewViewController.xib b/ShuttleSpotlightPreview/Base.lproj/PreviewViewController.xib new file mode 100644 index 0000000..deed027 --- /dev/null +++ b/ShuttleSpotlightPreview/Base.lproj/PreviewViewController.xib @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ShuttleSpotlightPreview/Images.xcassets/AppIcon.appiconset/Contents.json b/ShuttleSpotlightPreview/Images.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..c03bc65 --- /dev/null +++ b/ShuttleSpotlightPreview/Images.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,68 @@ +{ + "images" : [ + { + "size" : "16x16", + "idiom" : "mac", + "filename" : "shuttle16pt.png", + "scale" : "1x" + }, + { + "size" : "16x16", + "idiom" : "mac", + "filename" : "shuttle16pt2x.png", + "scale" : "2x" + }, + { + "size" : "32x32", + "idiom" : "mac", + "filename" : "shuttle32pt.png", + "scale" : "1x" + }, + { + "size" : "32x32", + "idiom" : "mac", + "filename" : "shuttle32pt2x.png", + "scale" : "2x" + }, + { + "size" : "128x128", + "idiom" : "mac", + "filename" : "shuttle128pt.png", + "scale" : "1x" + }, + { + "size" : "128x128", + "idiom" : "mac", + "filename" : "shuttle128pt2x.png", + "scale" : "2x" + }, + { + "size" : "256x256", + "idiom" : "mac", + "filename" : "shuttle256pt.png", + "scale" : "1x" + }, + { + "size" : "256x256", + "idiom" : "mac", + "filename" : "shuttle256pt2x.png", + "scale" : "2x" + }, + { + "size" : "512x512", + "idiom" : "mac", + "filename" : "shuttle512pt.png", + "scale" : "1x" + }, + { + "size" : "512x512", + "idiom" : "mac", + "filename" : "shuttle512pt2x.png", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/ShuttleSpotlightPreview/Images.xcassets/AppIcon.appiconset/shuttle128pt.png b/ShuttleSpotlightPreview/Images.xcassets/AppIcon.appiconset/shuttle128pt.png new file mode 100644 index 0000000..6258ef7 Binary files /dev/null and b/ShuttleSpotlightPreview/Images.xcassets/AppIcon.appiconset/shuttle128pt.png differ diff --git a/ShuttleSpotlightPreview/Images.xcassets/AppIcon.appiconset/shuttle128pt2x.png b/ShuttleSpotlightPreview/Images.xcassets/AppIcon.appiconset/shuttle128pt2x.png new file mode 100644 index 0000000..f73570e Binary files /dev/null and b/ShuttleSpotlightPreview/Images.xcassets/AppIcon.appiconset/shuttle128pt2x.png differ diff --git a/ShuttleSpotlightPreview/Images.xcassets/AppIcon.appiconset/shuttle16pt.png b/ShuttleSpotlightPreview/Images.xcassets/AppIcon.appiconset/shuttle16pt.png new file mode 100644 index 0000000..bbc054c Binary files /dev/null and b/ShuttleSpotlightPreview/Images.xcassets/AppIcon.appiconset/shuttle16pt.png differ diff --git a/ShuttleSpotlightPreview/Images.xcassets/AppIcon.appiconset/shuttle16pt2x.png b/ShuttleSpotlightPreview/Images.xcassets/AppIcon.appiconset/shuttle16pt2x.png new file mode 100644 index 0000000..8341a6f Binary files /dev/null and b/ShuttleSpotlightPreview/Images.xcassets/AppIcon.appiconset/shuttle16pt2x.png differ diff --git a/ShuttleSpotlightPreview/Images.xcassets/AppIcon.appiconset/shuttle256pt.png b/ShuttleSpotlightPreview/Images.xcassets/AppIcon.appiconset/shuttle256pt.png new file mode 100644 index 0000000..fa7a429 Binary files /dev/null and b/ShuttleSpotlightPreview/Images.xcassets/AppIcon.appiconset/shuttle256pt.png differ diff --git a/ShuttleSpotlightPreview/Images.xcassets/AppIcon.appiconset/shuttle256pt2x.png b/ShuttleSpotlightPreview/Images.xcassets/AppIcon.appiconset/shuttle256pt2x.png new file mode 100644 index 0000000..ac6ea6a Binary files /dev/null and b/ShuttleSpotlightPreview/Images.xcassets/AppIcon.appiconset/shuttle256pt2x.png differ diff --git a/ShuttleSpotlightPreview/Images.xcassets/AppIcon.appiconset/shuttle32pt.png b/ShuttleSpotlightPreview/Images.xcassets/AppIcon.appiconset/shuttle32pt.png new file mode 100644 index 0000000..54b927b Binary files /dev/null and b/ShuttleSpotlightPreview/Images.xcassets/AppIcon.appiconset/shuttle32pt.png differ diff --git a/ShuttleSpotlightPreview/Images.xcassets/AppIcon.appiconset/shuttle32pt2x.png b/ShuttleSpotlightPreview/Images.xcassets/AppIcon.appiconset/shuttle32pt2x.png new file mode 100644 index 0000000..16be35e Binary files /dev/null and b/ShuttleSpotlightPreview/Images.xcassets/AppIcon.appiconset/shuttle32pt2x.png differ diff --git a/ShuttleSpotlightPreview/Images.xcassets/AppIcon.appiconset/shuttle512pt.png b/ShuttleSpotlightPreview/Images.xcassets/AppIcon.appiconset/shuttle512pt.png new file mode 100644 index 0000000..bbd6dc9 Binary files /dev/null and b/ShuttleSpotlightPreview/Images.xcassets/AppIcon.appiconset/shuttle512pt.png differ diff --git a/ShuttleSpotlightPreview/Images.xcassets/AppIcon.appiconset/shuttle512pt2x.png b/ShuttleSpotlightPreview/Images.xcassets/AppIcon.appiconset/shuttle512pt2x.png new file mode 100644 index 0000000..a5a8530 Binary files /dev/null and b/ShuttleSpotlightPreview/Images.xcassets/AppIcon.appiconset/shuttle512pt2x.png differ diff --git a/ShuttleSpotlightPreview/Images.xcassets/Contents.json b/ShuttleSpotlightPreview/Images.xcassets/Contents.json new file mode 100644 index 0000000..da4a164 --- /dev/null +++ b/ShuttleSpotlightPreview/Images.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/ShuttleSpotlightPreview/Images.xcassets/ShuttleImage.imageset/Contents.json b/ShuttleSpotlightPreview/Images.xcassets/ShuttleImage.imageset/Contents.json new file mode 100644 index 0000000..7013979 --- /dev/null +++ b/ShuttleSpotlightPreview/Images.xcassets/ShuttleImage.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "shuttle128pt2x.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "shuttle256pt2x.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "filename" : "shuttle512pt2x.png", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/ShuttleSpotlightPreview/Images.xcassets/ShuttleImage.imageset/shuttle128pt2x.png b/ShuttleSpotlightPreview/Images.xcassets/ShuttleImage.imageset/shuttle128pt2x.png new file mode 100644 index 0000000..f73570e Binary files /dev/null and b/ShuttleSpotlightPreview/Images.xcassets/ShuttleImage.imageset/shuttle128pt2x.png differ diff --git a/ShuttleSpotlightPreview/Images.xcassets/ShuttleImage.imageset/shuttle256pt2x.png b/ShuttleSpotlightPreview/Images.xcassets/ShuttleImage.imageset/shuttle256pt2x.png new file mode 100644 index 0000000..ac6ea6a Binary files /dev/null and b/ShuttleSpotlightPreview/Images.xcassets/ShuttleImage.imageset/shuttle256pt2x.png differ diff --git a/ShuttleSpotlightPreview/Images.xcassets/ShuttleImage.imageset/shuttle512pt2x.png b/ShuttleSpotlightPreview/Images.xcassets/ShuttleImage.imageset/shuttle512pt2x.png new file mode 100644 index 0000000..a5a8530 Binary files /dev/null and b/ShuttleSpotlightPreview/Images.xcassets/ShuttleImage.imageset/shuttle512pt2x.png differ diff --git a/ShuttleSpotlightPreview/Info.plist b/ShuttleSpotlightPreview/Info.plist new file mode 100644 index 0000000..ec27c37 --- /dev/null +++ b/ShuttleSpotlightPreview/Info.plist @@ -0,0 +1,40 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleDisplayName + ShuttleSpotlightPreview + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + XPC! + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSMinimumSystemVersion + $(MACOSX_DEPLOYMENT_TARGET) + NSExtension + + NSExtensionAttributes + + QLSupportsSearchableItems + + + NSExtensionPointIdentifier + com.apple.quicklook.preview + NSExtensionPrincipalClass + PreviewViewController + + NSHumanReadableCopyright + Copyright © 2019 fitztrev. All rights reserved. + + diff --git a/ShuttleSpotlightPreview/PreviewViewController.h b/ShuttleSpotlightPreview/PreviewViewController.h new file mode 100644 index 0000000..6d4f2f4 --- /dev/null +++ b/ShuttleSpotlightPreview/PreviewViewController.h @@ -0,0 +1,13 @@ +// +// PreviewViewController.h +// ShuttleSpotlightPreview +// +// Copyright © 2019 fitztrev. All rights reserved. +// + +#import + + +@interface PreviewViewController : NSViewController + +@end diff --git a/ShuttleSpotlightPreview/PreviewViewController.m b/ShuttleSpotlightPreview/PreviewViewController.m new file mode 100644 index 0000000..120f5df --- /dev/null +++ b/ShuttleSpotlightPreview/PreviewViewController.m @@ -0,0 +1,39 @@ +// +// PreviewViewController.m +// ShuttleSpotlightPreview +// Copyright © 2019 fitztrev. All rights reserved. +// + +#import "PreviewViewController.h" +#import + +@interface PreviewViewController () { + IBOutlet NSTextField *label; + IBOutlet NSTextField *command; +} + +@end + +@implementation PreviewViewController + +- (NSString *)nibName { + return @"PreviewViewController"; +} + +- (void)loadView { + [super loadView]; + // Do any additional setup after loading the view from its nib. +} + +- (void)preparePreviewOfSearchableItemWithIdentifier:(NSString *)identifier queryString:(NSString *)queryString completionHandler:(void (^)(NSError * _Nullable))handler { + NSArray *objectsFromJSON = [identifier componentsSeparatedByString:(@"¬_¬")]; + if([objectsFromJSON count] > 3) { + [label setStringValue:[objectsFromJSON objectAtIndex:2]]; + + [command setStringValue:[objectsFromJSON objectAtIndex:0]]; + } + handler(nil); +} + +@end + diff --git a/ShuttleSpotlightPreview/ShuttleSpotlightPreview.entitlements b/ShuttleSpotlightPreview/ShuttleSpotlightPreview.entitlements new file mode 100644 index 0000000..f2ef3ae --- /dev/null +++ b/ShuttleSpotlightPreview/ShuttleSpotlightPreview.entitlements @@ -0,0 +1,10 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.files.user-selected.read-only + + +