Intents (WIP)

This commit is contained in:
Matt Kiazyk 2021-12-08 15:31:59 -06:00
parent 49746e4b81
commit 387640f2ff
No known key found for this signature in database
GPG key ID: 33D9938D5D45EFE2
5 changed files with 346 additions and 1 deletions

View file

@ -102,6 +102,7 @@
CAFE4ABC25B7D54B0064FE51 /* UpdatesPreferencePane.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAFE4ABB25B7D54B0064FE51 /* UpdatesPreferencePane.swift */; };
CAFFFED8259CDA5000903F81 /* XcodeListViewRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAFFFED7259CDA5000903F81 /* XcodeListViewRow.swift */; };
E87DD6EB25D053FA00D86808 /* Progress+.swift in Sources */ = {isa = PBXBuildFile; fileRef = E87DD6EA25D053FA00D86808 /* Progress+.swift */; };
E886ED08273D7D2F00CD81A2 /* Intents.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = E886ED07273D7D2F00CD81A2 /* Intents.intentdefinition */; };
E89342FA25EDCC17007CF557 /* NotificationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = E89342F925EDCC17007CF557 /* NotificationManager.swift */; };
E8977EA325C11E1500835F80 /* PreferencesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8977EA225C11E1500835F80 /* PreferencesView.swift */; };
E8DA461125FAF7FB002E85EF /* NotificationsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8DA461025FAF7FB002E85EF /* NotificationsView.swift */; };
@ -270,6 +271,7 @@
CAFFFED7259CDA5000903F81 /* XcodeListViewRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XcodeListViewRow.swift; sourceTree = "<group>"; };
CAFFFEEE259CEAC400903F81 /* RingProgressViewStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RingProgressViewStyle.swift; sourceTree = "<group>"; };
E87DD6EA25D053FA00D86808 /* Progress+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Progress+.swift"; sourceTree = "<group>"; };
E886ED07273D7D2F00CD81A2 /* Intents.intentdefinition */ = {isa = PBXFileReference; lastKnownFileType = file.intentdefinition; path = Intents.intentdefinition; sourceTree = "<group>"; };
E89342F925EDCC17007CF557 /* NotificationManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationManager.swift; sourceTree = "<group>"; };
E8977EA225C11E1500835F80 /* PreferencesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesView.swift; sourceTree = "<group>"; };
E8DA461025FAF7FB002E85EF /* NotificationsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationsView.swift; sourceTree = "<group>"; };
@ -484,6 +486,7 @@
CA9FF83E2594FBC000E47BAF /* Licenses.rtf */,
CAD2E7AE2449575000113D76 /* Xcodes.entitlements */,
CA8FB64D256E17B100469DA5 /* XcodesTest.entitlements */,
E886ED07273D7D2F00CD81A2 /* Intents.intentdefinition */,
);
path = Resources;
sourceTree = "<group>";
@ -823,6 +826,7 @@
CABFA9C72592EEEA00380FEE /* Entry+.swift in Sources */,
CAE424B4259A764700B8B246 /* AppState+Install.swift in Sources */,
CAE42487259A68A300B8B246 /* XcodeListCategory.swift in Sources */,
E886ED08273D7D2F00CD81A2 /* Intents.intentdefinition in Sources */,
CAA858C425A2BE4E00ACF8C0 /* Downloader.swift in Sources */,
E8977EA325C11E1500835F80 /* PreferencesView.swift in Sources */,
CA9FF87B2595293E00E47BAF /* DataSource.swift in Sources */,
@ -941,6 +945,7 @@
ENABLE_HARDENED_RUNTIME = NO;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = Xcodes/Resources/Info.plist;
INTENTS_CODEGEN_LANGUAGE = Swift;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
@ -1177,6 +1182,7 @@
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = Xcodes/Resources/Info.plist;
INTENTS_CODEGEN_LANGUAGE = Swift;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
@ -1200,6 +1206,7 @@
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = Xcodes/Resources/Info.plist;
INTENTS_CODEGEN_LANGUAGE = Swift;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",

View file

