Skip to content

Commit

Permalink
Open notes from spotlight search
Browse files Browse the repository at this point in the history
  • Loading branch information
charliescheer committed Apr 11, 2024
1 parent 98affe9 commit db42b63
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Simplenote/SimplenoteAppDelegate+Swift.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Foundation
import SimplenoteSearch
import Simperium_OSX
import CoreSpotlight

// MARK: - Initialization
//
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Simplenote/SimplenoteAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ - (IBAction)aboutAction:(id)sender
[self.aboutWindowController showWindow:self];
}

- (BOOL)application:(NSApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<NSUserActivityRestoring>> * _Nonnull))restorationHandler
{
[self handleUserActivity:userActivity];
}

#pragma mark - Simperium Delegates

Expand Down

0 comments on commit db42b63

Please sign in to comment.