Skip to content

[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

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

Camji55
Copy link
Member

@Camji55 Camji55 commented Apr 22, 2025

@Camji55 Camji55 requested review from ps2 and nhamming April 22, 2025 21:50
Comment on lines +14 to +17
struct AppSource: Hashable {
let name: String
let bundleId: String?
}
Copy link
Member Author

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!

Copy link
Member Author

@Camji55 Camji55 Apr 22, 2025

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.

Copy link
Member Author

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 🤷🏻‍♂️

Comment on lines +134 to +149
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()
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a way I thought we could display the source in the CarbEntryView if it's available:

Simulator Screenshot - iPhone 16 Pro - 2025-04-22 at 14 44 12

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also make editing disabled if presented via deeplink

Copy link

Choose a reason for hiding this comment

The 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?

.environment(\.settingsManager, settingsManager)
.environment(\.temporaryPresetsManager, temporaryPresetsManager)
.edgesIgnoringSafeArea(.top)
let statusTableView = StatusTableView(viewModel: viewModel, displayGlucosePreference: deviceDataManager.displayGlucosePreference, settingsManager: settingsManager, temporaryPresetsManager: temporaryPresetsManager)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving environment modifiers into the view itself make type matching the type-erased viewController much easier.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly not a huge fan of this. I understand why you're doing it; so you can cast it later, but having to cast also seems like a smell.

It seems like the deep link manager should probably already have a reference to the the status table view controller, rather than having to dig through the view stack, and unwrap/cast things.

It looks like LoopAppManager.handle is the entry point, passing the url off to the deeplinkManager. LoopAppManager also creates StatusTableView, can we get a ref to the status table view controller through there?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like all DeeplinkManager is pass through, so I don't think that really justifies another manager layer. Same with RootNavigationController. LoopAppManager/AppDelegate is the main entry point; and the StatusTableViewController has the real logic, and LoopAppManager should be able to retain a ref to StatusTableViewController/StatusTableView

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ps2 Alright -- I made some updates. Is this closer to what you'd expect?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think that's a lot better. Thanks!


/// The root view controller in Loop
class RootNavigationController: UINavigationController {

/// Its root view controller is always StatusTableViewController after loading
var statusTableViewController: StatusTableViewController? {
return viewControllers.first as? StatusTableViewController
return (viewControllers.first as? UIHostingController<StatusTableView>)?.rootView.viewController
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is where the type erasure makes things more simple.

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
Copy link

Choose a reason for hiding this comment

The 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.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or is sourceName coming from iOS here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants