Skip to content

Commit

Permalink
Merge pull request #18 from Zhbert/add-tray-as-experimental-option
Browse files Browse the repository at this point in the history
[backend][gui] Add tray and comments
  • Loading branch information
Zhbert authored Dec 14, 2023
2 parents f801789 + e852f83 commit b2006b0
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 10 deletions.
6 changes: 4 additions & 2 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 8 additions & 0 deletions internal/gui/main_window/help_dialog.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ import (
"net/url"
)

/******************************************************************************
* Window content generation function
******************************************************************************/

func getContent() fyne.CanvasObject {
verticalLayout := container.NewVBox()

Expand Down Expand Up @@ -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")
Expand Down
16 changes: 8 additions & 8 deletions internal/gui/main_window/main_window.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -41,6 +42,10 @@ import (

var shortPeriod = false

/******************************************************************************
* Generating and displaying the main window
******************************************************************************/

func StartMainWindow() {
application := app.New()
application.SetIcon(resources.TomatoIcon)
Expand All @@ -54,7 +59,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()
Expand Down Expand Up @@ -183,14 +190,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()
}

Expand Down
4 changes: 4 additions & 0 deletions internal/gui/resources/icons.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions internal/gui/tray/tray.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
9 changes: 9 additions & 0 deletions internal/services/config/app_icon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions internal/services/config/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@

package config

/******************************************************************************
* Common constants with resource paths
******************************************************************************/

const (
folderName = ".impomoro"
fileName = "config.yml"
Expand Down
3 changes: 3 additions & 0 deletions internal/services/config/config_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}),
}
}

Expand Down
7 changes: 7 additions & 0 deletions internal/services/config/structs/config_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@

package structs

/******************************************************************************
* The structure of the configuration file
******************************************************************************/

type ConfigOptions struct {
Display struct {
Width int `yaml:"width"`
Expand All @@ -33,4 +37,7 @@ type ConfigOptions struct {
LongTime int `yaml:"longTime"`
ShortTime int `yaml:"shortTime"`
} `yaml:"time"`
System struct {
EnableTray bool `yaml:"enableTray"`
} `yaml:"system"`
}
4 changes: 4 additions & 0 deletions internal/services/notifications/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions internal/services/time_services/time_transformations.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ package time_services

import "fmt"

/******************************************************************************
* Converting seconds to minutes
******************************************************************************/

func SecondsToMinutes(inSeconds int) string {
minutes := inSeconds / 60
seconds := inSeconds % 60
Expand Down

0 comments on commit b2006b0

Please sign in to comment.