Skip to content

Commit 8e736a4

Browse files
committed
App shortcuts (iOS 16+) support
1 parent bda3aea commit 8e736a4

File tree

13 files changed

+189
-5
lines changed

13 files changed

+189
-5
lines changed

Intents.swift

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import AppIntents
2+
import UIKit
3+
4+
@available(iOS 16.0, *)
5+
struct AmberOnIntent: AppIntent {
6+
static let title: LocalizedStringResource = "Amber On"
7+
static let description = IntentDescription(
8+
"Turn on all amber LEDs",
9+
categoryName: "Device"
10+
)
11+
static let openAppWhenRun: Bool = true
12+
13+
func perform() async throws -> some IntentResult {
14+
if let url = URL(string: "leds://com.ps.TrollLEDs.AmberOn") {
15+
if await UIApplication.shared.canOpenURL(url) {
16+
await UIApplication.shared.open(url)
17+
}
18+
}
19+
return .result()
20+
}
21+
}
22+
23+
@available(iOS 16.0, *)
24+
struct WhiteOnIntent: AppIntent {
25+
static let title: LocalizedStringResource = "White On"
26+
static let description = IntentDescription(
27+
"Turn on all white LEDs",
28+
categoryName: "Device"
29+
)
30+
static let openAppWhenRun: Bool = true
31+
32+
func perform() async throws -> some IntentResult {
33+
if let url = URL(string: "leds://com.ps.TrollLEDs.WhiteOn") {
34+
if await UIApplication.shared.canOpenURL(url) {
35+
await UIApplication.shared.open(url)
36+
}
37+
}
38+
return .result()
39+
}
40+
}
41+
42+
@available(iOS 16.0, *)
43+
struct AllOnIntent: AppIntent {
44+
static let title: LocalizedStringResource = "All On"
45+
static let description = IntentDescription(
46+
"Turn on all LEDs",
47+
categoryName: "Device"
48+
)
49+
static let openAppWhenRun: Bool = true
50+
51+
func perform() async throws -> some IntentResult {
52+
if let url = URL(string: "leds://com.ps.TrollLEDs.AllOn") {
53+
if await UIApplication.shared.canOpenURL(url) {
54+
await UIApplication.shared.open(url)
55+
}
56+
}
57+
return .result()
58+
}
59+
}

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
TARGET := iphone:clang:latest:11.0
22
INSTALL_TARGET_PROCESSES = TrollLEDs
33
ARCHS = arm64
4-
PACKAGE_VERSION = 1.6.1
4+
PACKAGE_VERSION = 1.7.0
55

66
include $(THEOS)/makefiles/common.mk
77

@@ -13,7 +13,7 @@ else
1313
IPA_NAME = $(APPLICATION_NAME)
1414
endif
1515

16-
$(APPLICATION_NAME)_FILES = main.m TLDeviceManager.m TLSceneDelegate.m TLAppDelegate.m TLRootViewController.m
16+
$(APPLICATION_NAME)_FILES = main.m TLDeviceManager.m TLSceneDelegate.m TLAppDelegate.m TLRootViewController.m Intents.swift ShortcutsProvider.swift
1717
$(APPLICATION_NAME)_FRAMEWORKS = UIKit CoreGraphics CoreMedia
1818
$(APPLICATION_NAME)_CFLAGS = -fobjc-arc
1919
ifeq ($(UNSANDBOX),1)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,4 @@ Build `.tipa` (sandboxed and unsandboxed) and `.deb` (rootful and rootless) with
7575

7676
1. More accessible sliders (are they too small?)
7777
2. Better error handling?
78+
3. As AppIntents metadata can only be generated from Xcode, we should find a way to generate it from theos

