Skip to content

Commit

Permalink
All Off, Manual Shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
PoomSmart committed Feb 4, 2024
1 parent 8e736a4 commit 8eb2cc7
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 69 deletions.
54 changes: 54 additions & 0 deletions Intents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,57 @@ struct AllOnIntent: AppIntent {
return .result()
}
}

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

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

@available(iOS 16.0, *)
struct ManualIntent: AppIntent {
static let title: LocalizedStringResource = "Manual"
static let description = IntentDescription(
"Configure LEDs levels manually (0 - 255) (For Quad-LEDs devices only)",
categoryName: "Device"
)
static let openAppWhenRun: Bool = true

@Parameter(title: "Cool LED 0", inclusiveRange: (0, 255))
var coolLED0: Int

@Parameter(title: "Cool LED 1", inclusiveRange: (0, 255))
var coolLED1: Int

@Parameter(title: "Warm LED 0", inclusiveRange: (0, 255))
var warmLED0: Int

@Parameter(title: "Warm LED 1", inclusiveRange: (0, 255))
var warmLED1: Int

static var parameterSummary: some ParameterSummary {
Summary("Configure LEDs levels to (\(\.$coolLED0), \(\.$coolLED1), \(\.$warmLED0), \(\.$warmLED1))")
}

func perform() async throws -> some IntentResult {
if let url = URL(string: "leds://com.ps.TrollLEDs.Manual?coolLED0=\(coolLED0)&coolLED1=\(coolLED1)&warmLED0=\(warmLED0)&warmLED1=\(warmLED1)") {
if await UIApplication.shared.canOpenURL(url) {
await UIApplication.shared.open(url)
}
}
return .result()
}
}
2 changes: 1 addition & 1 deletion 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.7.0
PACKAGE_VERSION = 1.8.0

include $(THEOS)/makefiles/common.mk

