Skip to content

Commit

Permalink
App shortcuts (iOS 16+) support
Browse files Browse the repository at this point in the history
  • Loading branch information
PoomSmart committed Feb 4, 2024
1 parent bda3aea commit 8e736a4
Show file tree
Hide file tree
Showing 13 changed files with 189 additions and 5 deletions.
59 changes: 59 additions & 0 deletions Intents.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import AppIntents
import UIKit

@available(iOS 16.0, *)
struct AmberOnIntent: AppIntent {
static let title: LocalizedStringResource = "Amber On"
static let description = IntentDescription(
"Turn on all amber LEDs",
categoryName: "Device"
)
static let openAppWhenRun: Bool = true

func perform() async throws -> some IntentResult {
if let url = URL(string: "leds://com.ps.TrollLEDs.AmberOn") {
if await UIApplication.shared.canOpenURL(url) {
await UIApplication.shared.open(url)
}
}
return .result()
}
}

@available(iOS 16.0, *)
struct WhiteOnIntent: AppIntent {
static let title: LocalizedStringResource = "White On"
static let description = IntentDescription(
"Turn on all white LEDs",
categoryName: "Device"
)
static let openAppWhenRun: Bool = true

func perform() async throws -> some IntentResult {
if let url = URL(string: "leds://com.ps.TrollLEDs.WhiteOn") {
if await UIApplication.shared.canOpenURL(url) {
await UIApplication.shared.open(url)
}
}
return .result()
}
}

@available(iOS 16.0, *)
struct AllOnIntent: AppIntent {
static let title: LocalizedStringResource = "All On"
static let description = IntentDescription(
"Turn on all LEDs",
categoryName: "Device"
)
static let openAppWhenRun: Bool = true

func perform() async throws -> some IntentResult {
if let url = URL(string: "leds://com.ps.TrollLEDs.AllOn") {
if await UIApplication.shared.canOpenURL(url) {
await UIApplication.shared.open(url)
}
}
return .result()
}
}
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
TARGET := iphone:clang:latest:11.0
INSTALL_TARGET_PROCESSES = TrollLEDs
ARCHS = arm64
PACKAGE_VERSION = 1.6.1
PACKAGE_VERSION = 1.7.0

include $(THEOS)/makefiles/common.mk

Expand All @@ -13,7 +13,7 @@ else
IPA_NAME = $(APPLICATION_NAME)
endif

$(APPLICATION_NAME)_FILES = main.m TLDeviceManager.m TLSceneDelegate.m TLAppDelegate.m TLRootViewController.m
$(APPLICATION_NAME)_FILES = main.m TLDeviceManager.m TLSceneDelegate.m TLAppDelegate.m TLRootViewController.m Intents.swift ShortcutsProvider.swift
$(APPLICATION_NAME)_FRAMEWORKS = UIKit CoreGraphics CoreMedia
$(APPLICATION_NAME)_CFLAGS = -fobjc-arc
ifeq ($(UNSANDBOX),1)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,4 @@ Build `.tipa` (sandboxed and unsandboxed) and `.deb` (rootful and rootless) with

