-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add Siri support for overrides #1429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
|
||
| import Foundation | ||
|
|
||
| struct IntentExtensionInfo: RawRepresentable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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