From fce38603d8c3e10a1c0c255ac01e1c91cf82c9de Mon Sep 17 00:00:00 2001 From: nxshock Date: Sun, 11 Apr 2021 10:44:47 +0500 Subject: [PATCH] Count update period as number of minutes --- config.go | 11 ++++------- config.toml | 4 ++-- main.go | 2 +- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/config.go b/config.go index 21d8b23..6228012 100644 --- a/config.go +++ b/config.go @@ -2,15 +2,14 @@ package main import ( "log" - "time" "github.com/ilyakaznacheev/cleanenv" "github.com/ncruces/zenity" ) type Config struct { - CityName string `toml:"CityName" env:"CITY_NAME"` - UpdatePeriod time.Duration `toml:"UpdatePeriod", env:"UPDATE_PERIOD"` + CityName string `toml:"CityName" env:"CITY_NAME"` + 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 } } diff --git a/config.toml b/config.toml index 48827a2..e040721 100644 --- a/config.toml +++ b/config.toml @@ -1,2 +1,2 @@ -CityName = "Moscow" -UpdatePeriod = 300_000_000_000 # Кол-во минут * 1_000_000_000 +CityName = "Moscow" # Населённый пункт +UpdatePeriodMin = 5 # Период обновления в минутах diff --git a/main.go b/main.go index cf3d813..00875c7 100644 --- a/main.go +++ b/main.go @@ -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) } }