diff options
| author | Christian Cleberg <[email protected]> | 2026-04-11 19:47:47 -0500 |
|---|---|---|
| committer | Christian Cleberg <[email protected]> | 2026-04-11 19:47:47 -0500 |
| commit | ba773aaa9da5798a458ee58f7ce37db070ada7d8 (patch) | |
| tree | 1485cab8d853d853654b199a4ec8cab4233d06d5 /Shared/ContributionWidgetContext.swift | |
| parent | 61164b6dd8343c8699d091dd5fccc55beb0b90b9 (diff) | |
| download | hutch-2.12.0.tar.gz hutch-2.12.0.tar.bz2 hutch-2.12.0.zip | |
feat: add contribution graph widget with adaptive layoutv2.12.0
Add small and medium widget families showing a trailing contribution
heatmap. Cell size is derived from available height to fill 7 rows,
columns scale with width. Trailing empty weeks are trimmed.
Diffstat (limited to 'Shared/ContributionWidgetContext.swift')
| -rw-r--r-- | Shared/ContributionWidgetContext.swift | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/Shared/ContributionWidgetContext.swift b/Shared/ContributionWidgetContext.swift new file mode 100644 index 0000000..3fadc8a --- /dev/null +++ b/Shared/ContributionWidgetContext.swift @@ -0,0 +1,36 @@ +import Foundation +#if canImport(WidgetKit) +import WidgetKit +#endif + +enum ContributionGraphWidgetConfiguration { + static let kind = "ContributionGraphWidget" +} + +enum ContributionWidgetContextStore { + private static let actorKey = "contributionWidget.actor" + + static func loadActor(defaults: UserDefaults? = sharedDefaults()) -> String? { + defaults?.string(forKey: actorKey) + } + + static func saveActor(_ actor: String, defaults: UserDefaults? = sharedDefaults()) { + defaults?.set(actor, forKey: actorKey) + reloadWidgetTimelines() + } + + static func clear(defaults: UserDefaults? = sharedDefaults()) { + defaults?.removeObject(forKey: actorKey) + reloadWidgetTimelines() + } + + private static func sharedDefaults() -> UserDefaults? { + UserDefaults(suiteName: HutchAppGroup.identifier) + } + + private static func reloadWidgetTimelines() { + #if canImport(WidgetKit) + WidgetCenter.shared.reloadTimelines(ofKind: ContributionGraphWidgetConfiguration.kind) + #endif + } +} |