@ -22,6 +22,12 @@
<string>8</string>
<key>CODE_SIGNING_SUBJECT_ORGANIZATIONAL_UNIT</key>
<string>$(CODE_SIGNING_SUBJECT_ORGANIZATIONAL_UNIT)</string>
<key>INIntentsSupported</key>
<array>
<string>DownloadXcodeVersionIntent</string>
</array>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSHumanReadableCopyright</key>
@ -32,6 +38,10 @@
<true/>
<key>NSSupportsSuddenTermination</key>
<true/>
<key>NSUserActivityTypes</key>
<array>
<string>DownloadXcodeVersionIntent</string>
</array>
<key>SMPrivilegedExecutables</key>
<dict>
<key>com.robotsandpencils.XcodesApp.Helper</key>

View file

@ -0,0 +1,273 @@
<?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>DDibcP</string>
<key>INIntentDefinitionSystemVersion</key>
<string>21A559</string>
<key>INIntentDefinitionToolsBuildVersion</key>
<string>13A1030d</string>
<key>INIntentDefinitionToolsVersion</key>
<string>13.1</string>
<key>INIntents</key>
<array>
<dict>
<key>INIntentCategory</key>
<string>download</string>
<key>INIntentConfigurable</key>
<true/>
<key>INIntentDescription</key>
<string>Downloads a specific xcode version from input</string>
<key>INIntentDescriptionID</key>
<string>7WiRvz</string>
<key>INIntentInput</key>
<string>version</string>
<key>INIntentKeyParameter</key>
<string>version</string>
<key>INIntentLastParameterTag</key>
<integer>4</integer>
<key>INIntentManagedParameterCombinations</key>
<dict>
<key>version</key>
<dict>
<key>INIntentParameterCombinationSupportsBackgroundExecution</key>
<true/>
<key>INIntentParameterCombinationTitle</key>
<string>Download Xcode ${version}</string>
<key>INIntentParameterCombinationTitleID</key>
<string>PjUEKy</string>
<key>INIntentParameterCombinationUpdatesLinked</key>
<true/>
</dict>
</dict>
<key>INIntentName</key>
<string>DownloadXcodeVersion</string>
<key>INIntentParameterCombinations</key>
<dict>
<key>version</key>
<dict>
<key>INIntentParameterCombinationSubtitle</key>
<string>Downloads a specific Xcode version</string>
<key>INIntentParameterCombinationSubtitleID</key>
<string>Jm4PtV</string>
<key>INIntentParameterCombinationSupportsBackgroundExecution</key>
<true/>
<key>INIntentParameterCombinationTitle</key>
<string>Download Xcode ${version}</string>
<key>INIntentParameterCombinationTitleID</key>
<string>hxK8St</string>
</dict>
</dict>
<key>INIntentParameters</key>
<array>
<dict>
<key>INIntentParameterConfigurable</key>
<true/>
<key>INIntentParameterCustomDisambiguation</key>
<true/>
<key>INIntentParameterDisplayName</key>
<string>Version</string>
<key>INIntentParameterDisplayNameID</key>
<string>xX1Nlk</string>
<key>INIntentParameterDisplayPriority</key>
<integer>1</integer>
<key>INIntentParameterName</key>
<string>version</string>
<key>INIntentParameterObjectType</key>
<string>XcodeVersion</string>
<key>INIntentParameterObjectTypeNamespace</key>
<string>DDibcP</string>
<key>INIntentParameterPromptDialogs</key>
<array>
<dict>
<key>INIntentParameterPromptDialogCustom</key>
<true/>
<key>INIntentParameterPromptDialogFormatString</key>
<string>Xcode version</string>
<key>INIntentParameterPromptDialogFormatStringID</key>
<string>QtXNi5</string>
<key>INIntentParameterPromptDialogType</key>
<string>Configuration</string>
</dict>
<dict>
<key>INIntentParameterPromptDialogCustom</key>
<true/>
<key>INIntentParameterPromptDialogFormatString</key>
<string>What version would you like to download?</string>
<key>INIntentParameterPromptDialogFormatStringID</key>
<string>GMl6KP</string>
<key>INIntentParameterPromptDialogType</key>
<string>Primary</string>
</dict>
<dict>
<key>INIntentParameterPromptDialogCustom</key>
<true/>
<key>INIntentParameterPromptDialogFormatString</key>
<string>There are ${count} options matching ${version}.</string>
<key>INIntentParameterPromptDialogFormatStringID</key>
<string>fShjJB</string>
<key>INIntentParameterPromptDialogType</key>
<string>DisambiguationIntroduction</string>
</dict>
<dict>
<key>INIntentParameterPromptDialogCustom</key>
<true/>
<key>INIntentParameterPromptDialogFormatString</key>
<string>Just to confirm, you wanted ${version}?</string>
<key>INIntentParameterPromptDialogFormatStringID</key>
<string>oWUTBx</string>
<key>INIntentParameterPromptDialogType</key>
<string>Confirmation</string>
</dict>
</array>
<key>INIntentParameterSupportsDynamicEnumeration</key>
<true/>
<key>INIntentParameterSupportsResolution</key>
<true/>
<key>INIntentParameterSupportsSearch</key>
<true/>
<key>INIntentParameterTag</key>
<integer>4</integer>
<key>INIntentParameterType</key>
<string>Object</string>
<key>INIntentParameterUnsupportedReasons</key>
<array>
<dict>
<key>INIntentParameterUnsupportedReasonCode</key>
<string>invalidVersion</string>
<key>INIntentParameterUnsupportedReasonCustom</key>
<true/>
<key>INIntentParameterUnsupportedReasonFormatString</key>
<string>Could not find the Xcode version ${version}</string>
<key>INIntentParameterUnsupportedReasonFormatStringID</key>
<string>u1xTKA</string>
</dict>
</array>
</dict>
</array>
<key>INIntentResponse</key>
<dict>
<key>INIntentResponseCodes</key>
<array>
<dict>
<key>INIntentResponseCodeConciseFormatString</key>
<string>Xcode ${versionString} is downloading. Please be patient.</string>
<key>INIntentResponseCodeConciseFormatStringID</key>
<string>TOpF4C</string>
<key>INIntentResponseCodeFormatString</key>
<string>Xcode ${versionString} is downloading. Please be patient.</string>
<key>INIntentResponseCodeFormatStringID</key>
<string>pZhmmj</string>
<key>INIntentResponseCodeName</key>
<string>success</string>
<key>INIntentResponseCodeSuccess</key>
<true/>
</dict>
<dict>
<key>INIntentResponseCodeName</key>
<string>failure</string>
</dict>
</array>
<key>INIntentResponseLastParameterTag</key>
<integer>2</integer>
<key>INIntentResponseParameters</key>
<array>
<dict>
<key>INIntentResponseParameterDisplayName</key>
<string>Version String</string>
<key>INIntentResponseParameterDisplayNameID</key>
<string>8kV4Bo</string>
<key>INIntentResponseParameterDisplayPriority</key>
<integer>1</integer>
<key>INIntentResponseParameterName</key>
<string>versionString</string>
<key>INIntentResponseParameterTag</key>
<integer>2</integer>
<key>INIntentResponseParameterType</key>
<string>String</string>
</dict>
</array>
</dict>
<key>INIntentTitle</key>
<string>Download Xcode Version</string>
<key>INIntentTitleID</key>
<string>9PPOeK</string>
<key>INIntentType</key>
<string>Custom</string>
<key>INIntentVerb</key>
<string>Download</string>
</dict>
</array>
<key>INTypes</key>
<array>
<dict>
<key>INTypeDisplayName</key>
<string>Xcode Version</string>
<key>INTypeDisplayNameID</key>
<string>eCDGVR</string>
<key>INTypeLastPropertyTag</key>
<integer>99</integer>
<key>INTypeName</key>
<string>XcodeVersion</string>
<key>INTypeProperties</key>
<array>
<dict>
<key>INTypePropertyDefault</key>
<true/>
<key>INTypePropertyDisplayPriority</key>
<integer>1</integer>
<key>INTypePropertyName</key>
<string>identifier</string>
<key>INTypePropertyTag</key>
<integer>1</integer>
<key>INTypePropertyType</key>
<string>String</string>
</dict>
<dict>
<key>INTypePropertyDefault</key>
<true/>
<key>INTypePropertyDisplayPriority</key>
<integer>2</integer>
<key>INTypePropertyName</key>
<string>displayString</string>
<key>INTypePropertyTag</key>
<integer>2</integer>
<key>INTypePropertyType</key>
<string>String</string>
</dict>
<dict>
<key>INTypePropertyDefault</key>
<true/>
<key>INTypePropertyDisplayPriority</key>
<integer>3</integer>
<key>INTypePropertyName</key>
<string>pronunciationHint</string>
<key>INTypePropertyTag</key>
<integer>3</integer>
<key>INTypePropertyType</key>
<string>String</string>
</dict>
<dict>
<key>INTypePropertyDefault</key>
<true/>
<key>INTypePropertyDisplayPriority</key>
<integer>4</integer>
<key>INTypePropertyName</key>
<string>alternativeSpeakableMatches</string>
<key>INTypePropertySupportsMultipleValues</key>
<true/>
<key>INTypePropertyTag</key>
<integer>4</integer>
<key>INTypePropertyType</key>
<string>SpeakableString</string>
</dict>
</array>
</dict>
</array>
</dict>
</plist>

