mirror of
https://github.com/nxshock/trayweather.git
synced 2025-07-02 00:23:43 +05:00
Count update period as number of minutes
This commit is contained in:
parent
f7c68897c7
commit
fce38603d8
3 changed files with 7 additions and 10 deletions
|
@ -2,7 +2,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/ilyakaznacheev/cleanenv"
|
"github.com/ilyakaznacheev/cleanenv"
|
||||||
"github.com/ncruces/zenity"
|
"github.com/ncruces/zenity"
|
||||||
|
@ -10,7 +9,7 @@ import (
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
CityName string `toml:"CityName" env:"CITY_NAME"`
|
CityName string `toml:"CityName" env:"CITY_NAME"`
|
||||||
UpdatePeriod time.Duration `toml:"UpdatePeriod", env:"UPDATE_PERIOD"`
|
UpdatePeriodMin int `toml:"UpdatePeriod", env:"UPDATE_PERIOD"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var config Config
|
var config Config
|
||||||
|
@ -29,10 +28,8 @@ func init() {
|
||||||
log.Fatalln("Город (поле CityName) не может быть пустым.")
|
log.Fatalln("Город (поле CityName) не может быть пустым.")
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println(config.UpdatePeriod)
|
if config.UpdatePeriodMin <= 0 {
|
||||||
|
|
||||||
if config.UpdatePeriod < time.Minute {
|
|
||||||
log.Printf("Частота обновлений слишком низкая (%s), будет установлено значение в одну минуту.")
|
log.Printf("Частота обновлений слишком низкая (%s), будет установлено значение в одну минуту.")
|
||||||
config.UpdatePeriod = time.Minute
|
config.UpdatePeriodMin = 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
CityName = "Moscow"
|
CityName = "Moscow" # Населённый пункт
|
||||||
UpdatePeriod = 300_000_000_000 # Кол-во минут * 1_000_000_000
|
UpdatePeriodMin = 5 # Период обновления в минутах
|
||||||
|
|
2
main.go
2
main.go
|
@ -54,7 +54,7 @@ func update() {
|
||||||
|
|
||||||
systray.SetTooltip(fmt.Sprintf("%s\n%.1f °C (%.1f °C)", c.Description(), c.CurrentTemperature(), c.FeelsLikeTemperature()))
|
systray.SetTooltip(fmt.Sprintf("%s\n%.1f °C (%.1f °C)", c.Description(), c.CurrentTemperature(), c.FeelsLikeTemperature()))
|
||||||
setTrayIcon(c.IconName())
|
setTrayIcon(c.IconName())
|
||||||
time.Sleep(config.UpdatePeriod)
|
time.Sleep(time.Duration(config.UpdatePeriodMin) * time.Minute)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue