When setting a new theme, these three functions need to run in sequence.
AppDefaults.shared.currentThemeName = newValue
updateThemeNames()
updateCurrentTheme()
Within updateThemeNames() there is a `Task { @MainActor in }` that allows `updateCurrentTheme()` to complete before `updateThemeNames()`. In this scenario, when `updateCurrentTheme() is run the app hasnt got an itinerary of installed themes, so it sets the current them back to Default.
Removing the `Task` fixes the persistence issue.
When the widget encoding is completed asynchronously and wrapped in `Task { @MainActor in }`, the app rarely (if ever) refreshes the widget unless attached to the debugger (in which case, unhelpfully, it works fine).
My thinking is that the app is being terminated _before_ `encode` is complete and therefore the call to refresh widget timelines is not happening consistently.
Moving the widget to synchronous encoding has resolved the widget refresh behaviour.
Rewrite `encode()`:
- Remove file removal checks, writing data will replace
- Compare existing widget data to new data and determine which widgets actually need refreshed
Refactor `flushSharedContainer` to `removeStaleFaviconsFromSharedContainer`:
- No longer nuked in full
- Only favicons not accessed in the last seven days are deleted (in DEBUG builds this is 30 seconds)
Improve `writeImageDataToSharedContainer`:
- Favicons now use their md5 digest instead of a UUID (thus one image per feed, instead of one image per article)
- If the favicon exists it is not rewritten
Add `reloadTimelines`:
- Compares existing article arrays to new article arrays and will only reload specific widget timelines where there is a difference.
- `LatestArticle` now conforms to `Hashable` to make this possible.
Improve `SceneDelegate` selection logic:
- select the correct feed before selecting the article