Skip to content

Commit

Permalink
Add dialog for showing user data
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikKalkoken committed Sep 9, 2024
1 parent b35cb65 commit 212ea46
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 50 deletions.
2 changes: 1 addition & 1 deletion FyneApp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Website = "https://github.com/ErikKalkoken/evebuddy"
Icon = "icon.png"
Name = "EVE Buddy"
ID = "io.github.erikkalkoken.evebuddy"
Version = "0.1.7"
Version = "0.2.0"
Build = 1

[Release]
Expand Down
23 changes: 0 additions & 23 deletions internal/app/ui/about.go

This file was deleted.

43 changes: 42 additions & 1 deletion internal/app/ui/menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import (
"net/url"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/driver/desktop"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
)

func makeMenu(u *ui) *fyne.MainMenu {
Expand Down Expand Up @@ -54,10 +59,46 @@ func makeMenu(u *ui) *fyne.MainMenu {
_ = u.fyneApp.OpenURL(url)
}),
fyne.NewMenuItemSeparator(),
fyne.NewMenuItem("About...", func() {
fyne.NewMenuItem("User data...", func() {
u.showUserDataDialog()
}), fyne.NewMenuItem("About...", func() {
u.showAboutDialog()
}),
)
main := fyne.NewMainMenu(fileMenu, toolsMenu, helpMenu)
return main
}

func (u *ui) showAboutDialog() {
c := container.NewVBox()
info := u.fyneApp.Metadata()
appData := widget.NewRichTextFromMarkdown(
"## " + u.appName() + "\n**Version:** " + info.Version)
c.Add(appData)
uri, _ := url.Parse("https://github.com/ErikKalkoken/evebuddy")
c.Add(widget.NewHyperlink("Website", uri))
c.Add(widget.NewLabel("\"EVE\", \"EVE Online\", \"CCP\", \nand all related logos and images \nare trademarks or registered trademarks of CCP hf."))
c.Add(widget.NewLabel("(c) 2024 Erik Kalkoken"))
d := dialog.NewCustom("About", "Close", c, u.window)
d.Show()
}

func (u *ui) showUserDataDialog() {
f := widget.NewForm(
widget.NewFormItem("Cache", makePathEntry(u.window.Clipboard(), u.ad.Cache)),
widget.NewFormItem("Data", makePathEntry(u.window.Clipboard(), u.ad.Data)),
widget.NewFormItem("Log", makePathEntry(u.window.Clipboard(), u.ad.Log)),
widget.NewFormItem("Settings", makePathEntry(u.window.Clipboard(), u.ad.Settings)),
)
d := dialog.NewCustom("User data", "Close", f, u.window)
d.Show()
}

func makePathEntry(cb fyne.Clipboard, p string) *fyne.Container {
return container.NewHBox(
widget.NewLabel(p),
layout.NewSpacer(),
widget.NewButtonWithIcon("", theme.ContentCopyIcon(), func() {
cb.SetContent(p)
}))
}
7 changes: 5 additions & 2 deletions internal/app/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/ErikKalkoken/evebuddy/internal/app/character"
"github.com/ErikKalkoken/evebuddy/internal/app/eveuniverse"
"github.com/ErikKalkoken/evebuddy/internal/app/humanize"
"github.com/ErikKalkoken/evebuddy/internal/appdirs"
)

// UI constants
Expand All @@ -47,6 +48,7 @@ type ui struct {
fyneApp fyne.App
deskApp desktop.App
window fyne.Window
ad appdirs.AppDirs

assetsArea *assetsArea
assetSearchArea *assetSearchArea
Expand Down Expand Up @@ -81,7 +83,7 @@ type ui struct {
}

// NewUI build the UI and returns it.
func NewUI(fyneApp fyne.App, isDebug bool) *ui {
func NewUI(fyneApp fyne.App, ad appdirs.AppDirs, isDebug bool) *ui {
desk, ok := fyneApp.(desktop.App)
if !ok {
log.Fatal("Failed to initialize as desktop app")
Expand All @@ -92,6 +94,7 @@ func NewUI(fyneApp fyne.App, isDebug bool) *ui {
sfg: new(singleflight.Group),
window: fyneApp.NewWindow(""),
deskApp: desk,
ad: ad,
}
u.attributesArea = u.newAttributesArena()
u.biographyArea = u.newBiographyArea()
Expand Down Expand Up @@ -298,7 +301,7 @@ func (u *ui) ShowAndRun() {
u.startUpdateTickerGeneralSections()
u.startUpdateTickerCharacters()
}()
u.refreshOverview()
go u.refreshOverview()
u.window.ShowAndRun()
}

Expand Down
37 changes: 14 additions & 23 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ import (
)

const (
ssoClientID = "11ae857fe4d149b2be60d875649c05f1"
appID = "io.github.erikkalkoken.evebuddy"
userAgent = "EveBuddy kalkoken87@gmail.com"
dbFileName = "evebuddy.sqlite"
logFileName = "evebuddy.log"
ssoClientID = "11ae857fe4d149b2be60d875649c05f1"
appID = "io.github.erikkalkoken.evebuddy"
userAgent = "EveBuddy kalkoken87@gmail.com"
dbFileName = "evebuddy.sqlite"
logFileName = "evebuddy.log"
logMaxSizeMB = 50
logMaxBackups = 3
)

type logLevelFlag struct {
Expand All @@ -61,9 +63,7 @@ func (l *logLevelFlag) Set(value string) error {
var (
levelFlag logLevelFlag
debugFlag = flag.Bool("debug", false, "Show additional debug information")
logFileFlag = flag.Bool("logfile", true, "Write logs to a file instead of the console")
uninstallFlag = flag.Bool("uninstall", false, "Uninstalls the app by deleting all user files")
// showDirsFlag = flag.Bool("show-dirs", false, "Show directories where user data is stored")
)

func init() {
Expand All @@ -78,13 +78,6 @@ func main() {
if err != nil {
log.Fatal(err)
}
// if *showDirsFlag {
// fmt.Printf("Database: %s\n", ad.data)
// fmt.Printf("Cache: %s\n", ad.cache)
// fmt.Printf("Logs: %s\n", ad.log)
// fmt.Printf("Settings: %s\n", ad.settings)
// return
// }
if *uninstallFlag {
u := uninstall.NewUI(fyneApp, ad)
u.ShowAndRun()
Expand All @@ -98,14 +91,12 @@ func main() {
log.Fatal(err)
}
slog.SetLogLoggerLevel(levelFlag.value)
if *logFileFlag {
fn := fmt.Sprintf("%s/%s", ad.Log, logFileName)
log.SetOutput(&lumberjack.Logger{
Filename: fn,
MaxSize: 50, // megabytes
MaxBackups: 3,
})
}
fn := fmt.Sprintf("%s/%s", ad.Log, logFileName)
log.SetOutput(&lumberjack.Logger{
Filename: fn,
MaxSize: logMaxSizeMB, // megabytes
MaxBackups: logMaxBackups,
})
dsn := fmt.Sprintf("file:%s/%s", ad.Data, dbFileName)
db, err := storage.InitDB(dsn)
if err != nil {
Expand Down Expand Up @@ -145,7 +136,7 @@ func main() {
cs.StatusCacheService = sc
cs.SSOService = sso.New(ssoClientID, httpClient, cache)

u := ui.NewUI(fyneApp, *debugFlag)
u := ui.NewUI(fyneApp, ad, *debugFlag)
u.CacheService = cache
u.CharacterService = cs
u.ESIStatusService = esistatus.New(esiClient)
Expand Down

0 comments on commit 212ea46

Please sign in to comment.