Resources/Info.plist

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444
<string>iPhoneOS</string>
4545
</array>
4646
<key>CFBundleShortVersionString</key>
47-
<string>1.6.1</string>
47+
<string>1.7.0</string>
4848
<key>CFBundleVersion</key>
49-
<string>1.6.1</string>
49+
<string>1.7.0</string>
5050
<key>LSRequiresIPhoneOS</key>
5151
<true/>
5252
<key>MinimumOSVersion</key>
@@ -117,5 +117,16 @@
117117
<string>com.ps.TrollLEDs.AllOn</string>
118118
</dict>
119119
</array>
120+
<key>CFBundleURLTypes</key>
121+
<array>
122+
<dict>
123+
<key>CFBundleURLName</key>
124+
<string>com.ps.TrollLEDs</string>
125+
<key>CFBundleURLSchemes</key>
126+
<array>
127+
<string>leds</string>
128+
</array>
129+
</dict>
130+
</array>
120131
</dict>
121132
</plist>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"generator":{"version":"15.2","name":"xcode-tools"},"enums":[],"autoShortcutProviderMangledName":"9TrollLEDs0aB20AppShortcutsProviderV","entities":{},"autoShortcuts":[{"actionIdentifier":"AmberOnIntent","phraseTemplates":[{"key":"Turn on amber LEDs with ${applicationName}"}],"systemImageName":"flashlight.on.circle.fill","shortTitle":{"key":"Amber On"}},{"systemImageName":"flashlight.on.circle.fill","actionIdentifier":"WhiteOnIntent","shortTitle":{"key":"White On"},"phraseTemplates":[{"key":"Turn on white LEDs with ${applicationName}"}]},{"systemImageName":"flashlight.on.circle.fill","shortTitle":{"key":"All On"},"actionIdentifier":"AllOnIntent","phraseTemplates":[{"key":"Turn on all LEDs with ${applicationName}"}]}],"queries":{},"shortcutTileColor":14,"actions":{"AmberOnIntent":{"parameters":[],"presentationStyle":0,"identifier":"AmberOnIntent","outputFlags":0,"systemProtocols":[],"title":{"key":"Amber On"},"openAppWhenRun":true,"isDiscoverable":true,"mangledTypeNameByBundleIdentifier":{},"typeSpecificMetadata":[],"systemProtocolMetadata":[],"availabilityAnnotations":{"LNPlatformNameWildcard":{"introducedVersion":"*"},"LNPlatformNameIOS":{"introducedVersion":"16.0"}},"mangledTypeNameV2":"9TrollLEDs13AmberOnIntentV","mangledTypeName":"9TrollLEDs13AmberOnIntentV","effectiveBundleIdentifiers":[],"authenticationPolicy":0,"descriptionMetadata":{"descriptionText":{"key":"Turn on all amber LEDs"},"searchKeywords":[],"categoryName":{"title":{"key":"Device"}}},"requiredCapabilities":[],"mangledTypeNameByBundleIdentifierV2":{}},"WhiteOnIntent":{"identifier":"WhiteOnIntent","mangledTypeNameByBundleIdentifier":{},"isDiscoverable":true,"mangledTypeName":"9TrollLEDs13WhiteOnIntentV","requiredCapabilities":[],"openAppWhenRun":true,"authenticationPolicy":0,"mangledTypeNameByBundleIdentifierV2":{},"parameters":[],"typeSpecificMetadata":[],"descriptionMetadata":{"descriptionText":{"key":"Turn on all white LEDs"},"categoryName":{"title":{"key":"Device"}},"searchKeywords":[]},"systemProtocols":[],"presentationStyle":0,"outputFlags":0,"availabilityAnnotations":{"LNPlatformNameWildcard":{"introducedVersion":"*"},"LNPlatformNameIOS":{"introducedVersion":"16.0"}},"mangledTypeNameV2":"9TrollLEDs13WhiteOnIntentV","title":{"key":"White On"},"systemProtocolMetadata":[],"effectiveBundleIdentifiers":[]},"AllOnIntent":{"outputFlags":0,"systemProtocolMetadata":[],"availabilityAnnotations":{"LNPlatformNameWildcard":{"introducedVersion":"*"},"LNPlatformNameIOS":{"introducedVersion":"16.0"}},"presentationStyle":0,"isDiscoverable":true,"title":{"key":"All On"},"mangledTypeNameByBundleIdentifier":{},"descriptionMetadata":{"searchKeywords":[],"categoryName":{"title":{"key":"Device"}},"descriptionText":{"key":"Turn on all LEDs"}},"systemProtocols":[],"mangledTypeNameByBundleIdentifierV2":{},"parameters":[],"requiredCapabilities":[],"openAppWhenRun":true,"effectiveBundleIdentifiers":[],"authenticationPolicy":0,"mangledTypeName":"9TrollLEDs11AllOnIntentV","typeSpecificMetadata":[],"mangledTypeNameV2":"9TrollLEDs11AllOnIntentV","identifier":"AllOnIntent"}},"negativePhrases":[],"version":1}
Binary file not shown.
1.33 KB
Binary file not shown.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
apiVersion: ssu/v1
2+
nlu:
3+
shortcuts:
4+
bundleIdentifier: com.ps.TrollLEDs
5+
intents:
6+
- metadata:
7+
name: AmberOnIntent_0
8+
title: Amber On
9+
corpuses:
10+
training:
11+
- locale: en_US
12+
utterances:
13+
- Turn on amber LEDs with ${+applicationName}
14+
- metadata:
15+
name: WhiteOnIntent_1
16+
title: White On
17+
corpuses:
18+
training:
19+
- locale: en_US
20+
utterances:
21+
- Turn on white LEDs with ${+applicationName}
22+
- metadata:
23+
name: AllOnIntent_2
24+
title: All On
25+
corpuses:
26+
training:
27+
- locale: en_US
28+
utterances:
29+
- Turn on all LEDs with ${+applicationName}
30+
- metadata:
31+
name: +negative
32+
corpuses:
33+
training:
34+
- locale: en_US
35+
utterances:
36+
- ${+standardAppShortcutNegatives}
37+
variables:
38+
- name: +applicationName
39+
type: ssu/expansion
40+
definitions:
41+
- locale: en_US
42+
synomyms:
43+
- TrollLEDs
44+
- name: +prefix
45+
type: ssu/expansion
46+
definitions:
47+
- locale: en_US
48+
synomyms:
49+
$ref: ssu://Resources/prefix/en.yaml
50+
- name: +standardAppShortcutNegatives
51+
type: ssu/expansion
52+
definitions:
53+
- locale: en_US
54+
synomyms:
55+
$ref: ssu://Resources/standardAppShortcutNegatives/en.yaml
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"toolsVersion" : "15.2",
3+
"version" : "3.0"
4+
}

ShortcutsProvider.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import AppIntents
2+
3+
@available(iOS 16.0, *)
4+
struct TrollLEDsAppShortcutsProvider: AppShortcutsProvider {
5+
@AppShortcutsBuilder static var appShortcuts: [AppShortcut] {
6+
AppShortcut(
7+
intent: AmberOnIntent(),
8+
phrases: [
9+
"Turn on amber LEDs with \(.applicationName)"
10+
],
11+
shortTitle: "Amber On",
12+
systemImageName: "flashlight.on.circle.fill"
13+
)
14+
AppShortcut(
15+
intent: WhiteOnIntent(),
16+
phrases: [
17+
"Turn on white LEDs with \(.applicationName)"
18+
],
19+
shortTitle: "White On",
20+
systemImageName: "flashlight.on.circle.fill"
21+
)
22+
AppShortcut(
23+
intent: AllOnIntent(),
24+
phrases: [
25+
"Turn on all LEDs with \(.applicationName)"
26+
],
27+
shortTitle: "All On",
28+
systemImageName: "flashlight.on.circle.fill"
29+
)
30+
}
31+
}

0 commit comments

Comments
 (0)