Expand Down
4 changes: 2 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.7.0</string>
<string>1.8.0</string>
<key>CFBundleVersion</key>
<string>1.7.0</string>
<string>1.8.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>MinimumOSVersion</key>
Expand Down
2 changes: 1 addition & 1 deletion Resources/Metadata.appintents/extract.actionsdata
Original file line number Diff line number Diff line change
@@ -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}
{"autoShortcuts":[{"actionIdentifier":"AmberOnIntent","shortTitle":{"key":"Amber On"},"phraseTemplates":[{"key":"Turn on amber LEDs with ${applicationName}"}],"systemImageName":"flashlight.on.circle.fill"},{"shortTitle":{"key":"White On"},"phraseTemplates":[{"key":"Turn on white LEDs with ${applicationName}"}],"actionIdentifier":"WhiteOnIntent","systemImageName":"flashlight.on.circle.fill"},{"actionIdentifier":"AllOnIntent","phraseTemplates":[{"key":"Turn on all LEDs with ${applicationName}"}],"shortTitle":{"key":"All On"},"systemImageName":"flashlight.on.circle.fill"},{"shortTitle":{"key":"All Off"},"systemImageName":"flashlight.off.circle.fill","phraseTemplates":[{"key":"Turn off all LEDs with ${applicationName}"}],"actionIdentifier":"AllOffIntent"},{"shortTitle":{"key":"Manual"},"systemImageName":"flashlight.on.circle.fill","actionIdentifier":"ManualIntent","phraseTemplates":[{"key":"Configure LEDs levels manually with ${applicationName}"}]}],"queries":{},"negativePhrases":[],"actions":{"ManualIntent":{"title":{"key":"Manual"},"parameters":[{"isOptional":false,"title":{"key":"Cool LED 0"},"dynamicOptionsSupport":0,"typeSpecificMetadata":["LNValueTypeMetadataKeyNumberRangeType",{"int":{"wrapper":0}},"LNValueTypeMetadataKeyNumberUpperBound",{"double":{"wrapper":255}},"LNValueTypeMetadataKeyNumberLowerBound",{"double":{"wrapper":0}}],"valueType":{"primitive":{"wrapper":{"typeIdentifier":2}}},"name":"coolLED0","inputConnectionBehavior":0,"resolvableInputTypes":[{"kindValue":0,"valueType":{"primitive":{"wrapper":{"typeIdentifier":2}}}},{"valueType":{"primitive":{"wrapper":{"typeIdentifier":7}}},"kindValue":0},{"kindValue":0,"valueType":{"primitive":{"wrapper":{"typeIdentifier":0}}}}],"isInput":false},{"valueType":{"primitive":{"wrapper":{"typeIdentifier":2}}},"dynamicOptionsSupport":0,"resolvableInputTypes":[{"valueType":{"primitive":{"wrapper":{"typeIdentifier":2}}},"kindValue":0},{"valueType":{"primitive":{"wrapper":{"typeIdentifier":7}}},"kindValue":0},{"kindValue":0,"valueType":{"primitive":{"wrapper":{"typeIdentifier":0}}}}],"title":{"key":"Cool LED 1"},"name":"coolLED1","typeSpecificMetadata":["LNValueTypeMetadataKeyNumberLowerBound",{"double":{"wrapper":0}},"LNValueTypeMetadataKeyNumberRangeType",{"int":{"wrapper":0}},"LNValueTypeMetadataKeyNumberUpperBound",{"double":{"wrapper":255}}],"isInput":false,"inputConnectionBehavior":0,"isOptional":false},{"isInput":false,"dynamicOptionsSupport":0,"title":{"key":"Warm LED 0"},"inputConnectionBehavior":0,"name":"warmLED0","isOptional":false,"valueType":{"primitive":{"wrapper":{"typeIdentifier":2}}},"resolvableInputTypes":[{"kindValue":0,"valueType":{"primitive":{"wrapper":{"typeIdentifier":2}}}},{"valueType":{"primitive":{"wrapper":{"typeIdentifier":7}}},"kindValue":0},{"kindValue":0,"valueType":{"primitive":{"wrapper":{"typeIdentifier":0}}}}],"typeSpecificMetadata":["LNValueTypeMetadataKeyNumberRangeType",{"int":{"wrapper":0}},"LNValueTypeMetadataKeyNumberLowerBound",{"double":{"wrapper":0}},"LNValueTypeMetadataKeyNumberUpperBound",{"double":{"wrapper":255}}]},{"isOptional":false,"isInput":false,"typeSpecificMetadata":["LNValueTypeMetadataKeyNumberUpperBound",{"double":{"wrapper":255}},"LNValueTypeMetadataKeyNumberLowerBound",{"double":{"wrapper":0}},"LNValueTypeMetadataKeyNumberRangeType",{"int":{"wrapper":0}}],"resolvableInputTypes":[{"valueType":{"primitive":{"wrapper":{"typeIdentifier":2}}},"kindValue":0},{"valueType":{"primitive":{"wrapper":{"typeIdentifier":7}}},"kindValue":0},{"kindValue":0,"valueType":{"primitive":{"wrapper":{"typeIdentifier":0}}}}],"title":{"key":"Warm LED 1"},"valueType":{"primitive":{"wrapper":{"typeIdentifier":2}}},"name":"warmLED1","inputConnectionBehavior":0,"dynamicOptionsSupport":0}],"openAppWhenRun":true,"isDiscoverable":true,"authenticationPolicy":0,"effectiveBundleIdentifiers":[],"outputFlags":0,"systemProtocols":[],"descriptionMetadata":{"searchKeywords":[],"categoryName":{"title":{"key":"Device"}},"descriptionText":{"key":"Configure LEDs levels manually (0 - 255) (For Quad-LEDs devices only)"}},"mangledTypeNameByBundleIdentifier":{},"systemProtocolMetadata":[],"typeSpecificMetadata":[],"mangledTypeNameV2":"9TrollLEDs12ManualIntentV","mangledTypeNameByBundleIdentifierV2":{},"availabilityAnnotations":{"LNPlatformNameIOS":{"introducedVersion":"16.0"},"LNPlatformNameWildcard":{"introducedVersion":"*"}},"requiredCapabilities":[],"actionConfiguration":{"actionSummary":{"wrapper":{"summaryString":{"parameterIdentifiers":["coolLED0","coolLED1","warmLED0","warmLED1"],"formatString":"Configure LEDs levels to (${coolLED0}, ${coolLED1}, ${warmLED0}, ${warmLED1})"},"otherParameterIdentifiers":[]}}},"mangledTypeName":"9TrollLEDs12ManualIntentV","presentationStyle":0,"identifier":"ManualIntent"},"AllOnIntent":{"requiredCapabilities":[],"systemProtocols":[],"systemProtocolMetadata":[],"openAppWhenRun":true,"descriptionMetadata":{"descriptionText":{"key":"Turn on all LEDs"},"categoryName":{"title":{"key":"Device"}},"searchKeywords":[]},"identifier":"AllOnIntent","parameters":[],"outputFlags":0,"typeSpecificMetadata":[],"mangledTypeNameByBundleIdentifier":{},"presentationStyle":0,"authenticationPolicy":0,"title":{"key":"All On"},"isDiscoverable":true,"effectiveBundleIdentifiers":[],"mangledTypeName":"9TrollLEDs11AllOnIntentV","availabilityAnnotations":{"LNPlatformNameWildcard":{"introducedVersion":"*"},"LNPlatformNameIOS":{"introducedVersion":"16.0"}},"mangledTypeNameV2":"9TrollLEDs11AllOnIntentV","mangledTypeNameByBundleIdentifierV2":{}},"AmberOnIntent":{"parameters":[],"availabilityAnnotations":{"LNPlatformNameIOS":{"introducedVersion":"16.0"},"LNPlatformNameWildcard":{"introducedVersion":"*"}},"mangledTypeNameByBundleIdentifier":{},"authenticationPolicy":0,"openAppWhenRun":true,"descriptionMetadata":{"categoryName":{"title":{"key":"Device"}},"descriptionText":{"key":"Turn on all amber LEDs"},"searchKeywords":[]},"mangledTypeNameV2":"9TrollLEDs13AmberOnIntentV","effectiveBundleIdentifiers":[],"systemProtocolMetadata":[],"typeSpecificMetadata":[],"presentationStyle":0,"identifier":"AmberOnIntent","requiredCapabilities":[],"mangledTypeNameByBundleIdentifierV2":{},"systemProtocols":[],"mangledTypeName":"9TrollLEDs13AmberOnIntentV","isDiscoverable":true,"title":{"key":"Amber On"},"outputFlags":0},"AllOffIntent":{"requiredCapabilities":[],"effectiveBundleIdentifiers":[],"parameters":[],"systemProtocolMetadata":[],"mangledTypeName":"9TrollLEDs12AllOffIntentV","identifier":"AllOffIntent","title":{"key":"All Off"},"presentationStyle":0,"descriptionMetadata":{"searchKeywords":[],"descriptionText":{"key":"Turn off all LEDs"},"categoryName":{"title":{"key":"Device"}}},"isDiscoverable":true,"systemProtocols":[],"outputFlags":0,"mangledTypeNameByBundleIdentifierV2":{},"openAppWhenRun":true,"typeSpecificMetadata":[],"authenticationPolicy":0,"mangledTypeNameV2":"9TrollLEDs12AllOffIntentV","mangledTypeNameByBundleIdentifier":{},"availabilityAnnotations":{"LNPlatformNameWildcard":{"introducedVersion":"*"},"LNPlatformNameIOS":{"introducedVersion":"16.0"}}},"WhiteOnIntent":{"mangledTypeName":"9TrollLEDs13WhiteOnIntentV","parameters":[],"effectiveBundleIdentifiers":[],"mangledTypeNameByBundleIdentifierV2":{},"systemProtocols":[],"isDiscoverable":true,"typeSpecificMetadata":[],"availabilityAnnotations":{"LNPlatformNameWildcard":{"introducedVersion":"*"},"LNPlatformNameIOS":{"introducedVersion":"16.0"}},"authenticationPolicy":0,"presentationStyle":0,"mangledTypeNameV2":"9TrollLEDs13WhiteOnIntentV","title":{"key":"White On"},"requiredCapabilities":[],"descriptionMetadata":{"categoryName":{"title":{"key":"Device"}},"searchKeywords":[],"descriptionText":{"key":"Turn on all white LEDs"}},"mangledTypeNameByBundleIdentifier":{},"outputFlags":0,"identifier":"WhiteOnIntent","openAppWhenRun":true,"systemProtocolMetadata":[]}},"entities":{},"enums":[],"autoShortcutProviderMangledName":"9TrollLEDs0aB20AppShortcutsProviderV","shortcutTileColor":14,"generator":{"name":"xcode-tools","version":"15.2"},"version":1}
Binary file not shown.
Binary file removed Resources/Metadata.appintents/nlu/en_US.nlu.lzfse
Binary file not shown.
55 changes: 0 additions & 55 deletions Resources/Metadata.appintents/root.ssu.yaml