View file

@ -1,4 +1,4 @@
{\rtf1\ansi\ansicpg1252\cocoartf2580
{\rtf1\ansi\ansicpg1252\cocoartf2636
\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fnil\fcharset0 .SFNS-Regular;}
{\colortbl;\red255\green255\blue255;}
{\*\expandedcolortbl;;}

View file

@ -1,6 +1,7 @@
import AppKit
import Sparkle
import SwiftUI
import Intents
@main
struct XcodesApp: App {
@ -120,4 +121,58 @@ class AppDelegate: NSObject, NSApplicationDelegate {
// Initialize manually
SUUpdater.shared()
}
func application(_ application: NSApplication, handlerFor intent: INIntent) -> Any? {
if intent is DownloadXcodeVersionIntent {
return IntentHandler()
}
return nil
}
}
class IntentHandler: NSObject, DownloadXcodeVersionIntentHandling {
var appState: AppState = AppState()
func provideVersionOptionsCollection(for intent: DownloadXcodeVersionIntent, searchTerm: String?, with completion: @escaping (INObjectCollection<XcodeVersion>?, Error?) -> Void) {
guard let searchTerm = searchTerm else {
return
}
let xcodes = appState.allXcodes.filter { $0.description.contains(searchTerm) }
let versions: [XcodeVersion] = xcodes.map { XcodeVersion(identifier: $0.id.appleDescription, display: $0.description)}
completion(INObjectCollection(items: versions), nil)
}
// check the version parameter
func resolveVersion(for intent: DownloadXcodeVersionIntent, with completion: @escaping (DownloadXcodeVersionVersionResolutionResult) -> Void) {
guard let version = intent.version else {
return completion(.needsValue())
}
return completion(.success(with: version))
}
func handle(intent: DownloadXcodeVersionIntent, completion: @escaping (DownloadXcodeVersionIntentResponse) -> Void) {
// do actual downloading
let response = DownloadXcodeVersionIntentResponse(code: .success, userActivity: nil)
response.versionString = intent.version?.description
completion(response)
}
// func provideVersionOptionsCollection(for intent: DownloadXcodeVersionIntent, searchTerm: String?, with completion: @escaping (INObjectCollection<Type>?, Error?) -> Void) {
// guard let searchTerm = searchTerm else {
// return
// }
//
// let xcodes = appState.allXcodes.filter { $0.description.contains(searchTerm) }
// let versions: [NSString] = xcodes.map { $0.version.descriptionWithoutBuildMetadata }
// let xcodeVersions = INObjectCollection(items: xcodes)
// }
}