Skip to content
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

adding the "contact trick" #505

Merged
merged 6 commits into from
Apr 11, 2024

Conversation

yurique
Copy link
Contributor

@yurique yurique commented Mar 11, 2024

Fixes #481.


Most of this PR is adding the new settings section to the iOS app.
The contact image rendering itself is heavily inspired by the implementation in OpenGlück, but I modified it quite a bit to support more customizations (and removed things related to "episodes", etc).


This is my first time coding for iOS, as well as first time coding in swift or in xcode – please feel free to nitpick all the things :)


Does it work? - Yes!
I kept the original G7 complication on my watch together with the "contact trick" for a while - feels like half of the time I was looking, the G7 complication was either not showing anything (--) or showing the outdated reading (the previous one), while the contact picture updates almost immediately and has been up-to-date all the time.


image
IMG_3219

@yurique yurique changed the title contact trick adding the "contact trick" Mar 11, 2024
@callms
Copy link

callms commented Mar 11, 2024

Hello @yurique! OpenGlück maintainer here, nice to see you have been able to port this to xdripswift! 🥳
From the screen it looks great, well done! 🎉

@yurique
Copy link
Contributor Author

yurique commented Mar 11, 2024

@callms hey hey! Btw, a bit off-topic: I tried running the OpenGlück-server but never managed to get it to work (it doesn't seem to be creating the initial user and keeps sending me back to the create-user page) (I was trying to launch it inside k8s, so it could be a misconfiguration on my side - but I couldn't figure it out)

@callms
Copy link

callms commented Mar 11, 2024

@callms hey hey! Btw, a bit off-topic: I tried running the OpenGlück-server but never managed to get it to work (it doesn't seem to be creating the initial user and keeps sending me back to the create-user page) (I was trying to launch it inside k8s, so it could be a misconfiguration on my side - but I couldn't figure it out)

Thanks for pointing it out, I think it was somehow broken when I added multi-user. I think it should be fixed in open-gluck/opengluck-server#28

@bjornoleh
Copy link
Contributor

What a cool addition! Now I just need to get it to work :-) Any special requirements for the contact that is used? I am not seeing any picture being added to this contact, so still just seeing the x. And should it work both as NS follower and Dexcom master (receiver)? Thanks!

@yurique
Copy link
Contributor Author

yurique commented Mar 23, 2024

@bjornoleh I don't know enough about the internals of xdrip, but the contact trick is just subscribing to receive updates whenever there is a new BG reading available and then renders it into the contact picture - I'm assuming it doesn't matter if it's in follower or master mode (though I could be wrong about this).

I have only tested it on my phone, and in the simulator - and for me it "just works".