This file was deleted.

16 changes: 16 additions & 0 deletions ShortcutsProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,21 @@ struct TrollLEDsAppShortcutsProvider: AppShortcutsProvider {
shortTitle: "All On",
systemImageName: "flashlight.on.circle.fill"
)
AppShortcut(
intent: AllOffIntent(),
phrases: [
"Turn off all LEDs with \(.applicationName)"
],
shortTitle: "All Off",
systemImageName: "flashlight.off.circle.fill"
)
AppShortcut(
intent: ManualIntent(),
phrases: [
"Configure LEDs levels manually with \(.applicationName)"
],
shortTitle: "Manual",
systemImageName: "flashlight.on.circle.fill"
)
}
}
8 changes: 5 additions & 3 deletions TLAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ - (UISceneConfiguration *)application:(UIApplication *)application configuration
}

- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL succeeded))completionHandler {
[_myViewController handleShortcutAction:shortcutItem.type];
[_myViewController handleShortcutAction:shortcutItem.type withParameters:nil];
}

- (void)appWillEnterForeground:(UIApplication *)application {
Expand All @@ -45,8 +45,10 @@ - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDiction
if (!url) return NO;
if ([url.scheme isEqualToString:@"leds"]) {
NSString *action = url.host;
if (action)
[_myViewController handleShortcutAction:action];
if (action) {
NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];
[_myViewController handleShortcutAction:action withParameters:components.queryItems];
}
}
return YES;
}
Expand Down
2 changes: 1 addition & 1 deletion TLRootViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
TLDeviceManager *deviceManager;
}
@property (nonatomic, retain) NSString *shortcutAction;
- (void)handleShortcutAction:(NSString *)action;
- (void)handleShortcutAction:(NSString *)action withParameters:(NSArray <NSURLQueryItem *> *)params;
- (void)setupStream;
- (void)releaseStream;
@end
Expand Down
30 changes: 27 additions & 3 deletions TLRootViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ - (BOOL)isQuadLEDs {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"TLQuadLEDs"];
}

