Repository navigation
fix: reload the widgets when fresh readings resume - #119
Merged
Merged
Conversation
After launch or sleep, macOS could leave the desktop widgets on "Open Tidegauge to start" for hours while the app kept writing fresh readings, because nothing asked WidgetKit to rebuild their timelines. WidgetKit accepts a reload only from the app's main executable, so a small Swift function is compiled by build.rs and linked into the binary. The app calls it on the first successful write after any other outcome: at launch and when readings resume after sleep.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On 0.6.1 the desktop widget showed "Open Tidegauge to start" for 12+ hours while the app was running and writing fresh readings every 12 s. macOS had not asked the widget for a new timeline in that time, and the widget's last timeline entry is the "not running" state.
Change
widgets/Center/WidgetCenter.swift: a C-callabletidegauge_reload_widgets()that callsWidgetCenter.shared.reloadAllTimelines().build.rs: compiles it withxcrun swiftcinto a static library and links WidgetKit and the system Swift runtime.src/widget_export.rs: calls it on the first successful write after any other outcome (launch, and resuming after sleep or stale samples). A steady state does not call it again.WidgetKit accepts the reload only from the app's main executable. A helper in
Contents/MacOSgotChronoCoreErrorDomain Code=10, and the same code as the bundle's main executable worked. That is why this links Swift into the binary instead of shipping a helper.Verification
cargo test --locked: 439 passed, 28 ignored.reloadAllTimelines() - reloaded all timelinesfromtidegauge, then the widget extension decoded a snapshot 0.48 s old.otool -Lshows WidgetKit and/usr/lib/swiftruntime only, so nothing new needs to be bundled.Not checked