Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add about dialog in tray #28

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ builds:
flags:
- -trimpath
ldflags:
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{ .CommitDate }} -X main.builtBy=goreleaser
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.commitDate={{.CommitDate}}
# Enable macOS "Universal Binaries" (amd64 + arm binaries)
universal_binaries:
- replace: true
Expand Down
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@ import (
"github.com/tomsquest/fynodoro/ui"
)

// Variables set by goreleaser
// We need to put them in a Struct to be able to access them in the UI
var (
version string
commit string
commitDate string
)

func main() {
myApp := app.NewWithID("com.tomsquest.fynodoro")
myApp.Settings().SetTheme(&ui.Theme{})
myApp.SetIcon(ui.AssetIconPng)

ui.Display(myApp)
ui.Display(myApp, ui.BuildInfo{version, commit, commitDate})
}
52 changes: 44 additions & 8 deletions ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ import (
"time"
)

func Display(app fyne.App) {
type BuildInfo struct {
Version string
Commit string
CommitDate string
}

func Display(app fyne.App, buildInfo BuildInfo) {
myPref := pref.Load()
myPomodoro := pomodoro.NewPomodoro(&pomodoro.Params{
WorkDuration: time.Duration(myPref.WorkDuration) * time.Minute,
Expand All @@ -23,21 +29,51 @@ func Display(app fyne.App) {
})

mainWindow := app.NewWindow("Fynodoro")
mainWindow.SetMaster()
mainWindow.SetContent(MakeClassicLayout(myPomodoro))
mainWindow.SetCloseIntercept(mainWindow.Hide)
mainWindow.SetFixedSize(true)

if desk, ok := app.(desktop.App); ok {
trayMenu := fyne.NewMenu(app.Metadata().Name,
aboutWindow := makeAboutWindow(app, buildInfo)
trayMenu := fyne.NewMenu("Fynodoro",
fyne.NewMenuItem("Show", mainWindow.Show),
fyne.NewMenuItem("Hide", mainWindow.Hide),
fyne.NewMenuItem("Center", mainWindow.CenterOnScreen))
fyne.NewMenuItem("Center", mainWindow.CenterOnScreen),
fyne.NewMenuItem("About", aboutWindow.Show))
desk.SetSystemTrayMenu(trayMenu)
}
mainWindow.SetMaster()
mainWindow.SetContent(MakeClassicLayout(myPomodoro))
mainWindow.SetCloseIntercept(func() {
mainWindow.Hide()
})
mainWindow.ShowAndRun()
}

func makeAboutWindow(app fyne.App, buildInfo BuildInfo) fyne.Window {
aboutWindow := app.NewWindow("About Fynodoro")
aboutWindow.SetFixedSize(true)

img := canvas.NewImageFromResource(AssetIconPng)
img.SetMinSize(fyne.NewSquareSize(64))
imgContainer := container.NewHBox(img, layout.NewSpacer())

markdownStr := "# Fynodoro" + "\n"
markdownStr += "" + "\n"
markdownStr += "Fynodoro is a tiny and cute **Pomodoro** Widget" + "\n"
markdownStr += "" + "\n"
markdownStr += "- `Version: " + buildInfo.Version + "`" + "\n"
markdownStr += "- `Commit date: " + buildInfo.CommitDate + " `" + "\n"
markdownStr += "- `Commit: " + buildInfo.Commit + "`" + "\n"
markdown := widget.NewRichTextFromMarkdown(markdownStr)

closeButton := &widget.Button{
Text: "Close",
OnTapped: aboutWindow.Hide,
}
buttonsContainer := container.NewHBox(layout.NewSpacer(), closeButton)

aboutWindow.SetContent(container.NewVBox(imgContainer, markdown, layout.NewSpacer(), buttonsContainer))

return aboutWindow
}

func MakeClassicLayout(myPomodoro *pomodoro.Pomodoro) fyne.CanvasObject {
timer := canvas.NewText(formatDuration(myPomodoro.RemainingTime), nil)
timer.TextSize = 42
Expand Down