mirror of
https://github.com/glanceapp/glance.git
synced 2025-01-08 15:31:17 +01:00
Fix weather widget making HTTP request as part of validation
Which would prevent app startup if there was no internet connection
This commit is contained in:
parent
2af6500028
commit
d2f5dbbc26
@ -27,6 +27,10 @@ var timeLabels24h = [12]string{"02:00", "04:00", "06:00", "08:00", "10:00", "12:
|
||||
func (widget *Weather) Initialize() error {
|
||||
widget.withTitle("Weather").withCacheOnTheHour()
|
||||
|
||||
if widget.Location == "" {
|
||||
return fmt.Errorf("location must be specified for weather widget")
|
||||
}
|
||||
|
||||
if widget.HourFormat == "" || widget.HourFormat == "12h" {
|
||||
widget.TimeLabels = timeLabels12h
|
||||
} else if widget.HourFormat == "24h" {
|
||||
@ -41,18 +45,21 @@ func (widget *Weather) Initialize() error {
|
||||
return fmt.Errorf("invalid units '%s' for weather, must be either metric or imperial", widget.Units)
|
||||
}
|
||||
|
||||
place, err := feed.FetchPlaceFromName(widget.Location)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed fetching data for %s: %v", widget.Location, err)
|
||||
}
|
||||
|
||||
widget.Place = place
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (widget *Weather) Update(ctx context.Context) {
|
||||
if widget.Place == nil {
|
||||
place, err := feed.FetchPlaceFromName(widget.Location)
|
||||
|
||||
if err != nil {
|
||||
widget.withError(err).scheduleEarlyUpdate()
|
||||
return
|
||||
}
|
||||
|
||||
widget.Place = place
|
||||
}
|
||||
|
||||
weather, err := feed.FetchWeatherForPlace(widget.Place, widget.Units)
|
||||
|
||||
if !widget.canContinueUpdateAfterHandlingErr(err) {
|
||||
|
Loading…
Reference in New Issue
Block a user