forked from p0deje/Maccy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support deleting history item by its position via Shortcuts
Fixes p0deje#582
- Loading branch information
Showing
7 changed files
with
240 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import Intents | ||
|
||
@available(macOS 11.0, *) | ||
class DeleteIntentHandler: NSObject, DeleteIntentHandling { | ||
private let positionOffset = 1 | ||
private var maccy: Maccy! | ||
|
||
init(_ maccy: Maccy) { | ||
self.maccy = maccy | ||
} | ||
|
||
func handle(intent: DeleteIntent, completion: @escaping (DeleteIntentResponse) -> Void) { | ||
guard let number = intent.number as? Int, | ||
let value = maccy.delete(position: number - positionOffset) else { | ||
return completion(DeleteIntentResponse(code: .failure, userActivity: nil)) | ||
} | ||
|
||
let response = DeleteIntentResponse(code: .success, userActivity: nil) | ||
response.value = value | ||
return completion(response) | ||
} | ||
|
||
func resolveNumber(for intent: DeleteIntent, with completion: @escaping (DeleteNumberResolutionResult) -> Void) { | ||
guard let number = intent.number as? Int else { | ||
return completion(.needsValue()) | ||
} | ||
|
||
return completion(.success(with: number)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters