diff --git a/Stapler.xcodeproj/project.pbxproj b/Stapler.xcodeproj/project.pbxproj index b37d81c..5076843 100644 --- a/Stapler.xcodeproj/project.pbxproj +++ b/Stapler.xcodeproj/project.pbxproj @@ -281,10 +281,10 @@ GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = Stapler/Info.plist; INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.productivity"; - INFOPLIST_KEY_NSDesktopFolderUsageDescription = "This app needs access to your Desktop folder to open and manage files."; - INFOPLIST_KEY_NSDocumentsFolderUsageDescription = "This app needs access to your Documents folder to open and manage files."; - INFOPLIST_KEY_NSDownloadsFolderUsageDescription = "This app needs access to your Downloads folder to open and manage files."; - INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2024 Matt Sephton.\nAll rights reserved."; + INFOPLIST_KEY_NSDesktopFolderUsageDescription = "Stapler needs access to your files to read aliases and create and manage its own files."; + INFOPLIST_KEY_NSDocumentsFolderUsageDescription = "Stapler needs access to your files to read aliases and create and manage its own files."; + INFOPLIST_KEY_NSDownloadsFolderUsageDescription = "Stapler needs access to your files to read aliases and create and manage its own files."; + INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2024 Matt Sephton"; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/../Frameworks", @@ -313,10 +313,10 @@ GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = Stapler/Info.plist; INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.productivity"; - INFOPLIST_KEY_NSDesktopFolderUsageDescription = "This app needs access to your Desktop folder to open and manage files."; - INFOPLIST_KEY_NSDocumentsFolderUsageDescription = "This app needs access to your Documents folder to open and manage files."; - INFOPLIST_KEY_NSDownloadsFolderUsageDescription = "This app needs access to your Downloads folder to open and manage files."; - INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2024 Matt Sephton.\nAll rights reserved."; + INFOPLIST_KEY_NSDesktopFolderUsageDescription = "Stapler needs access to your files to read aliases and create and manage its own files."; + INFOPLIST_KEY_NSDocumentsFolderUsageDescription = "Stapler needs access to your files to read aliases and create and manage its own files."; + INFOPLIST_KEY_NSDownloadsFolderUsageDescription = "Stapler needs access to your files to read aliases and create and manage its own files."; + INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2024 Matt Sephton"; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/../Frameworks", diff --git a/Stapler/Info.plist b/Stapler/Info.plist index 24aeff3..ac2bb2e 100644 --- a/Stapler/Info.plist +++ b/Stapler/Info.plist @@ -2,12 +2,6 @@ - NSDesktopFolderUsageDescription - Stapler needs access to your files to read aliases and create and manage its own files. - NSDocumentsFolderUsageDescription - Stapler needs access to your files to read aliases and create and manage its own files. - NSDownloadsFolderUsageDescription - Stapler needs access to your files to read aliases and create and manage its own files. CFBundleDocumentTypes diff --git a/Stapler/StaplerApp.swift b/Stapler/StaplerApp.swift index ccd13b5..d24da21 100644 --- a/Stapler/StaplerApp.swift +++ b/Stapler/StaplerApp.swift @@ -8,6 +8,7 @@ enum DocumentOpeningScenario { case launchedWithDocument case resumedBySystem case openedThroughFileMenu + case openedFromFinderWhileRunning case unknown } @@ -15,7 +16,7 @@ enum DocumentOpeningScenario { class AppDelegate: NSObject, NSApplicationDelegate { func setupDefaultCommandKeyDelay() { if UserDefaults.standard.object(forKey: "CommandKeyDelay") == nil { - UserDefaults.standard.set(100, forKey: "CommandKeyDelay") // Default wait 100ms + UserDefaults.standard.set(0, forKey: "CommandKeyDelay") // Default wait 0ms } } @@ -585,6 +586,10 @@ struct StaplerApp: App { logger.info("Document Opening Scenario: openedThroughFileMenu") // Handle opened through file menu scenario break + case .openedFromFinderWhileRunning: + logger.info("Document Opening Scenario: openedFromFinderWhileRunning") + // Handle opened through Finder whilst running scenario + handleOpenedFromFinderWhileRunning(url) case .unknown: logger.info("Document Opening Scenario: unknown") // Handle unknown scenarios @@ -601,6 +606,8 @@ struct StaplerApp: App { if appStateManager.wasJustLaunched && isOpenedFromFinder { return .launchedWithDocument + } else if isOpenedFromFinder && NSApp.isActive { + return .openedFromFinderWhileRunning } else if NSApp.isActive { return .openedThroughFileMenu } else if ProcessInfo.processInfo.isOperatingSystemAtLeast(OperatingSystemVersion(majorVersion: 10, minorVersion: 15, patchVersion: 0)) { @@ -612,38 +619,65 @@ struct StaplerApp: App { } private func handleLaunchedWithDocument(_ url: URL) { - DispatchQueue.main.asyncAfter(deadline: .now() + commandKeyDelay) { - let commandKeyPressed = NSEvent.modifierFlags.contains(.command) - - if !commandKeyPressed { - do { - guard url.startAccessingSecurityScopedResource() else { - logger.error("Failed to access security-scoped resource") - return - } - defer { url.stopAccessingSecurityScopedResource() } - - let document = try StaplerDocument(contentsOf: url) - let viewModel = StaplerViewModel(document: document) - viewModel.launchAliases(at: IndexSet(integersIn: 0..