Add Siri support for overrides#1429
Conversation
|
|
||
| import Foundation | ||
|
|
||
| struct IntentExtensionInfo: RawRepresentable { |
There was a problem hiding this comment.
I created IntentExtensionInfo so it would be easier to pass data between the intent extension and the main app in the event someone wanted to add other things to Loop's Siri capabilities
| } | ||
|
|
||
| func handle(intent: EnableOverridePresetIntent, completion: @escaping (EnableOverridePresetIntentResponse) -> Void) { | ||
| guard let defaults = self.defaults, let overrideName = intent.overrideName?.lowercased(), containsOverrideName(name: overrideName) else { |
There was a problem hiding this comment.
My (pretty simple) implementation to set overrides just looks for the preset's name (and lowercases the names when comparing to avoid capitalization-related difficulties). This will fail to distinguish between overrides if they have the same name but different capitalization.
| currentEffectiveOverride = scheduleOverride | ||
| case (let preMealOverride?, let scheduleOverride?): | ||
| currentEffectiveOverride = preMealOverride.endDate > Date() | ||
| currentEffectiveOverride = preMealOverride.scheduledEndDate > Date() |
There was a problem hiding this comment.
This is a rename that I made on the LoopKit level
|
In the project file, |
Currently, overrides aren't visible to Siri (meaning they can't be set with Shortcuts or via voice). There also isn't a great way to view the override history in Loop; the issue report does contain the history, but it's not in a very human-readable format.
This PR:
Some notes about the overrides with Siri implementation:
UserDefaultsso the extension could communicate with the main Loop app; the main app has a key-value observer that will watch for changes to set the appropriate override. One issue with this is that the KVO doesn't happen when Loop is in the background, so I changed the intent handler to always.continueInAppso the override will be set. Open to other ways to do this if there's something that could set the override in the backgroundLoopKit PR: LoopKit/LoopKit#343
NightscoutService PR: ps2/NightscoutService#4