1. More accessible sliders (are they too small?)
2. Better error handling?
3. As AppIntents metadata can only be generated from Xcode, we should find a way to generate it from theos
15 changes: 13 additions & 2 deletions Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
<string>iPhoneOS</string>
</array>
<key>CFBundleShortVersionString</key>
<string>1.6.1</string>
<string>1.7.0</string>
<key>CFBundleVersion</key>
<string>1.6.1</string>
<string>1.7.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>MinimumOSVersion</key>
Expand Down Expand Up @@ -117,5 +117,16 @@
<string>com.ps.TrollLEDs.AllOn</string>
</dict>
</array>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.ps.TrollLEDs</string>
<key>CFBundleURLSchemes</key>
<array>
<string>leds</string>
</array>
</dict>
</array>
</dict>
</plist>
1 change: 1 addition & 0 deletions Resources/Metadata.appintents/extract.actionsdata
Original file line number Diff line number Diff line change
@@ -0,0 +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.
Binary file added Resources/Metadata.appintents/nlu/en_US.nlu.lzfse
Binary file not shown.
55 changes: 55 additions & 0 deletions Resources/Metadata.appintents/root.ssu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
apiVersion: ssu/v1
nlu:
shortcuts:
bundleIdentifier: com.ps.TrollLEDs
intents:
- metadata:
name: AmberOnIntent_0
title: Amber On
corpuses:
training:
- locale: en_US
utterances:
- Turn on amber LEDs with ${+applicationName}
- metadata:
name: WhiteOnIntent_1
title: White On
corpuses:
training:
- locale: en_US
utterances:
- Turn on white LEDs with ${+applicationName}
- metadata:
name: AllOnIntent_2
title: All On
corpuses:
training:
- locale: en_US
utterances:
- Turn on all LEDs with ${+applicationName}
- metadata:
name: +negative
corpuses:
training:
- locale: en_US
utterances:
- ${+standardAppShortcutNegatives}
variables:
- name: +applicationName
type: ssu/expansion
definitions:
- locale: en_US
synomyms:
- TrollLEDs
- name: +prefix
type: ssu/expansion
definitions:
- locale: en_US
synomyms:
$ref: ssu://Resources/prefix/en.yaml
- name: +standardAppShortcutNegatives
type: ssu/expansion
definitions:
- locale: en_US
synomyms:
$ref: ssu://Resources/standardAppShortcutNegatives/en.yaml
4 changes: 4 additions & 0 deletions Resources/Metadata.appintents/version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"toolsVersion" : "15.2",
"version" : "3.0"
}
31 changes: 31 additions & 0 deletions ShortcutsProvider.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import AppIntents

@available(iOS 16.0, *)
struct TrollLEDsAppShortcutsProvider: AppShortcutsProvider {
@AppShortcutsBuilder static var appShortcuts: [AppShortcut] {
AppShortcut(
intent: AmberOnIntent(),
phrases: [
"Turn on amber LEDs with \(.applicationName)"
],
shortTitle: "Amber On",
systemImageName: "flashlight.on.circle.fill"
)
AppShortcut(
intent: WhiteOnIntent(),
phrases: [
"Turn on white LEDs with \(.applicationName)"
],
shortTitle: "White On",
systemImageName: "flashlight.on.circle.fill"
)
AppShortcut(
intent: AllOnIntent(),
phrases: [
"Turn on all LEDs with \(.applicationName)"
],
shortTitle: "All On",
systemImageName: "flashlight.on.circle.fill"
)
}
}
10 changes: 10 additions & 0 deletions TLAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,14 @@ - (void)appDidEnterBackground:(UIApplication *)application {
});
}

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {
if (!url) return NO;
if ([url.scheme isEqualToString:@"leds"]) {
NSString *action = url.host;
if (action)
[_myViewController handleShortcutAction:action];
}
return YES;
}

@end
12 changes: 12 additions & 0 deletions TLSceneDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,16 @@ - (void)sceneDidEnterBackground:(UIScene *)scene API_AVAILABLE(ios(13.0)) {
});
}

- (void)scene:(UIScene *)scene openURLContexts:(NSSet <UIOpenURLContext *> *)URLContexts API_AVAILABLE(ios(13.0)) {
for (UIOpenURLContext *context in URLContexts) {
NSURL *url = context.URL;
if (!url) continue;
if ([url.scheme isEqualToString:@"leds"]) {
NSString *action = url.host;
if (action)
[_myViewController handleShortcutAction:action];
}
}
}

@end
2 changes: 1 addition & 1 deletion control
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: com.ps.trollleds
Name: TrollLEDs
Version: 1.0.0
Depends: firmware (>= 11.0), gsc.camera-flash
Depends: firmware (>= 11.0), firmware (>= 12.2) | ${LIBSWIFT}, gsc.camera-flash
Architecture: iphoneos-arm
Description: Control flashlight LEDs with eases.
Maintainer: PoomSmart
Expand Down

0 comments on commit 8e736a4

Please sign in to comment.