Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shortcut: Create note with content #1171

Merged
merged 5 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions IntentsExtension/IntentHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class IntentHandler: INExtension {
return FindNoteIntentHandler()
case is AppendNoteIntent:
return AppendNoteIntentHandler()
case is CreateNewNoteIntent:
return CreateNewNoteIntentHandler()
default:
return self
}
Expand Down
28 changes: 28 additions & 0 deletions IntentsExtension/IntentHandlers/CreateNewNoteIntentHandler.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Intents

class CreateNewNoteIntentHandler: NSObject, CreateNewNoteIntentHandling {
let coreDataWrapper = ExtensionCoreDataWrapper()

func handle(intent: CreateNewNoteIntent) async -> CreateNewNoteIntentResponse {
guard let content = intent.content,
let token = KeychainManager.extensionToken,
let note = note(with: content) else {
return CreateNewNoteIntentResponse(code: .failure, userActivity: nil)
}

Uploader(simperiumToken: token).send(note)
return CreateNewNoteIntentResponse(code: .success, userActivity: nil)
}

private func note(with content: String) -> Note? {
guard let context = coreDataWrapper.context() else {
return nil
}
let note = Note(context: context)
note.creationDate = .now
note.modificationDate = .now
note.content = content

return note
}
}
1 change: 1 addition & 0 deletions IntentsExtension/Support Files/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<key>IntentsSupported</key>
<array>
<string>AppendNoteIntent</string>
<string>CreateNewNoteIntent</string>
<string>FindNoteIntent</string>
<string>OpenNewNoteIntent</string>
<string>OpenNoteIntent</string>
Expand Down
4 changes: 4 additions & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2.21
-----
- Added shortcuts to Simplenote Mac!!

