-
Notifications
You must be signed in to change notification settings - Fork 8
[LOOP-5328] Fix Deeplinking and Widgets #786
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,18 +7,69 @@ | |
// | ||
|
||
import Foundation | ||
import LoopAlgorithm | ||
|
||
enum Deeplink: String, CaseIterable { | ||
case carbEntry = "carb-entry" | ||
case bolus = "manual-bolus" | ||
case preMeal = "pre-meal-preset" | ||
case customPresets = "custom-presets" | ||
enum Deeplink: Hashable { | ||
|
||
struct AppSource: Hashable { | ||
let name: String | ||
let bundleId: String? | ||
} | ||
|
||
enum Host: String, CaseIterable { | ||
case carbEntry = "carb-entry" | ||
case bolus = "manual-bolus" | ||
case preMeal = "pre-meal-preset" | ||
case customPresets = "custom-presets" | ||
} | ||
|
||
enum CarbEntryLink: Hashable { | ||
case carbEntryDetected(value: LoopQuantity, source: AppSource?) | ||
} | ||
|
||
case carbEntry(CarbEntryLink?) | ||
|
||
case bolus | ||
case preMeal | ||
case customPresets | ||
|
||
var host: Host { | ||
switch self { | ||
case .carbEntry: .carbEntry | ||
case .bolus: .bolus | ||
case .preMeal: .preMeal | ||
case .customPresets: .customPresets | ||
} | ||
} | ||
|
||
init?(url: URL?) { | ||
guard let url, let host = url.host, let deeplink = Deeplink.allCases.first(where: { $0.rawValue == host }) else { | ||
guard let url, let host = url.host, let deeplinkHost = Deeplink.Host.allCases.first(where: { $0.rawValue == host }) else { | ||
return nil | ||
} | ||
|
||
let components = URLComponents(url: url, resolvingAgainstBaseURL: true) | ||
|
||
self = deeplink | ||
switch deeplinkHost { | ||
case .carbEntry: | ||
if let value = components?.queryItems?.first(where: { $0.name == "value" })?.value, let doubleValue = Double(value) { | ||
let sourceBundleId = components?.queryItems?.first(where: { $0.name == "sourceBundleId" })?.value | ||
let sourceName = components?.queryItems?.first(where: { $0.name == "sourceName" })?.value | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering about possible misuse of this; any app could send a spoofed name to make the carb entry look it it came from a different app. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or is sourceName coming from iOS here? |
||
|
||
var source: AppSource? | ||
if let sourceName { | ||
source = AppSource(name: sourceName, bundleId: sourceBundleId) | ||
} | ||
|
||
self = .carbEntry(.carbEntryDetected(value: LoopQuantity(unit: .gram, doubleValue: doubleValue), source: source)) | ||
} else { | ||
self = .carbEntry(nil) | ||
} | ||
case .bolus: | ||
self = .bolus | ||
case .preMeal: | ||
self = .preMeal | ||
case .customPresets: | ||
self = .customPresets | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,6 +131,22 @@ struct CarbEntryView: View, HorizontalSizeClassOverride { | |
|
||
CardSectionDivider() | ||
|
||
if let source = viewModel.carbsSource { | ||
HStack(spacing: 2) { | ||
Text("Source") | ||
.foregroundColor(.primary) | ||
.frame(maxWidth: .infinity, alignment: .leading) | ||
|
||
Spacer() | ||
|
||
Text(source.name) | ||
.foregroundColor(Color(.secondaryLabel)) | ||
} | ||
.accessibilityElement(children: .combine) | ||
|
||
CardSectionDivider() | ||
} | ||
|
||
Comment on lines
+134
to
+149
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could also make editing disabled if presented via deeplink There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure we'd want to disable editing? Seems like that should always be a good thing, for cases where the originating app might not be correct? Or the user changes their mind? |
||
DatePickerRow(date: $viewModel.time, isFocused: timeFocused, minimumDate: viewModel.minimumDate, maximumDate: viewModel.maximumDate) | ||
|
||
CardSectionDivider() | ||
|
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.
@ps2 this is something I was prototyping around with; a way to pre-fill the carbs value via a deepLink. Lmk your thoughts!
Uh oh!
There was an error while loading. Please reload this page.
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.
Deeper value here could be the ability to observe carb entries from 3rd parties and then have Loop notify you to bolus for it. Or having a Siri Shortcut for common carb entries.
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.
BundleId here could allow to query the app icon from the App Store API if we wanted to display it 🤷🏻♂️