From db42b63c6186e7cd6d3c7c3a3ef74082e591d3d7 Mon Sep 17 00:00:00 2001 From: Charlie Scheer Date: Thu, 11 Apr 2024 14:42:14 -0600 Subject: [PATCH] Open notes from spotlight search --- Simplenote/SimplenoteAppDelegate+Swift.swift | 17 +++++++++++++++++ Simplenote/SimplenoteAppDelegate.m | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/Simplenote/SimplenoteAppDelegate+Swift.swift b/Simplenote/SimplenoteAppDelegate+Swift.swift index 0627ebb7d..1230d284b 100644 --- a/Simplenote/SimplenoteAppDelegate+Swift.swift +++ b/Simplenote/SimplenoteAppDelegate+Swift.swift @@ -1,6 +1,7 @@ import Foundation import SimplenoteSearch import Simperium_OSX +import CoreSpotlight // MARK: - Initialization // @@ -237,6 +238,22 @@ extension SimplenoteAppDelegate { SPTracker.trackSettingsStatusBarDisplayMode(hidden: Options.shared.statusBarHidden) } + + @objc + func handleUserActivity(_ userActivity: NSUserActivity) { + if userActivity.activityType == "com.apple.corespotlightitem" { + presentNote(for: userActivity) + return + } + } + + func presentNote(for userActivity: NSUserActivity) { + guard let uniqueIdentifier = userActivity.userInfo?[CSSearchableItemActivityIdentifier] as? String else { + return + } + + displayNote(simperiumKey: uniqueIdentifier) + } } // MARK: - URL Handlers diff --git a/Simplenote/SimplenoteAppDelegate.m b/Simplenote/SimplenoteAppDelegate.m index 97c65b3c3..1aa263cc5 100644 --- a/Simplenote/SimplenoteAppDelegate.m +++ b/Simplenote/SimplenoteAppDelegate.m @@ -232,6 +232,10 @@ - (IBAction)aboutAction:(id)sender [self.aboutWindowController showWindow:self]; } +- (BOOL)application:(NSApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray> * _Nonnull))restorationHandler +{ + [self handleUserActivity:userActivity]; +} #pragma mark - Simperium Delegates