1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-04-08 14:52:08 -04:00

weather: fix fallback temporarily

This commit is contained in:
bbedward
2026-02-27 22:37:10 -05:00
parent 7bea6b4a62
commit b9e9da579f
6 changed files with 86 additions and 21 deletions

View File

@@ -3,12 +3,23 @@ package geolocation
import "github.com/AvengeMedia/DankMaterialShell/core/internal/log"
func NewClient() Client {
if geoclueClient, err := newGeoClueClient(); err != nil {
geoclueClient, err := newGeoClueClient()
if err != nil {
log.Warnf("Failed to initialize GeoClue2 client: %v", err)
} else {
log.Info("Falling back to IP location")
return newIpClient()
}
loc, _ := geoclueClient.GetLocation()
if loc.Latitude != 0 || loc.Longitude != 0 {
return geoclueClient
}
log.Info("Falling back to IP location")
return newIpClient()
log.Info("GeoClue2 has no fix yet, seeding with IP location")
ipClient := newIpClient()
if ipLoc, err := ipClient.GetLocation(); err == nil {
geoclueClient.SeedLocation(ipLoc)
}
return geoclueClient
}

View File

@@ -222,6 +222,13 @@ func (c *GeoClueClient) notifySubscribers() {
})
}
func (c *GeoClueClient) SeedLocation(loc Location) {
c.locationMutex.Lock()
defer c.locationMutex.Unlock()
c.currLocation.Latitude = loc.Latitude
c.currLocation.Longitude = loc.Longitude
}
func (c *GeoClueClient) GetLocation() (Location, error) {
c.locationMutex.RLock()
defer c.locationMutex.RUnlock()

View File

@@ -31,10 +31,8 @@ func newIpClient() *IpClient {
func (c *IpClient) Subscribe(id string) chan Location {
ch := make(chan Location, 1)
if location, err := c.GetLocation(); err != nil {
if location, err := c.GetLocation(); err == nil {
ch <- location
} else {
close(ch)
}
return ch

View File

@@ -14,8 +14,9 @@ func NewManager(client geolocation.Client) (*Manager, error) {
}
m := &Manager{
client: client,
dirty: make(chan struct{}),
client: client,
dirty: make(chan struct{}),
stopChan: make(chan struct{}),
state: &State{
Latitude: currLocation.Latitude,