Skip to content

Commit

Permalink
Test trying to add intents
Browse files Browse the repository at this point in the history
  • Loading branch information
Snesnopic committed May 27, 2024
1 parent 76b8883 commit bf98dbe
Show file tree
Hide file tree
Showing 6 changed files with 263 additions and 4 deletions.
52 changes: 52 additions & 0 deletions IntentHandler.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// IntentHandler.swift
// Morser
//
// Created by Giuseppe Francione on 27/05/24.
//

import Foundation
import Intents

class EncodeMorseIntentHandler: NSObject, EncodeMorseIntentHandling {
func resolveSentence(for intent: EncodeMorseIntent, with completion: @escaping (INStringResolutionResult) -> Void) {
guard let inputText = intent.sentence else {
completion(INStringResolutionResult.success(with: "Invalid input"))
return
}

// Trigger vibration (assuming you have this function)
VibrationEngine.shared.createEngine()
VibrationEngine.shared.readMorseCode(morseCode: inputText.morseCode())

// Respond with a success message
let response = INStringResolutionResult.success(with: "Vibrating...")
completion(response)
}

// func handle(intent: EncodeMorseIntent, completion: @escaping (EncodeMorseIntentResponse) -> Void) {
// guard let inputText = intent.inputText else {
// completion(EncodeMorseIntentResponse.failure(error: "Invalid input"))
// return
// }
//
// // Encode the inputText to Morse code
// let morseCode = encodeToMorse(inputText)
//
// // Trigger vibration (assuming you have this function)
// vibrateMorse(morseCode)
//
// // Respond with a success message
// let response = EncodeMorseIntentResponse.success(result: morseCode)
// completion(response)
// }
//
func encodeToMorse(_ text: String) -> String {
// Use your existing Morse code encoding logic here
return "..." // Example placeholder
}

func vibrateMorse(_ morseCode: String) {
// Use your existing vibration logic here
}
}
164 changes: 164 additions & 0 deletions Intents.intentdefinition
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>INEnums</key>
<array/>
<key>INIntentDefinitionModelVersion</key>
<string>1.2</string>
<key>INIntentDefinitionNamespace</key>
<string>HmvOxA</string>
<key>INIntentDefinitionSystemVersion</key>
<string>23F79</string>
<key>INIntentDefinitionToolsBuildVersion</key>
<string>15F31d</string>
<key>INIntentDefinitionToolsVersion</key>
<string>15.4</string>
<key>INIntents</key>
<array>
<dict>
<key>INIntentCategory</key>
<string>generic</string>
<key>INIntentConfigurable</key>
<true/>
<key>INIntentDeprecated</key>
<true/>
<key>INIntentDescription</key>
<string>Quickly encode and vibrate a sentence.</string>
<key>INIntentDescriptionID</key>
<string>EHqMhZ</string>
<key>INIntentEligibleForWidgets</key>
<true/>
<key>INIntentInput</key>
<string>sentence</string>
<key>INIntentKeyParameter</key>
<string>sentence</string>
<key>INIntentLastParameterTag</key>
<integer>1</integer>
<key>INIntentManagedParameterCombinations</key>
<dict>
<key>sentence</key>
<dict>
<key>INIntentParameterCombinationSupportsBackgroundExecution</key>
<true/>
<key>INIntentParameterCombinationTitle</key>
<string>Encode to morse and vibrate</string>
<key>INIntentParameterCombinationTitleID</key>
<string>ltlfaB</string>
<key>INIntentParameterCombinationUpdatesLinked</key>
<true/>
</dict>
</dict>
<key>INIntentName</key>
<string>EncodeMorse</string>
<key>INIntentParameterCombinations</key>
<dict>
<key>sentence</key>
<dict>
<key>INIntentParameterCombinationSubtitle</key>
<string>Dai</string>
<key>INIntentParameterCombinationSubtitleID</key>
<string>osFF9b</string>
<key>INIntentParameterCombinationSupportsBackgroundExecution</key>
<true/>
<key>INIntentParameterCombinationTitle</key>
<string>Encode to morse and vibrate</string>
<key>INIntentParameterCombinationTitleID</key>
<string>uKKLa2</string>
</dict>
</dict>
<key>INIntentParameters</key>
<array>
<dict>
<key>INIntentParameterConfigurable</key>
<true/>
<key>INIntentParameterDisplayName</key>
<string>Sentence to encode</string>
<key>INIntentParameterDisplayNameID</key>
<string>DeikLP</string>
<key>INIntentParameterDisplayPriority</key>
<integer>1</integer>
<key>INIntentParameterMetadata</key>
<dict>
<key>INIntentParameterMetadataCapitalization</key>
<string>Sentences</string>
<key>INIntentParameterMetadataDefaultValue</key>
<string>SOS</string>
<key>INIntentParameterMetadataDefaultValueID</key>
<string>EUNF92</string>
</dict>
<key>INIntentParameterName</key>
<string>sentence</string>
<key>INIntentParameterPromptDialogs</key>
<array>
<dict>
<key>INIntentParameterPromptDialogCustom</key>
<true/>
<key>INIntentParameterPromptDialogType</key>
<string>Configuration</string>
</dict>
<dict>
<key>INIntentParameterPromptDialogCustom</key>
<true/>
<key>INIntentParameterPromptDialogFormatString</key>
<string>What sentence to encode?</string>
<key>INIntentParameterPromptDialogFormatStringID</key>
<string>ALzJpj</string>
<key>INIntentParameterPromptDialogType</key>
<string>Primary</string>
</dict>
</array>
<key>INIntentParameterSupportsResolution</key>
<true/>
<key>INIntentParameterTag</key>
<integer>1</integer>
<key>INIntentParameterType</key>
<string>String</string>
</dict>
</array>
<key>INIntentResponse</key>
<dict>
<key>INIntentResponseCodes</key>
<array>
<dict>
<key>INIntentResponseCodeConciseFormatString</key>
<string>test 456</string>
<key>INIntentResponseCodeConciseFormatStringID</key>
<string>Fg1mNP</string>
<key>INIntentResponseCodeFormatString</key>
<string>test 123</string>
<key>INIntentResponseCodeFormatStringID</key>
<string>q2y3Zg</string>
<key>INIntentResponseCodeName</key>
<string>success</string>
<key>INIntentResponseCodeSuccess</key>
<true/>
</dict>
<dict>
<key>INIntentResponseCodeConciseFormatString</key>
<string>test 101</string>
<key>INIntentResponseCodeConciseFormatStringID</key>
<string>FKIDO4</string>
<key>INIntentResponseCodeFormatString</key>
<string>test 789</string>
<key>INIntentResponseCodeFormatStringID</key>
<string>XbPyei</string>
<key>INIntentResponseCodeName</key>
<string>failure</string>
</dict>
</array>
</dict>
<key>INIntentTitle</key>
<string>Encode to Morse</string>
<key>INIntentTitleID</key>
<string>PNzBOv</string>
<key>INIntentType</key>
<string>Custom</string>
<key>INIntentVerb</key>
<string>Do</string>
</dict>
</array>
<key>INTypes</key>
<array/>
</dict>
</plist>
8 changes: 8 additions & 0 deletions Morser.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
9DAE65512C00E8CE00663324 /* WatchCommunicationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9DAE65502C00E8CE00663324 /* WatchCommunicationManager.swift */; };
9DAE65542C011BBD00663324 /* BeepPlayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9DD425092BE3C5BF009EE623 /* BeepPlayer.swift */; };
9DB015632C03C17A00BB18EB /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9D3DED2E2BCD109500DAD675 /* Assets.xcassets */; };
9DC14EC82C04DEE6008F8B18 /* Intents.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = 9DC14EC72C04DEE6008F8B18 /* Intents.intentdefinition */; };
9DC14ECA2C04DF86008F8B18 /* IntentHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9DC14EC92C04DF86008F8B18 /* IntentHandler.swift */; };
9DD162F82C038F78006A410D /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9DA6966F2BCD7154002B9CBB /* Extensions.swift */; };
9DD162F92C038F7B006A410D /* MorseEncoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D3DED412BCD248100DAD675 /* MorseEncoder.swift */; };
9DD162FA2C038F91006A410D /* Sentence.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 9D0CB0552BF5E78500FD8E57 /* Sentence.xcdatamodeld */; };
Expand Down Expand Up @@ -95,6 +97,8 @@
9DAE65432C00E68A00663324 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
9DAE654E2C00E89D00663324 /* WatchConnectivityProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WatchConnectivityProvider.swift; sourceTree = "<group>"; };
9DAE65502C00E8CE00663324 /* WatchCommunicationManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WatchCommunicationManager.swift; sourceTree = "<group>"; };
9DC14EC72C04DEE6008F8B18 /* Intents.intentdefinition */ = {isa = PBXFileReference; lastKnownFileType = file.intentdefinition; path = Intents.intentdefinition; sourceTree = "<group>"; };
9DC14EC92C04DF86008F8B18 /* IntentHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntentHandler.swift; sourceTree = "<group>"; };
9DD162FC2C0397A3006A410D /* EncodeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EncodeView.swift; sourceTree = "<group>"; };
9DD163042C03A512006A410D /* QuickTranslateView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuickTranslateView.swift; sourceTree = "<group>"; };
9DD163062C03A89C006A410D /* MorserWatch-Watch-App-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = "MorserWatch-Watch-App-Info.plist"; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -139,6 +143,8 @@
9D3DED1E2BCD109400DAD675 = {
isa = PBXGroup;
children = (
9DC14EC92C04DF86008F8B18 /* IntentHandler.swift */,
9DC14EC72C04DEE6008F8B18 /* Intents.intentdefinition */,
9DED8FBB2BF793B9008D0B29 /* .swiftlint.yml */,
9D3DED292BCD109400DAD675 /* Morser */,
9DAE653B2C00E68900663324 /* MorserWatch Watch App */,
Expand Down Expand Up @@ -362,13 +368,15 @@
files = (
9DD4250A2BE3C5BF009EE623 /* BeepPlayer.swift in Sources */,
9D3DED2D2BCD109400DAD675 /* ParentView.swift in Sources */,
9DC14EC82C04DEE6008F8B18 /* Intents.intentdefinition in Sources */,
9DD801DB2C04B630007DEC31 /* TorchEngine.swift in Sources */,
9D1CB9B02BCEB5930088F90C /* SpeechRecognizer.swift in Sources */,
9D3DED3C2BCD16DE00DAD675 /* QuickTranslateView.swift in Sources */,
9D3DED402BCD23E700DAD675 /* VibrationEngine.swift in Sources */,
9DA696702BCD7154002B9CBB /* Extensions.swift in Sources */,
9D0CB0592BF5E87F00FD8E57 /* DataController.swift in Sources */,
9D3DED3E2BCD16EB00DAD675 /* ListenView.swift in Sources */,
9DC14ECA2C04DF86008F8B18 /* IntentHandler.swift in Sources */,
9D0CB0572BF5E78500FD8E57 /* Sentence.xcdatamodeld in Sources */,
9D3DED2B2BCD109400DAD675 /* MorserApp.swift in Sources */,
9D7F43402C00C4BB00DB6DE3 /* ExpandingCircle.swift in Sources */,
Expand Down
13 changes: 13 additions & 0 deletions Morser/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSUserActivityTypes</key>
<array>
<string>EncodeMorseIntent</string>
</array>
<key>UIApplicationShortcutItems</key>
<array>
<dict>
<key>UIApplicationShortcutItemTitle</key>
<string>Encode Morse</string>
<key>UIApplicationShortcutItemType</key>
<string>com.snesnopic.morser</string>
</dict>
</array>
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
Expand Down
10 changes: 6 additions & 4 deletions Morser/Morser.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
<key>com.apple.developer.siri</key>
<true/>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
</dict>
</plist>
20 changes: 20 additions & 0 deletions Morser/Views/MorserApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,29 @@ struct MorserApp: App {
}
}

import Intents
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
WatchConnectivityProvider.shared.activate()
return true
}
func application(_ application: UIApplication, handlerFor intent: INIntent) -> Any? {
if intent is EncodeMorseIntent {
return EncodeMorseIntentHandler()
}
return nil
}
func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
if shortcutItem.type == "com.snesnopic.morser" {
// Handle the quick action
// Present a view controller or encode a predefined text
let text = "Sample text"
VibrationEngine.shared.createEngine()
VibrationEngine.shared.readMorseCode(morseCode: text.morseCode())
completionHandler(true)
} else {
completionHandler(false)
}
}

}

0 comments on commit bf98dbe

Please sign in to comment.