Count update period as number of minutes

This commit is contained in:
nxshock 2021-04-11 10:44:47 +05:00
parent f7c68897c7
commit fce38603d8
3 changed files with 7 additions and 10 deletions

View file

@ -2,7 +2,6 @@ package main
import (
"log"
"time"
"github.com/ilyakaznacheev/cleanenv"
"github.com/ncruces/zenity"
@ -10,7 +9,7 @@ import (
type Config struct {
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
@ -29,10 +28,8 @@ func init() {
log.Fatalln("Город (поле CityName) не может быть пустым.")
}
log.Println(config.UpdatePeriod)
if config.UpdatePeriod < time.Minute {
if config.UpdatePeriodMin <= 0 {
log.Printf("Частота обновлений слишком низкая (%s), будет установлено значение в одну минуту.")
config.UpdatePeriod = time.Minute
config.UpdatePeriodMin = 1
}
}

View file

@ -1,2 +1,2 @@
CityName = "Moscow"
UpdatePeriod = 300_000_000_000 # Кол-во минут * 1_000_000_000
CityName = "Moscow" # Населённый пункт
UpdatePeriodMin = 5 # Период обновления в минутах

View file

@ -54,7 +54,7 @@ func update() {
systray.SetTooltip(fmt.Sprintf("%s\n%.1f °C (%.1f °C)", c.Description(), c.CurrentTemperature(), c.FeelsLikeTemperature()))
setTrayIcon(c.IconName())
time.Sleep(config.UpdatePeriod)
time.Sleep(time.Duration(config.UpdatePeriodMin) * time.Minute)
}
}