Loop icon indicating copy to clipboard operation
Loop copied to clipboard

feature: Live Activity

Open bastiaanv opened this issue 1 year ago • 45 comments

This PR is an initial/basic version of this Live Activity, without any feature which are spoken of in the Zulipchat.

Look & Feel:

Lock Screen (all iPhone's):

History only History and predictive line Live activity stale (8h limit i.e.)
IMG_2536 IMG_2534 IMG_2535

Dynamic Island (iPhone 14 pro max and higher):

Screenshots are from a iPhone 15 pro max simulator

Dynamic Island minimal Dynamic Island expanded
Simulator Screenshot - iPhone 15 Pro Max - 2024-07-15 at 12 49 36 Simulator Screenshot - iPhone 15 Pro Max - 2024-07-15 at 12 51 14

Settings

Can be found at: Settings -> Alert management -> Live Activity

Root settings Bottom row settings Available datapoints for bottom row
IMG_2537 IMG_2538 IMG_2539

Things to know:

  • The bottom row has a max of 4 items, but less items can be configured for small screen sizes (like the iPhone 13 mini)
  • The bottom row can be configured to the user's wishes. Swap items around, different order etc. The default is: CurrentBG, IOB, COB, UpdatedAt (like in the screenshots)
  • The following events trigger a re-render of the Live Activity:
    • LoopDataManager -> GlucoseStore.glucoseSamplesDidChange
    • LoopDataManager -> CarbStore.carbEntriesDidChange
    • LoopDataManager -> dosing changing
    • NotificationCenter -> UIApplication.willEnterForegroundNotification

bastiaanv avatar Jul 15 '24 10:07 bastiaanv

Love the draft/prototype! Would love to see this make it into the project down the line I think it looks amazing!

A9qx avatar Jul 16 '24 02:07 A9qx

Built onto my real phone. Thanks so much for making this available. 👍

marionbarker avatar Jul 23 '24 00:07 marionbarker

Awesome work !

Feat request

  • Is it possible to change the y-axis of the graph in order to be more center on the data like in the app? image image

  • Maybe the blue area can replace the settings of the upper / lower limit, because it can change in the day. Or maybe the blue area should be displayed with no limit like the other graphs

  • In order to have the graph with full width, the status ring could be in the bottom bar

Bugs found

  • Sometime on iPhone 13 Pro the live activity don't appear. I have to Disable and Enable it in the settings to have it again.

bastienmoulia avatar Jul 24 '24 12:07 bastienmoulia

I have been using this for several days - I really enjoy having it attached to Loop.

Bug report:

  • Dynamic Island expanded (long press on dynamic island)
    • truncates the display when glucose is in mg/dL and above 99 mg/dL
    • graphic below with 24 hour display disabled (top) and enabled (bottom)

loop-pr-2191-dynamic-island-expanded

Feature requests:

  • see the target range shown on the Look Screen Widget graph
  • see if an override is currently enabled, definitely added to target display on graph, possibly with the override name displayed

marionbarker avatar Jul 24 '24 17:07 marionbarker

Thanks for all the feedback:

  • The truncate bug has been fixed @marionbarker
  • Also I added the blue area (glucose targets) & the preset to the views, so thank you for the ideas @marionbarker @bastienmoulia .
  • @bastienmoulia I have enabled some extra logging for myown device to research the issue regarding the disappearing of the Live Activity.

Preview

Blue area (glucose target) Preset enabled (without predictive line) Preset enabled (with predictive line)
Simulator Screenshot - iPhone 15 - 2024-07-25 at 20 19 57 Simulator Screenshot - iPhone 15 - 2024-07-25 at 20 07 31 Simulator Screenshot - iPhone 15 - 2024-07-25 at 20 20 08

bastiaanv avatar Jul 25 '24 18:07 bastiaanv

Nice upgrade except the override appears confused.

  • This override was active from 11:05 to 1:05 pm (with 2 hours duration), but it shows as being currently active (1:45 pm).
  • I see the same pattern when long-pressing the dynamic island.
  • I updated with the latest commit at 1:21 pm local (after this override had expired).

old-override-shows

  • I added a new override at 1:47 pm that has a duration of 3 hours.
  • I will report back in 20 minutes or so. Long enough to see if the start point is correct
  • And then I will turn it off and see what the plots look like.

marionbarker avatar Jul 25 '24 20:07 marionbarker

The walking override started at 1:47 with a duration of 3 hours and was cancelled 19 minutes later.

  • upper plot: While override is active. The bad news is the start point for the plot for both lock screen and dynamic island expanded plot is "now" instead of when override started.
  • lower plot: After disabling the override. The good news is that plotting a cancelled override was not repeated - perhaps that was related to the new build, or perhaps because it was cancelled instead of allowed to run the full duration.

override-status

marionbarker avatar Jul 25 '24 21:07 marionbarker

Thanks for the blue area!

Same here for the bug with an override label shown even none were triggered IMG_B15E4FD11EDD-1

bastienmoulia avatar Jul 26 '24 08:07 bastienmoulia

I did a bit more testing.

  • If an override is active, it is shown as starting "now"
  • If an override expires after the planned duration, it continues to be show starting "now"
  • If an override is cancelled early, no extraneous override is displayed

marionbarker avatar Jul 26 '24 13:07 marionbarker

In the last update, I didn't see the target area for the next hour by default: IMG_598D1AB784AD-1

If I activate the premeal, then remove it, it's ok.

bastienmoulia avatar Jul 28 '24 08:07 bastienmoulia

Aight, it has been a crazy few days, but I made several fixes and restructured the code a bit. This should fix most of the weird behaviour found by @bastienmoulia and @marionbarker.

@marionbarker regarding the extraneous override. With this new version, I made it so that the preMeal override is "preferred" above the scheduled overrides, since that is only active for a maximum between now and 1hour. Do you agree with this? I dont think there is enough space to show both texts, tho it is possible to show both in the graph

bastiaanv avatar Jul 31 '24 18:07 bastiaanv

Other question, do we want to keep the upper and lower limit in the settings (and with that the green, orange and red coloring in the graph)?

bastiaanv avatar Jul 31 '24 18:07 bastiaanv

Other question, do we want to keep the upper and lower limit in the settings (and with that the green, orange and red coloring in the graph)?

Personally I prefer to not have multiple color because it causing more stress when it's orange or red. So no limit.

bastienmoulia avatar Jul 31 '24 18:07 bastienmoulia

I have no strong opinion on the color. But with the ability to modify the glucose levels at which colors change allows people who want colors to have them and folks who do not want colors to turn them off.

I just set mine to 40 and 400 mg/dL to give it a try.

marionbarker avatar Jul 31 '24 23:07 marionbarker

I added the setting to enable or disable the coloring based on the BG

Chart view without coloring New setting (with BG coloring enabled)
Simulator Screenshot - iPhone 15 Pro Max - 2024-08-01 at 20 43 44 Simulator Screenshot - iPhone 15 Pro Max - 2024-08-01 at 20 45 36

bastiaanv avatar Aug 01 '24 18:08 bastiaanv

Bug reports:

  1. I tested with the latest and I am still having the Live Activity show overrides that were allowed to end at the planned duration. It does clear by setting and unsetting any override on the Loop app.
  2. Adjust the values for BG coloring, there does not appear to be a way to save these values

Comments

I would prefer if there was an explicit Save button to save new settings on the Live Activities screen with the Back button leaving settings alone.

Successes

The things that work as expected:

  • Choose Large or Small
  • Available for Large or Small:
    • Add / Delete / Rearrange items for bottom row
  • Available for Large only:
    • Enable / Disable Prediction Line
    • Enable / Disable Use BG coloring
    • Adjust the values for the BG coloring (see bug report)

marionbarker avatar Aug 09 '24 14:08 marionbarker

Dumb question, but could anyone point me to documentation that could show me how to try out this branch? Downloading the ZIP from https://github.com/bastiaanv/Loop/tree/feat/live-activity doesn't seem to be buildable in Xcode but perhaps I am missing a step.

rfmurphy81 avatar Aug 09 '24 15:08 rfmurphy81

Dumb question, but could anyone point me to documentation that could show me how to try out this branch? Downloading the ZIP from https://github.com/bastiaanv/Loop/tree/feat/live-activity doesn't seem to be buildable in Xcode but perhaps I am missing a step.

I don't know how to do this with Xcode, but with the build from github I change the .gitmodules file like this : https://github.com/bastienmoulia/LoopWorkspace/blob/dev/.gitmodules And when there is an update I run git submodule update --remote in the LoopWorkspace before pushing it.

bastienmoulia avatar Aug 09 '24 15:08 bastienmoulia

There are several ways to do this:

  1. Open the terminal in the Loop folder. Do 'git remote set-url origin https//github.com/bastiaanv/loop', then do 'git pull', then do 'git checkout feat/live-activity'

  2. Or download the patch file from https://github.com/loopandlearn/customization, open the terminal in the Loop folder, then do 'git apply

  3. Or run the customization script in your terminal yourself: https://www.loopnlearn.org/custom-code/

Please note, that I typed this on my phone, so there might be typos in my commands

bastiaanv avatar Aug 09 '24 15:08 bastiaanv

Bug report

When using Nightscout as CGM, it appears that the data will always be reported as stale. For additional context on this issue, Nightscout is reading from LibreLinkUp, and thus reporting blood glucose values on a 1-minute interval, which may affect how this is handled.

Using v3.4.1 with the latest customization as of today.

partcoffee avatar Aug 14 '24 10:08 partcoffee

Hi @partcoffee ,

This behaviour is correct. The Live Activity doesnt keep iOS from suspending the app (also called Heartbeath). This also means that Loop isn't doing anything while the app is suspended. Jumping to conclusion, I assume you use Loop as a following app (just watching the BG values from NightScout).

There are a few ways to correct this:

  1. Connect a BLE-enabled pump to Loop
  2. Customize Loop to include background sounds (like LoopFollow) or use Location services to keep Loop from being suspended
  3. Or switch to something like xDrip4ios which is a dedicated app to follow BG values from different sources like NightScout or LibreLinkUp

bastiaanv avatar Aug 14 '24 17:08 bastiaanv

Hi @partcoffee ,

This behaviour is correct. The Live Activity doesnt keep iOS from suspending the app (also called Heartbeath). This also means that Loop isn't doing anything while the app is suspended. Jumping to conclusion, I assume you use Loop as a following app (just watching the BG values from NightScout).

There are a few ways to correct this:

  1. Connect a BLE-enabled pump to Loop

  2. Customize Loop to include background sounds (like LoopFollow) or use Location services to keep Loop from being suspended

  3. Or switch to something like xDrip4ios which is a dedicated app to follow BG values from different sources like NightScout or LibreLinkUp

Thanks for the clarification, but I'm using Nightscout as a CGM with Omnipod Dash, which functions as a heartbeat as well from my understanding. Loop is running its normal closed loop activities in the background like bolusing and suspending basal based on the readings from Nightscout.

My CGM is not compatible unfortunately, which is why Nightscout is being used.

The Live Activity is reporting the data as stale immediately, and not after a few minutes, when the app in theory still would be "awake".

partcoffee avatar Aug 14 '24 17:08 partcoffee

@partcoffee My bad. Thank you for the clarification!

I think you are spot on with the 1 minute time interval. The LA has a limit for the amount of data I can send to the widget, too much data leads to the Widget always being stale. So I can limit the amount of samples being send to the widget even further, but that would limit the usages of the LA. You could try to limit the glucoseSamples yourself for the LA maybe to 70: https://github.com/bastiaanv/Loop/blob/feat/live-activity/Loop/Managers/Live%20Activity/GlucoseActivityManager.swift#L183

But the best solution would be to limit the amount of Glucose samples in Nightscout. Maybe the import script you are running allows for something like that?

bastiaanv avatar Aug 14 '24 18:08 bastiaanv

@marionbarker I fixed your reported bugs! I also made that when you open Loop and the LA isn't showing but is activated, that Loop will recreate the LA, without the need to re-enable LA or kill Loop

bastiaanv avatar Aug 14 '24 18:08 bastiaanv

@bastiaanv Thanks for looking in to it! I'll do some tinkering with it myself, I know it's a very niche issue.

I think the best approach would be to alter Nightscout, as you suggested. Loop runs a lot better with 5 minute intervals.

partcoffee avatar Aug 14 '24 18:08 partcoffee

Good luck! If you need help, you can always contact me via DM on Zulipchat

bastiaanv avatar Aug 14 '24 20:08 bastiaanv

@marionbarker Update the PR to include a save button and minor bg coloring fix

bastiaanv avatar Aug 15 '24 15:08 bastiaanv

Not published yet in CustomizationSelect. Testing prior to publishing.

Test result 1

The stale override that expired at end of duration is fixed.

Save is almost ok

The save button is there but does not seem to work quite right.

  1. If I go to the Live Activities screen
    • make a modification
    • save it and then use the Back button and then return to the Live Activities screen - it shows previous value (before I hit save)
  2. If I subsequently view the LA widget on the Lock Screen, the widget does show the update
  3. If I then go back to the Live Activities display, the modifications shows as a requested in Step 1

I rebooted the phone and got the same behavior.

marionbarker avatar Aug 15 '24 18:08 marionbarker

@bastiaanv, thanks so much for putting this together. I put this together last night and had a few notes that I was hoping to pass along for you to consider incorporating into the next commit:

  1. On the lock screen, the deault lime green color of the current glucose reading is difficult to read on my light blue background during the daytime (using the "weather" background). See attached. The contrast needs to be sharper. If it were black or a darker color, it would be easier to read. I see you can remove the BG colors via the Settings, but I think the default "normal" color should be black instead of lime green. IMG_0482
  2. On the lock screen, is it possible to update the grid so it doesn't show areas out of range? In the screenshot above, I am put expected to go in the lower range (the previous low value was 86) so it would make sense to show the grid range as 75-175 like it does within the Loop app itself. Hopefully that makes sense.
  3. In the Settings > Notifications > Live activity screen, the Save button seems to save my changes but doesn't close the window. Unsure why this is happening.

I built this last night with the code. This feature is so awesome. I'm already finding it much more convenient to keep ann eye on things than before. :)

And for those who are not as technically savvy as me, I followed the instructions at https://www.loopandlearn.org/custom-code/ which easily allowed me to pull in a set list of customizations, including this one. :)

rfmurphy81 avatar Sep 08 '24 18:09 rfmurphy81

@rfmurphy81 First of all, thank you for your feedback! Really appreciate it.

I will try to find some time to fix the save button soon!

About point 1: The only option currently is to disable BG colouring, but since the save button doesnt work correctly it is hard to try that option. Other idea: would less opacity in the background be a solution for you? Because I think changing the color would be a solution for your background color, but not for someone else. Having less opacity in the widget would leave the widget less vulnerable to this issue.

About point 2: I found the code for the y-axis calculation for the Loop chart, will use that code as soon as I try to fix the save button!

bastiaanv avatar Sep 11 '24 19:09 bastiaanv