- (void)handleShortcutAction:(NSString *)shortcutType {
- (void)handleShortcutAction:(NSString *)shortcutType withParameters:(NSArray <NSURLQueryItem *> *)parameters {
BOOL legacy = [_deviceManager isLegacyLEDs];
BOOL quad = [self isQuadLEDs];
if ([shortcutType isEqualToString:@"com.ps.TrollLEDs.AmberOn"]) {
Expand All @@ -98,12 +98,36 @@ - (void)handleShortcutAction:(NSString *)shortcutType {
WarmLED1Level = 0;
}
} else if ([shortcutType isEqualToString:@"com.ps.TrollLEDs.AllOn"]) {
if (!legacy) {
if (legacy) {
LEDLevel = 100;
} else {
CoolLED0Level = 255;
CoolLED1Level = quad ? 255 : 0;
WarmLED0Level = 255;
WarmLED1Level = quad ? 255 : 0;
}
} else if ([shortcutType isEqualToString:@"com.ps.TrollLEDs.AllOff"]) {
if (legacy) {
LEDLevel = 0;
} else {
CoolLED0Level = 0;
CoolLED1Level = 0;
WarmLED0Level = 0;
WarmLED1Level = 0;
}
} else if ([shortcutType isEqualToString:@"com.ps.TrollLEDs.Manual"]) {
if (!legacy) {
for (NSURLQueryItem *parameter in parameters) {
if ([parameter.name isEqualToString:@"coolLED0"])
CoolLED0Level = [parameter.value intValue];
else if ([parameter.name isEqualToString:@"coolLED1"])
CoolLED1Level = [parameter.value intValue];
else if ([parameter.name isEqualToString:@"warmLED0"])
WarmLED0Level = [parameter.value intValue];
else if ([parameter.name isEqualToString:@"warmLED1"])
WarmLED1Level = [parameter.value intValue];
}
}
}
if (legacy) {
_sliders[0].value = LEDLevel;
Expand Down Expand Up @@ -290,7 +314,7 @@ - (void)viewDidLoad {
[self configureLEDSliders:sliderCount maximumValue:isLegacyLEDs ? 100 : 255];

if (_shortcutAction) {
[self handleShortcutAction:_shortcutAction];
[self handleShortcutAction:_shortcutAction withParameters:nil];
_shortcutAction = nil;
}
}
Expand Down
Loading

0 comments on commit 8eb2cc7

Please sign in to comment.