Is there a chance you could get the logs from the app? (if you're running it from xcode - the logs should show up there, in the debugger - otherwise you can send the logs from within the app - "Send Issue Report"). In case of errors it should log messages starting with in updateContact, ... (for example, in updateContact, failed to update the contact).

@bjornoleh
Copy link
Contributor

Thanks for your reply. I am trying to get this to work in a S3, which only gets to watchOS 8. Any limitations here?

Regarding the contact added, can any contact (with a fake email address?) be used, or is a specific one like in your screenshot needed?

@callms
Copy link

callms commented Mar 23, 2024

(Original OG implementor here.) It should work with any watchOS version compatible with xdripswift, just like when using the calendar trick. watchOS doesn't have limitations on Apple widgets as far as refresh goes.

@bjornoleh
Copy link
Contributor

(Original OG implementor here.) It should work with any watchOS version compatible with xdripswift, just like when using the calendar trick. watchOS doesn't have limitations on Apple widgets as far as refresh goes.

Thanks!

Can any contact be used, or only a specific email (there is a specific one menton the OG readme)? I also tested adding a picture to the contact to see if that was displayed, and it was (but rather small on the 38 mm S3). The picture was not updated though.

@yurique
Copy link
Contributor Author

yurique commented Mar 23, 2024

Any contact should work - it stores the ID of the contact you select in the settings, and then finds the contact by that ID and updates it.

@bjornoleh
Copy link
Contributor

Ok, thanks. I did find in updateContact, failed to update the contact every five minutes in the logs, but I guess that doesn’t tell us much

@yurique
Copy link
Contributor Author

yurique commented Mar 23, 2024

@bjornoleh that's a very good start! There is an error, but its message is not logged. I just pushed an update that should log a bit more details about why it's failing.

@callms
Copy link

callms commented Mar 23, 2024

@bjornoleh by any chance, can you double-check if permissions allow xdripswift to update contacts?

@bjornoleh
Copy link
Contributor

Thank @callms for looking into this! I rebuilt with the additional logging now. Then I verified that the contacts permission is given: Disabled, noted the warning in Xdrip when toggling on the contacts trick, then gave permission and started testing again.

I get Code 207: Container is read-only

Did fail to save (1740 µs): Error Domain=CNErrorDomain Code=207 "Container is read-only" UserInfo={NSUnderlyingError=0x280866280 {Error Domain=ABAddressBookErrorDomain Code=0 "(null)" UserInfo={PolicyRejectionReason=SourceNotWritable}}, CNInvalidRecords=(
    "<CNMutableContact: 0x117f05db0: identifier=AFB3B46E-876E-481F-A322-38D4489EA01A:ABPerson, givenName=(not fetched), familyName=(not fetched), organizationName=(not fetched), phoneNumbers=(not fetched), emailAddresses=(not fetched), postalAddresses=(not fetched)>"
), NSLocalizedFailureReason=The save request failed because it attempted to modify records in a container that is read-only., NSLocalizedDescription=Container is read-only}
in updateContact, failed to update the contact - Code 207: Container is read-only

@yurique
Copy link
Contributor Author

yurique commented Mar 23, 2024

It looks like the contact is read-only. I don't really know, why. Is it a regular contact on your phone? Is there anything "special" about it?

@bjornoleh
Copy link
Contributor

bjornoleh commented Mar 23, 2024

It looks like the contact is read-only. I don't really know, why. Is it a regular contact on your phone? Is there anything "special" about it?

I don't think there is anything special about it. It is given a name (xd) and has the same email as in your readme ([email protected]) I have tried various other contacts too.

The picture was displayed on the S3 watch when I set a contact picture manually.

The phone is a kids phone with some Screen Time restrictions. Not sure if any of that could interfere?

The phone also shared its iCloud with another phone used as a follower phone by other caregivers, so the account had two associated phone numbers. I thought this could matter, and signed the outer phone out of iCloud. I rebooted phone and watch afterwards for good measure. But no difference still.

@callms
Copy link

callms commented Mar 23, 2024

@bjornoleh by any chance, does it work when you update the contact from your phone? Does it work when you create a new contact?

@bjornoleh
Copy link
Contributor

@bjornoleh by any chance, does it work when you update the contact from your phone? Does it work when you create a new contact?

Yes, I can change the contact picture manually, it updates on the watch

@yurique
Copy link
Contributor Author

yurique commented Mar 23, 2024

It seems like some kind of restriction on the phone - Screen Time, iCloud, something else? Unfortunately, I know next to nothing about all of this :(

@paulplant
Copy link
Collaborator

Once 5.2.0 is released, we'll look at getting this PR merged in @yurique , @callms . Nice work!

We'd need to try and limit the settings options if possible. Can the font size/type and also the dark mode option be removed? I mean can we use a fixed/system font and have SwiftUI scale it to the size needed to fit the circularAccessory widget?

@paulplant paulplant added the enhancement New feature or request label Mar 24, 2024
@paulplant
Copy link
Collaborator

Another thought... although technically the name "Contact Trick" would work for devs because it accurately describes what it is, I don't think it would work well for public release. In fact translating this into other languages would probably create confusion that would need further explanation. The fact that it's a trick/workaround/exploit shouldn't be worded into the description itself.

Do you guys have any other ideas that could be used? For example, "Calendar events" works well because it is exactly what it is, an event in the calendar. But I'm struggling to think of a better name for this that doesn't use the work "trick".

If this is also only for Watch complications, then maybe this needs to be clearer too. Maybe something like "Watch contact complication" would work but it's maybe a bit long.

@m-a-v
Copy link

m-a-v commented Mar 24, 2024

What about Contact Sync. At least in the docs there will be needed some kind of explanation. But agree, that trick is probably not the best term...

@yurique
Copy link
Contributor Author

yurique commented Mar 24, 2024

Can the font size/type and also the dark mode option be removed? I mean can we use a fixed/system font and have SwiftUI scale it to the size needed to fit the circularAccessory widget?

Definitely! The renderer is already trying to adjust the font size to fit it into the area.

Dark mode - this was an attempt to make it work on both dark and brighter watch backgrounds. But it looks like the watch is able to be somewhat smart about it. I tried playing with it just now: when I'm changing the color "scheme" - the watch is replacing the white text color on the contact pictures with the color I select. I've never used a non-black background, though.

Font name - I was trying to find a font that looks the most readable in a small complication, but system default looks decent as well.

@callms
Copy link

callms commented Mar 24, 2024

What about Contact Sync

I personally like it, “Contact Sync” and “Calendar Sync” would make it even to understand for non-developers if we were to talk about the two in the same sentence.

@yurique
Copy link
Contributor Author

yurique commented Apr 9, 2024

@paulplant sounds good to me!
I'll try to find time to resolve the conflicts later today and will remove some unnecessary settings.

But definitely - please feel free to adjust it as much as you find necessary :)

@yurique
Copy link
Contributor Author

yurique commented Apr 9, 2024

the "Contact Trick" is only used for the Apple Watch complications.

I have only used it on the watch. One can put a contact widget on the phone as well (or even on the desktop in macOS) but I'm not sure if it's useful.

@yurique
Copy link
Contributor Author

yurique commented Apr 10, 2024

Sorry, didn't get to this yesterday :/. Now aiming for today :)

# Conflicts:
#	xdrip.xcodeproj/project.pbxproj
#	xdrip/Constants/ConstantsLog.swift
#	xdrip/View Controllers/Root View Controller/RootViewController.swift
@yurique
Copy link
Contributor Author

yurique commented Apr 11, 2024

Conflicts resolved, now going to remove some of the font settings.

@paulplant
Copy link
Collaborator

Great... let me know when ready and I'll probably cherry pick your commits into my staging branch and we can finish working on it there.

@dnzxy
Copy link
Contributor

dnzxy commented Apr 11, 2024

@yurique @paulplant is it worth verifying fastlane build-ability now, or wait for the RC in your staging branch, Paul? Just curious when to best set aside a bit of time to test.

@yurique
Copy link
Contributor Author

yurique commented Apr 11, 2024

@dnzxy I just pushed a commit removing some of the settings. It builds in xcode, but I haven't tested it yet.
There is one thing that I'm not sure about - in iAPS I used the standard Contact Selector "component", and here I'm just building a drop-down (I didn't know better when I implemented it). I think it's worth using the standard component as well but I'm not sure how to integrate it into the way settings views are built.

@dnzxy
Copy link
Contributor

dnzxy commented Apr 11, 2024

I‘ll spin up a build tonight and see how it goes. Pretty confident that it should build fine. Doesn’t look like this should break the fastlane build 😊🤞

@paulplant
Copy link
Collaborator

@yurique @paulplant is it worth verifying fastlane build-ability now, or wait for the RC in your staging branch, Paul? Just curious when to best set aside a bit of time to test.

I would hang off for a bit... when I saw the changes you did 2 weeks ago I know understand what causes things to break in the fastlane build and there shouldn't be anything like that yet.

Last time we were up against the 90 day expiry so had to really push to get 5.1.0 out and then we were rushing hot-fixes out for a few days.

This time we've got lots of time so it's better to wait until everything hits develop in the next week or so and then we can calmly test fastlane before release. There's no rush this time and we'll make sure it's all ready before release.

@paulplant
Copy link
Collaborator

@paulplant paulplant changed the base branch from develop to staging-5.2 April 11, 2024 15:33
@paulplant paulplant merged commit e4977cf into JohanDegraeve:staging-5.2 Apr 11, 2024
@yurique
Copy link
Contributor Author

yurique commented Apr 11, 2024

looks like I missed to stage one of the changes when when committing (removing the reference to FontTypeWeight in project.pbxproj), I fixed it and merged the upstream changes (last two commits here: https://github.com/yurique/xdripswift/commits/feature/contact-trick/)

@paulplant
Copy link
Collaborator

Please open a PR with them into this branch

@yurique
Copy link
Contributor Author

yurique commented Apr 11, 2024

@paulplant here it is: #527

@dnzxy
Copy link
Contributor

dnzxy commented Apr 11, 2024

FWIW: Staging 5.2 (with all things merged) is building fine 🚀 see successful run at https://github.com/dnzxy/xdripswift/actions/runs/8651372734/job/23721981359

@paulplant
Copy link
Collaborator

They'll be a lot more commits going to that branch over the next week or two so I'll tag you again when it's worth re-checking. Thanks!!

@dnzxy
Copy link
Contributor

dnzxy commented Apr 11, 2024

Anytime! 🤝 I just wanted to make sure that this feature is building without issue (as expected; now verified).

@paulplant
Copy link
Collaborator

@yurique , @callms , @m-a-v , I've been using it for a short while and thinking about it and I would like to propose "Contact Image" as the name... as this is exactly what it is/does without any confusion or making it sound like a workaround.

Does this sound ok?

@yurique
Copy link
Contributor Author

yurique commented Apr 11, 2024

Sounds perfectly fine! (I don't really have any preferences regarding the name :) )

@paulplant
Copy link
Collaborator

@yurique , @callms , @m-a-v , @dnzxy , @bjornoleh , @LiroyvH I think this should now be pretty much ready for pushing to develop.

If you want to build and test:
https://github.com/JohanDegraeve/xdripswift/tree/staging-5.2

(note that the 5.2.0 staging branch also has Watch app/complication background refresh implemented amongst other stuff)

I've rewrote a lot of the ContactImageView struct and adapted the style to match fully the xDrip4iOS UI.

I removed also the rangeIndicator as this is already explicitly implied by the bg value text color in xDrip4iOS UI style.

I think that the "Show trend" could also be removed and just always shown if available, but I guess this might be going too far in paring things down :)

Also changed quite a lot of ContactImageManager class.

To try and simplify things for the user, they now don't need create and select an e-mail address/contact. The app will now automatically create a contact based on ConstantsHomeView.applicationName (to allow this to work with Shuggah and other forks cleanly) and keep that contact updated.

It'll also add the data source info to the contact organisation and add a note when it's first created to avoid confusion when the user sees that a new contact has appeared (in case they forget).

When the user disables the contact image function, the app will now automatically delete the contact to clean up after itself*

  • I'm not 100% sure if this is the best way to manage this as the watch complication will still show the old image when the contact was deleted. Please feedback on this.

Initial localisations added for English and Spanish. If you want me to quickly add other languages, just copy/paste this with the new strings in the comments:

"settingsviews_infoContactsAccessRestricted" = "You cannot give authorization to %@ to access your contacts. This is possibly due to active restrictions such as parental controls being in place.";
"settingsviews_contactImageSectionTitle" = "Contact Image";
"settingsviews_enableContactImage" = "Create Contact";
"settingsviews_displayTrendInContactImage" = "Show Trend";
"settingsviews_contactImageCreatedByString" = "Contact automatically created by";

Settings screen:
Simulator Screenshot - iPhone 15 Pro + Watch - 2024-04-14 at 14 26 20

Contact screen:
Simulator Screenshot - iPhone 15 Pro + Watch - 2024-04-14 at 14 21 25

Contact Image as Watch complication:
incoming-044DFAD6-1737-4A29-A5D8-5CAD52611FA6

@paulplant
Copy link
Collaborator

Note: In the above xDrip4iOS Watch Complication you can see WCSession.remainingComplicationUserInfoTransfers shown in cyan color. The idea is that this will reach 0 at around 23hrs (bed time)...

This will be removed for merging, it's just there for debugging now.

@dnzxy
Copy link
Contributor

dnzxy commented Apr 14, 2024

Great work you guys!

One small suggestion: can the white border of the circle be used as the range indicator color and the BG be in plain white? Similar to the battery complication in the left of the screenshotted watch face?

Most if not all watch complications use white as text color and give color to all other shapes or elements, hence the idea.

For the translation, I can supply German.
"settingsviews_infoContactsAccessRestricted" = "Authorisierung von %@ zum Zugriff auf Kontakte nicht möglich. Möglicherweise sind Einschränkungen, bspw. Elternkontrolle, aktiv."; "settingsviews_contactImageSectionTitle" = "Kontaktbild"; "settingsviews_enableContactImage" = "Erstelle Kontakt"; "settingsviews_displayTrendInContactImage" = "Zeige Trend"; "settingsviews_contactImageCreatedByString" = "Kontakt automatisch erstellt von";

@yurique
Copy link
Contributor Author

yurique commented Apr 14, 2024

can the white border of the circle be used as the range indicator color and the BG be in plain white?

unfortunately, the white circle is part of the contact complication UI - it's always there around the actual contact picture

@paulplant
Copy link
Collaborator

One small suggestion: can the white border of the circle be used as the range indicator color and the BG be in plain white? Similar to the battery complication in the left of the screenshotted watch face?

When I first started looking at it, I thought the same, but it's as @yurique says, we can't do anything to avoid it.

@dnzxy
Copy link
Contributor

dnzxy commented Apr 14, 2024

Okay, strike that thought then. Still fire. Awesome work! 👏

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

Successfully merging this pull request may close these issues.

6 participants