2.20
-----
- Added spotlight search support for notes
Expand Down
4 changes: 4 additions & 0 deletions Simplenote.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@
BA4C6D16264CA8C000B723A7 /* SignupRemoteTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA4C6D15264CA8C000B723A7 /* SignupRemoteTests.swift */; };
BA4C6D18264CAAF800B723A7 /* URLRequest+Simplenote.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA4C6D17264CAAF800B723A7 /* URLRequest+Simplenote.swift */; };
BA54F2462C0E63C700DBCE9D /* AppendNoteIntentHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA54F2452C0E63C700DBCE9D /* AppendNoteIntentHandler.swift */; };
BA54F2482C0E6A6900DBCE9D /* CreateNewNoteIntentHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA54F2472C0E6A6900DBCE9D /* CreateNewNoteIntentHandler.swift */; };
BA553F0927065E20007737E9 /* FontSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA553F0727065E20007737E9 /* FontSettings.swift */; };
BA5A658C2C090F4800F605A6 /* SharedStorageMigratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA5A658B2C090F4800F605A6 /* SharedStorageMigratorTests.swift */; };
BA5A658F2C090FEC00F605A6 /* FileManagerProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA5A658E2C090FEC00F605A6 /* FileManagerProtocol.swift */; };
Expand Down Expand Up @@ -704,6 +705,7 @@
BA52005A2BC878F1003F1B75 /* CSSearchable+Helpers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CSSearchable+Helpers.swift"; sourceTree = "<group>"; };
BA52005C2BC88397003F1B75 /* NSManagedObjectContext+Simplenote.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSManagedObjectContext+Simplenote.swift"; sourceTree = "<group>"; };
BA54F2452C0E63C700DBCE9D /* AppendNoteIntentHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppendNoteIntentHandler.swift; sourceTree = "<group>"; };
BA54F2472C0E6A6900DBCE9D /* CreateNewNoteIntentHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateNewNoteIntentHandler.swift; sourceTree = "<group>"; };
BA553F0727065E20007737E9 /* FontSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FontSettings.swift; sourceTree = "<group>"; };
BA5A658B2C090F4800F605A6 /* SharedStorageMigratorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SharedStorageMigratorTests.swift; sourceTree = "<group>"; };
BA5A658E2C090FEC00F605A6 /* FileManagerProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileManagerProtocol.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1640,6 +1642,7 @@
BAC5DFB82C079E5A002AD7EF /* OpenNoteIntentHandler.swift */,
BA2BF33F2C07C75500A7C894 /* FindNoteIntentHandler.swift */,
BA54F2452C0E63C700DBCE9D /* AppendNoteIntentHandler.swift */,
BA54F2472C0E6A6900DBCE9D /* CreateNewNoteIntentHandler.swift */,
);
path = IntentHandlers;
sourceTree = "<group>";
Expand Down Expand Up @@ -2236,6 +2239,7 @@
BACA68792C0A7608005409C1 /* KeychainManager.swift in Sources */,
BAB261762BFFD319009A98D7 /* OpenNewNoteIntentHandler.swift in Sources */,
BA2BF3402C07C75500A7C894 /* FindNoteIntentHandler.swift in Sources */,
BA54F2482C0E6A6900DBCE9D /* CreateNewNoteIntentHandler.swift in Sources */,
BAAA71D72C07A11500244C01 /* Note+Intents.swift in Sources */,
BAAA71D82C07A12F00244C01 /* NoteContentHelper.swift in Sources */,
BAAA71EA2C07A58100244C01 /* Simplenote.xcdatamodeld in Sources */,
Expand Down
97 changes: 97 additions & 0 deletions Simplenote/ShortcutIntents.intentdefinition
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,103 @@
<key>INIntentVerb</key>
<string>Do</string>
</dict>
<dict>
<key>INIntentCategory</key>
<string>generic</string>
<key>INIntentConfigurable</key>
<true/>
<key>INIntentDescription</key>
<string>Creates a note with supplied content and save it in Simplenote</string>
<key>INIntentDescriptionID</key>
<string>mekg4S</string>
<key>INIntentIneligibleForSuggestions</key>
<true/>
<key>INIntentInput</key>
<string>content</string>
<key>INIntentLastParameterTag</key>
<integer>1</integer>
<key>INIntentManagedParameterCombinations</key>
<dict>
<key>content</key>
<dict>
<key>INIntentParameterCombinationSupportsBackgroundExecution</key>
<true/>
<key>INIntentParameterCombinationTitle</key>
<string>Create new note with ${content}</string>
<key>INIntentParameterCombinationTitleID</key>
<string>Fjvqm6</string>
<key>INIntentParameterCombinationUpdatesLinked</key>
<true/>
</dict>
</dict>
<key>INIntentName</key>
<string>CreateNewNote</string>
<key>INIntentParameters</key>
<array>
<dict>
<key>INIntentParameterConfigurable</key>
<true/>
<key>INIntentParameterDisplayName</key>
<string>Content</string>
<key>INIntentParameterDisplayNameID</key>
<string>mH6JsQ</string>
<key>INIntentParameterDisplayPriority</key>
<integer>1</integer>
<key>INIntentParameterMetadata</key>
<dict>
<key>INIntentParameterMetadataCapitalization</key>
<string>Sentences</string>
<key>INIntentParameterMetadataDefaultValueID</key>
<string>Zjifxw</string>
</dict>
<key>INIntentParameterName</key>
<string>content</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>
</array>
<key>INIntentParameterTag</key>
<integer>1</integer>
<key>INIntentParameterType</key>
<string>String</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>
</dict>
<key>INIntentTitle</key>
<string>Create New Note With Content</string>
<key>INIntentTitleID</key>
<string>2jZ9yi</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 @@ -57,6 +57,7 @@
<key>NSUserActivityTypes</key>
<array>
<string>AppendNoteIntent</string>
<string>CreateNewNoteIntent</string>
<string>FindNoteIntent</string>
<string>OpenNewNoteIntent</string>
<string>OpenNoteIntent</string>
Expand Down