daneden / Solstice

🌅 An app that tells you how the daylight is changing
80 stars 6 forks source link

Bug: widget doesn’t update sometimes #60

Closed Milo123459 closed 2 years ago

Milo123459 commented 2 years ago

image

As you can see, the time is 16:19 and the sunset was 16:05. Shouldn't the widget of updated?

I'm on an iPhone se 2nd edition running the latest iOS (15.2)

Milo123459 commented 2 years ago

Even when I click the widget, it's not updating.

Milo123459 commented 2 years ago

The widget now looks like this - it appears to be counting backwards!image

daneden commented 2 years ago

Hey @Milo123459, thanks for this bug report! I should be able to fix this by ensuring that the widget’s timeline entries include times corresponding with the day’s sunrise/sunset. Let me look into that!

Milo123459 commented 2 years ago

Thank you so much! Has a new version been released?

daneden commented 2 years ago

@Milo123459 I had submitted to App Store review but then noticed the bug still exhibiting in my "fixed" build 😔 will keep looking into this!

Milo123459 commented 2 years ago

Oh, that's not good! Thanks for keeping to look into this

Milo123459 commented 2 years ago

Also - this is effecting notifications as well. I have something to notify me when the sunrises which today was at 08:06 but I got it 30 minutes later at 08:36 - I believe this is related

daneden commented 2 years ago

@Milo123459 It's unlikely that the issues are related.

Widgets (and watchOS complications) expect a timeline of entries, which the system renders on a schedule. Once the system reaches the end of the timeline, a new one is requested. The widget bug is caused by this timeline not including (or updating at) the sunrise/sunset times, meaning it could be several minutes before it updates the UI to reflect the day beginning/ending.

The notifications work slightly differently. When the app is opened, or when a background task runs, it schedules a batch of notifications, one per day, using your notification preferences. From what I understand, the notification system may sometimes delay notifications in order to send them at a time when the resources to do so are available; that said, 30min seems like a stretch. Are you sure your preferences are set to send the notification 1min before/after sunrise?

Milo123459 commented 2 years ago

image That's my notifications config

daneden commented 2 years ago

@Milo123459 its not super obvious, but you also can configure the time offset (which defaults to 30min) and whether notifications are sent before/after sunrise/sunset, back on the main settings screen (see the linked video)

https://user-images.githubusercontent.com/439365/148429283-7899d91e-28f6-4497-8e99-49d536d23d54.MOV

daneden commented 2 years ago

I think this is properly fixed now; released 1.4.2 on the App Store last night, will keep monitoring the widget to be sure!

daneden commented 2 years ago

Still present in 1.4.2 🥲

Milo123459 commented 2 years ago

This is seeming to be a challenge! Sorry that I can't help that much, but I appreciate the work being put into it :)

daneden commented 2 years ago

I can finally close this! v1.4.3 (waiting for review) fixes this with two changes:

  1. I realised I wasn't actually asking the widget to update at the correct time. I’ve fixed this!
  2. Even with (1), WidgetKit doesn’t always update exactly at the provided time. I can ask for an update after date, but iOS might not update the widget until several seconds or even hours after the requested date. To overcome this, the countdown string now has better formatting: before it said “N seconds until {sunrise/sunset}”, which obviously appears broken when N is increasing. Now it says “{Sunrise/Sunset} {in} N seconds {ago}” using Swift’s built-in formatting.
Milo123459 commented 2 years ago

That's fantastic news! Thanks for looking into this :)