Fix widget voting buttons not responding
- Change openAppWhenRun to false so intent runs in widget extension - Use WidgetDataProvider.add() directly instead of MoodLogger - Reload all timelines after voting for immediate UI update 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -15,8 +15,8 @@ struct VoteMoodIntent: AppIntent {
|
||||
static var title: LocalizedStringResource = "Vote Mood"
|
||||
static var description = IntentDescription("Record your mood for today")
|
||||
|
||||
// Run in main app process - enables full MoodLogger with watch sync
|
||||
static var openAppWhenRun: Bool { true }
|
||||
// Run directly in widget extension for immediate feedback
|
||||
static var openAppWhenRun: Bool = false
|
||||
|
||||
@Parameter(title: "Mood")
|
||||
var moodValue: Int
|
||||
@@ -34,21 +34,16 @@ struct VoteMoodIntent: AppIntent {
|
||||
let mood = Mood(rawValue: moodValue) ?? .average
|
||||
let votingDate = ShowBasedOnVoteLogics.getCurrentVotingDate(onboardingData: UserDefaultsStore.getOnboarding())
|
||||
|
||||
// This code runs in the main app process (openAppWhenRun = true)
|
||||
// Use conditional compilation for widget extension to compile
|
||||
#if !WIDGET_EXTENSION
|
||||
// Main app: use MoodLogger for all side effects including watch sync
|
||||
MoodLogger.shared.logMood(mood, for: votingDate, entryType: .widget)
|
||||
#else
|
||||
// Widget extension compilation path (never executed at runtime)
|
||||
// Save mood via WidgetDataProvider (uses shared App Group container)
|
||||
WidgetDataProvider.shared.add(mood: mood, forDate: votingDate, entryType: .widget)
|
||||
WidgetCenter.shared.reloadAllTimelines()
|
||||
#endif
|
||||
|
||||
// Store last voted date
|
||||
let dateString = ISO8601DateFormatter().string(from: Calendar.current.startOfDay(for: votingDate))
|
||||
GroupUserDefaults.groupDefaults.set(dateString, forKey: UserDefaultsStore.Keys.lastVotedDate.rawValue)
|
||||
|
||||
// Reload all widget timelines to show updated state
|
||||
WidgetCenter.shared.reloadAllTimelines()
|
||||
|
||||
return .result()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user