From 031d98e29a0b882f4551fd6944c06353a1941fce Mon Sep 17 00:00:00 2001 From: Zhbert Date: Thu, 14 Dec 2023 23:14:56 +0300 Subject: [PATCH 1/2] Add tray parameter into config file Signed-off-by: Zhbert --- internal/gui/main_window/main_window.go | 12 ++++-------- internal/services/config/config_file.go | 3 +++ internal/services/config/structs/config_struct.go | 3 +++ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/internal/gui/main_window/main_window.go b/internal/gui/main_window/main_window.go index 263d035..a845fa7 100644 --- a/internal/gui/main_window/main_window.go +++ b/internal/gui/main_window/main_window.go @@ -32,6 +32,7 @@ import ( "fyne.io/fyne/v2/theme" "fyne.io/fyne/v2/widget" "impomoro/internal/gui/resources" + "impomoro/internal/gui/tray" "impomoro/internal/services/config" "impomoro/internal/services/notifications" "impomoro/internal/services/time_services" @@ -54,7 +55,9 @@ func StartMainWindow() { window := application.NewWindow("impomoro") - // tray.MakeTray(application, window) + if confOpts.System.EnableTray { + tray.MakeTray(application, window) + } content := container.NewPadded() verticalBoxLayout := container.NewVBox() @@ -183,14 +186,7 @@ func StartMainWindow() { window.SetContent(content) window.Resize(fyne.NewSize(float32(confOpts.Display.Width), float32(confOpts.Display.Height))) - window.CenterOnScreen() - - // indow.SetCloseIntercept(func() { - // window.Hide() - // }) - - // window.SetOnClosed(window.Close) window.ShowAndRun() } diff --git a/internal/services/config/config_file.go b/internal/services/config/config_file.go index 7e74586..3bd490a 100644 --- a/internal/services/config/config_file.go +++ b/internal/services/config/config_file.go @@ -99,6 +99,9 @@ func getDefaultConfigStruct() structs.ConfigOptions { LongTime int ShortTime int }{LongTime: 25, ShortTime: 5}), + System: struct { + EnableTray bool `yaml:"enableTray"` + }(struct{ EnableTray bool }{EnableTray: false}), } } diff --git a/internal/services/config/structs/config_struct.go b/internal/services/config/structs/config_struct.go index a455c6b..efc7509 100644 --- a/internal/services/config/structs/config_struct.go +++ b/internal/services/config/structs/config_struct.go @@ -33,4 +33,7 @@ type ConfigOptions struct { LongTime int `yaml:"longTime"` ShortTime int `yaml:"shortTime"` } `yaml:"time"` + System struct { + EnableTray bool `yaml:"enableTray"` + } `yaml:"system"` } From e852f830458380f19bc8431310f346833f53b0d3 Mon Sep 17 00:00:00 2001 From: Zhbert Date: Thu, 14 Dec 2023 23:30:27 +0300 Subject: [PATCH 2/2] Add comments into code Signed-off-by: Zhbert --- internal/app/app.go | 6 ++++-- internal/gui/main_window/help_dialog.go | 8 ++++++++ internal/gui/main_window/main_window.go | 4 ++++ internal/gui/resources/icons.go | 4 ++++ internal/gui/tray/tray.go | 4 ++++ internal/services/config/app_icon.go | 9 +++++++++ internal/services/config/common.go | 4 ++++ internal/services/config/structs/config_struct.go | 4 ++++ internal/services/notifications/notifications.go | 4 ++++ internal/services/time_services/time_transformations.go | 4 ++++ 10 files changed, 49 insertions(+), 2 deletions(-) diff --git a/internal/app/app.go b/internal/app/app.go index f831249..68f092c 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -27,11 +27,13 @@ package app import ( "impomoro/internal/gui/main_window" "impomoro/internal/services/config" - "log" ) +/****************************************************************************** +* Application launch function +******************************************************************************/ + func Run() { - log.Println("The application has started") config.DetectConfigFile() config.CreateMainIcon() main_window.StartMainWindow() diff --git a/internal/gui/main_window/help_dialog.go b/internal/gui/main_window/help_dialog.go index 361f654..b1aa796 100644 --- a/internal/gui/main_window/help_dialog.go +++ b/internal/gui/main_window/help_dialog.go @@ -34,6 +34,10 @@ import ( "net/url" ) +/****************************************************************************** +* Window content generation function +******************************************************************************/ + func getContent() fyne.CanvasObject { verticalLayout := container.NewVBox() @@ -61,6 +65,10 @@ func getContent() fyne.CanvasObject { return verticalLayout } +/****************************************************************************** +* Displaying the dialog box +******************************************************************************/ + func ShowHelpWindow(win *fyne.Window) { dialog.ShowCustom("About", "OK", getContent(), *win) log.Println("Showed help window") diff --git a/internal/gui/main_window/main_window.go b/internal/gui/main_window/main_window.go index a845fa7..c5f7689 100644 --- a/internal/gui/main_window/main_window.go +++ b/internal/gui/main_window/main_window.go @@ -42,6 +42,10 @@ import ( var shortPeriod = false +/****************************************************************************** +* Generating and displaying the main window +******************************************************************************/ + func StartMainWindow() { application := app.New() application.SetIcon(resources.TomatoIcon) diff --git a/internal/gui/resources/icons.go b/internal/gui/resources/icons.go index ce7b9b9..fe1044a 100644 --- a/internal/gui/resources/icons.go +++ b/internal/gui/resources/icons.go @@ -26,6 +26,10 @@ package resources import "impomoro/internal/gui/resources/icons" +/****************************************************************************** +* Application Icon Resources +******************************************************************************/ + var TomatoIcon = icons.ResourceTomatoPng var PlayIcon = icons.ResourcePlayPng var PauseIcon = icons.ResourcePausePng diff --git a/internal/gui/tray/tray.go b/internal/gui/tray/tray.go index 2de6986..99c0347 100644 --- a/internal/gui/tray/tray.go +++ b/internal/gui/tray/tray.go @@ -29,6 +29,10 @@ import ( "fyne.io/fyne/v2/driver/desktop" ) +/****************************************************************************** +* Launching and displaying the tray +******************************************************************************/ + func MakeTray(a fyne.App, w fyne.Window) { if desk, ok := a.(desktop.App); ok { showItem := fyne.NewMenuItem("Show", func() { diff --git a/internal/services/config/app_icon.go b/internal/services/config/app_icon.go index de90514..17ea46e 100644 --- a/internal/services/config/app_icon.go +++ b/internal/services/config/app_icon.go @@ -35,6 +35,11 @@ import ( "path/filepath" ) +/****************************************************************************** +* Creating an icon in a directory with configuration files from application +* resources +******************************************************************************/ + func CreateMainIcon() { usr, err := user.Current() if err != nil { @@ -62,6 +67,10 @@ func CreateMainIcon() { } } +/****************************************************************************** +* Getting the path to the icon file in the directory with the configuration file +******************************************************************************/ + func GetIconPath() string { usr, err := user.Current() if err != nil { diff --git a/internal/services/config/common.go b/internal/services/config/common.go index 231384c..aa66b28 100644 --- a/internal/services/config/common.go +++ b/internal/services/config/common.go @@ -24,6 +24,10 @@ package config +/****************************************************************************** +* Common constants with resource paths +******************************************************************************/ + const ( folderName = ".impomoro" fileName = "config.yml" diff --git a/internal/services/config/structs/config_struct.go b/internal/services/config/structs/config_struct.go index efc7509..c72ec89 100644 --- a/internal/services/config/structs/config_struct.go +++ b/internal/services/config/structs/config_struct.go @@ -24,6 +24,10 @@ package structs +/****************************************************************************** +* The structure of the configuration file +******************************************************************************/ + type ConfigOptions struct { Display struct { Width int `yaml:"width"` diff --git a/internal/services/notifications/notifications.go b/internal/services/notifications/notifications.go index b77677f..556c52b 100644 --- a/internal/services/notifications/notifications.go +++ b/internal/services/notifications/notifications.go @@ -30,6 +30,10 @@ import ( "log" ) +/****************************************************************************** +* Displaying the system notification +******************************************************************************/ + func ShowNotification(title string, message string) { err := beeep.Notify(title, message, config.GetIconPath()) if err != nil { diff --git a/internal/services/time_services/time_transformations.go b/internal/services/time_services/time_transformations.go index 31b7273..b2be714 100644 --- a/internal/services/time_services/time_transformations.go +++ b/internal/services/time_services/time_transformations.go @@ -26,6 +26,10 @@ package time_services import "fmt" +/****************************************************************************** +* Converting seconds to minutes +******************************************************************************/ + func SecondsToMinutes(inSeconds int) string { minutes := inSeconds / 60 seconds := inSeconds % 60