Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/trunk' into charlie/fix-intents-…
Browse files Browse the repository at this point in the history
…version-number
  • Loading branch information
mokagio committed Jun 4, 2024
2 parents 133e882 + a3d8a53 commit f802e59
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 0 deletions.
2 changes: 2 additions & 0 deletions IntentsExtension/IntentHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class IntentHandler: INExtension {
return OpenNoteIntentHandler()
case is FindNoteIntent:
return FindNoteIntentHandler()
case is CopyNoteContentIntent:
return CopyNoteContentIntentHandler()
default:
return self
}
Expand Down
39 changes: 39 additions & 0 deletions IntentsExtension/IntentHandlers/CopyNoteContentIntentHandler.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// CopyNoteContentIntentHandler.swift
// IntentsExtension
//
// Created by Charlie Scheer on 5/29/24.
// Copyright © 2024 Simperium. All rights reserved.
//

import Intents

class CopyNoteContentIntentHandler: NSObject, CopyNoteContentIntentHandling {
let coreDataWrapper = ExtensionCoreDataWrapper()

func provideNoteOptionsCollection(for intent: CopyNoteContentIntent, with completion: @escaping (INObjectCollection<IntentNote>?, (any Error)?) -> Void) {
do {
let intentNotes = try IntentNote.allNotes(in: coreDataWrapper)
completion(INObjectCollection(items: intentNotes), nil)
} catch {
completion(nil, IntentsError.couldNotFetchNotes)
}
}

func handle(intent: CopyNoteContentIntent, completion: @escaping (CopyNoteContentIntentResponse) -> Void) {
guard let note = intent.note else {
completion(CopyNoteContentIntentResponse(code: .unspecified, userActivity: nil))
return
}

guard let identifier = note.identifier,
let content = coreDataWrapper.resultsController?.note(forSimperiumKey: identifier)?.content else {
completion(CopyNoteContentIntentResponse(code: .failure, userActivity: nil))
return
}

let response = CopyNoteContentIntentResponse(code: .success, userActivity: nil)
response.noteContent = content
completion(response)
}
}
1 change: 1 addition & 0 deletions IntentsExtension/Support Files/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<array/>
<key>IntentsSupported</key>
<array>
<string>CopyNoteContentIntent</string>
<string>FindNoteIntent</string>
<string>OpenNewNoteIntent</string>
<string>OpenNoteIntent</string>
Expand Down
4 changes: 4 additions & 0 deletions Simplenote.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@
BA5A65952C09164100F605A6 /* MockStorageSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA5A65942C09164100F605A6 /* MockStorageSettings.swift */; };
BA5A65972C091D0600F605A6 /* CoreDataValidator.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA5A65962C091D0600F605A6 /* CoreDataValidator.swift */; };
BA5A65992C091E6000F605A6 /* MockStorageValidator.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA5A65982C091E6000F605A6 /* MockStorageValidator.swift */; };
BA5A658A2C07CD0B00F605A6 /* CopyNoteContentIntentHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA5A65892C07CD0B00F605A6 /* CopyNoteContentIntentHandler.swift */; };
BA5F020626BB57F000581E92 /* NSAlert+Simplenote.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA5F020426BB57F000581E92 /* NSAlert+Simplenote.swift */; };
BA71EC242BC88FD000F42CB1 /* CSSearchable+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA52005A2BC878F1003F1B75 /* CSSearchable+Helpers.swift */; };
BA71EC252BC88FFC00F42CB1 /* NSManagedObjectContext+Simplenote.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA52005C2BC88397003F1B75 /* NSManagedObjectContext+Simplenote.swift */; };
Expand Down Expand Up @@ -702,6 +703,7 @@
BA5A65942C09164100F605A6 /* MockStorageSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockStorageSettings.swift; sourceTree = "<group>"; };
BA5A65962C091D0600F605A6 /* CoreDataValidator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataValidator.swift; sourceTree = "<group>"; };
BA5A65982C091E6000F605A6 /* MockStorageValidator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockStorageValidator.swift; sourceTree = "<group>"; };
BA5A65892C07CD0B00F605A6 /* CopyNoteContentIntentHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CopyNoteContentIntentHandler.swift; sourceTree = "<group>"; };
BA5F020426BB57F000581E92 /* NSAlert+Simplenote.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSAlert+Simplenote.swift"; sourceTree = "<group>"; };
BA8CF21B2BFD20770087F33D /* Intents.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Intents.framework; path = System/Library/Frameworks/Intents.framework; sourceTree = SDKROOT; };
BA938CEB26ACFF4A00BE5A1D /* Remote.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Remote.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1618,6 +1620,7 @@
BAB261742BFFD319009A98D7 /* OpenNewNoteIntentHandler.swift */,
BAC5DFB82C079E5A002AD7EF /* OpenNoteIntentHandler.swift */,
BA2BF33F2C07C75500A7C894 /* FindNoteIntentHandler.swift */,
BA5A65892C07CD0B00F605A6 /* CopyNoteContentIntentHandler.swift */,
);
path = IntentHandlers;
sourceTree = "<group>";
Expand Down Expand Up @@ -2193,6 +2196,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
BA5A658A2C07CD0B00F605A6 /* CopyNoteContentIntentHandler.swift in Sources */,
BAAA71EF2C07A6CF00244C01 /* IntentsError.swift in Sources */,
BAAA71F22C07A7FD00244C01 /* IntentsConstants.swift in Sources */,
BAAA71D92C07A14600244C01 /* String+Simplenote.swift in Sources */,
Expand Down
137 changes: 137 additions & 0 deletions Simplenote/ShortcutIntents.intentdefinition
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,143 @@
<key>INIntentVerb</key>
<string>Do</string>
</dict>
<dict>
<key>INIntentCategory</key>
<string>generic</string>
<key>INIntentConfigurable</key>
<true/>
<key>INIntentDescription</key>
<string>Copy content from note to clipboard</string>
<key>INIntentDescriptionID</key>
<string>5vfiUZ</string>
<key>INIntentIneligibleForSuggestions</key>
<true/>
<key>INIntentInput</key>
<string>note</string>
<key>INIntentLastParameterTag</key>
<integer>2</integer>
<key>INIntentManagedParameterCombinations</key>
<dict>
<key>note</key>
<dict>
<key>INIntentParameterCombinationSupportsBackgroundExecution</key>
<true/>
<key>INIntentParameterCombinationTitle</key>
<string>Copy content from ${note}</string>
<key>INIntentParameterCombinationTitleID</key>
<string>w9U7WT</string>
<key>INIntentParameterCombinationUpdatesLinked</key>
<true/>
</dict>
</dict>
<key>INIntentName</key>
<string>CopyNoteContent</string>
<key>INIntentParameters</key>
<array>
<dict>
<key>INIntentParameterConfigurable</key>
<true/>
<key>INIntentParameterDisplayName</key>
<string>Note</string>
<key>INIntentParameterDisplayNameID</key>
<string>2hJptW</string>
<key>INIntentParameterDisplayPriority</key>
<integer>1</integer>
<key>INIntentParameterName</key>
<string>note</string>
<key>INIntentParameterObjectType</key>
<string>IntentNote</string>
<key>INIntentParameterObjectTypeNamespace</key>
<string>ihfyvu</string>
<key>INIntentParameterPromptDialogs</key>
<array>
<dict>
<key>INIntentParameterPromptDialogCustom</key>
<true/>
<key>INIntentParameterPromptDialogType</key>
<string>Configuration</string>
</dict>
<dict>
<key>INIntentParameterPromptDialogCustom</key>
<true/>
<key>INIntentParameterPromptDialogType</key>
<string>Primary</string>
</dict>
<dict>
<key>INIntentParameterPromptDialogCustom</key>
<true/>
<key>INIntentParameterPromptDialogFormatString</key>
<string>There are ${count} options matching ‘${note}’.</string>
<key>INIntentParameterPromptDialogFormatStringID</key>
<string>jr7M0N</string>
<key>INIntentParameterPromptDialogType</key>
<string>DisambiguationIntroduction</string>
</dict>
<dict>
<key>INIntentParameterPromptDialogCustom</key>
<true/>
<key>INIntentParameterPromptDialogFormatString</key>
<string>Just to confirm, you wanted ‘${note}’?</string>
<key>INIntentParameterPromptDialogFormatStringID</key>
<string>YU4Kd7</string>
<key>INIntentParameterPromptDialogType</key>
<string>Confirmation</string>
</dict>
</array>
<key>INIntentParameterSupportsDynamicEnumeration</key>
<true/>
<key>INIntentParameterTag</key>
<integer>2</integer>
<key>INIntentParameterType</key>
<string>Object</string>
</dict>
</array>
<key>INIntentResponse</key>
<dict>
<key>INIntentResponseCodes</key>
<array>
<dict>
<key>INIntentResponseCodeName</key>
<string>success</string>
<key>INIntentResponseCodeSuccess</key>
<true/>
</dict>
<dict>
<key>INIntentResponseCodeName</key>
<string>failure</string>
</dict>
</array>
<key>INIntentResponseLastParameterTag</key>
<integer>1</integer>
<key>INIntentResponseOutput</key>
<string>noteContent</string>
<key>INIntentResponseParameters</key>
<array>
<dict>
<key>INIntentResponseParameterDisplayName</key>
<string>Note Content</string>
<key>INIntentResponseParameterDisplayNameID</key>
<string>uBpNIP</string>
<key>INIntentResponseParameterDisplayPriority</key>
<integer>1</integer>
<key>INIntentResponseParameterName</key>
<string>noteContent</string>
<key>INIntentResponseParameterTag</key>
<integer>1</integer>
<key>INIntentResponseParameterType</key>
<string>String</string>
</dict>
</array>
</dict>
<key>INIntentTitle</key>
<string>Copy Note Content</string>
<key>INIntentTitleID</key>
<string>wst1ys</string>
<key>INIntentType</key>
<string>Custom</string>
<key>INIntentVerb</key>
<string>Do</string>
</dict>
</array>
<key>INTypes</key>
<array>
Expand Down
1 change: 1 addition & 0 deletions Simplenote/Simplenote-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<string>SPApplication</string>
<key>NSUserActivityTypes</key>
<array>
<string>CopyNoteContentIntent</string>
<string>FindNoteIntent</string>
<string>OpenNewNoteIntent</string>
<string>OpenNoteIntent</string>
Expand Down

0 comments on commit f802e59

Please sign in to comment.