From b7b722563eea38fc261d4e195be090621f8639a3 Mon Sep 17 00:00:00 2001 From: Jacalz Date: Wed, 7 Jun 2023 20:52:53 +0200 Subject: [PATCH 1/6] Initial support for Linux and BSD specific metadata --- cmd/fyne/internal/commands/package-unix.go | 23 +++++++++++++++++++- cmd/fyne/internal/metadata/data.go | 9 ++++++++ cmd/fyne/internal/templates/bundled.go | 2 +- cmd/fyne/internal/templates/data/app.desktop | 4 ++++ cmd/fyne_demo/FyneApp.toml | 8 ++++++- 5 files changed, 43 insertions(+), 3 deletions(-) diff --git a/cmd/fyne/internal/commands/package-unix.go b/cmd/fyne/internal/commands/package-unix.go index 806523153b..3819f332e9 100644 --- a/cmd/fyne/internal/commands/package-unix.go +++ b/cmd/fyne/internal/commands/package-unix.go @@ -6,6 +6,7 @@ import ( "os" "path/filepath" + "fyne.io/fyne/v2/cmd/fyne/internal/metadata" "fyne.io/fyne/v2/cmd/fyne/internal/templates" "golang.org/x/sys/execabs" @@ -14,6 +15,10 @@ import ( type unixData struct { Name, Exec, Icon string Local string + GenericName string + Categories string + Comment string + Keywords string } func (p *Packager) packageUNIX() error { @@ -52,7 +57,23 @@ func (p *Packager) packageUNIX() error { desktop := filepath.Join(appsDir, p.Name+".desktop") deskFile, _ := os.Create(desktop) - tplData := unixData{Name: p.Name, Exec: filepath.Base(p.exe), Icon: p.Name + filepath.Ext(p.icon), Local: local} + data, err := metadata.LoadStandard(p.srcDir) + if err != nil { + return fmt.Errorf("failed to load data from FyneApp.toml: %w", err) + } + + fmt.Println(data.LinuxAndBSD) + + tplData := unixData{ + Name: p.Name, + Exec: filepath.Base(p.exe), + Icon: p.Name + filepath.Ext(p.icon), + Local: local, + GenericName: data.LinuxAndBSD.GenericName, + Keywords: data.LinuxAndBSD.Keywords, + Comment: data.LinuxAndBSD.Comment, + Categories: data.LinuxAndBSD.Categories, + } err = templates.DesktopFileUNIX.Execute(deskFile, tplData) if err != nil { return fmt.Errorf("failed to write desktop entry string: %w", err) diff --git a/cmd/fyne/internal/metadata/data.go b/cmd/fyne/internal/metadata/data.go index 5b00c79533..544464c1dd 100644 --- a/cmd/fyne/internal/metadata/data.go +++ b/cmd/fyne/internal/metadata/data.go @@ -6,6 +6,7 @@ type FyneApp struct { Details AppDetails Development map[string]string `toml:",omitempty"` Release map[string]string `toml:",omitempty"` + LinuxAndBSD LinuxAndBSD } // AppDetails describes the build information, this group may be OS or arch specific @@ -15,3 +16,11 @@ type AppDetails struct { Version string `toml:",omitempty"` Build int `toml:",omitempty"` } + +// LinuxAndBSD describes specific metadata for desktop files on Linux and BSD. +type LinuxAndBSD struct { + GenericName string `toml:",omitempty"` + Categories string `toml:",omitempty"` + Comment string `toml:",omitempty"` + Keywords string `toml:",omitempty"` +} diff --git a/cmd/fyne/internal/templates/bundled.go b/cmd/fyne/internal/templates/bundled.go index b478c58a50..513c5ec90b 100644 --- a/cmd/fyne/internal/templates/bundled.go +++ b/cmd/fyne/internal/templates/bundled.go @@ -23,7 +23,7 @@ var resourceMakefile = &fyne.StaticResource{ var resourceAppDesktop = &fyne.StaticResource{ StaticName: "app.desktop", StaticContent: []byte( - "[Desktop Entry]\nType=Application\nName={{.Name}}\nExec={{.Exec}}\nIcon={{.Name}}\n"), + "[Desktop Entry]\nType=Application\nName={{.Name}}\n{{if ne .GenericName \"\"}}GenericName={{.GenericName}}{{end}}\nExec={{.Exec}}\nIcon={{.Name}}\n{{if ne .Comment \"\"}}Comment={{.Comment}}{{end}}\n{{if ne .Categories \"\"}}Categories={{.Categories}}{{end}}\n{{if ne .Keywords \"\"}}Keywords={{.Keywords}}{{else}}Keywords=fyne;{{end}}"), } var resourceAppManifest = &fyne.StaticResource{ StaticName: "app.manifest", diff --git a/cmd/fyne/internal/templates/data/app.desktop b/cmd/fyne/internal/templates/data/app.desktop index 9efeec3cf5..95f6a833bc 100644 --- a/cmd/fyne/internal/templates/data/app.desktop +++ b/cmd/fyne/internal/templates/data/app.desktop @@ -1,5 +1,9 @@ [Desktop Entry] Type=Application Name={{.Name}} +{{if ne .GenericName ""}}GenericName={{.GenericName}}{{end}} Exec={{.Exec}} Icon={{.Name}} +{{if ne .Comment ""}}Comment={{.Comment}}{{end}} +{{if ne .Categories ""}}Categories={{.Categories}}{{end}} +{{if ne .Keywords ""}}Keywords={{.Keywords}}{{else}}Keywords=fyne;{{end}} \ No newline at end of file diff --git a/cmd/fyne_demo/FyneApp.toml b/cmd/fyne_demo/FyneApp.toml index d94b84037d..793637524f 100644 --- a/cmd/fyne_demo/FyneApp.toml +++ b/cmd/fyne_demo/FyneApp.toml @@ -3,10 +3,16 @@ Name = "Fyne Demo" ID = "io.fyne.demo" Version = "2.3.0" - Build = 10 + Build = 11 [Development] HelperText = "This binary was build with debug symbol" [Release] HelperText = "This binary was build without debug symbol" + +[LinuxAndBSD] + GenericName = "Fyne Demo" + Categories = "Development;" + Comment = "A demo of Fyne and its capabilities." + Keywords = "demo;fyne;" From 0ad5d50eebdd82ffef588e1f9f7549bff2d808b1 Mon Sep 17 00:00:00 2001 From: Jacalz Date: Wed, 7 Jun 2023 20:57:09 +0200 Subject: [PATCH 2/6] cmd/fyne: Don't load package metadata twice --- cmd/fyne/internal/commands/package-unix.go | 16 ++++------------ cmd/fyne/internal/commands/package.go | 4 +++- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/cmd/fyne/internal/commands/package-unix.go b/cmd/fyne/internal/commands/package-unix.go index 3819f332e9..82871ef28b 100644 --- a/cmd/fyne/internal/commands/package-unix.go +++ b/cmd/fyne/internal/commands/package-unix.go @@ -6,7 +6,6 @@ import ( "os" "path/filepath" - "fyne.io/fyne/v2/cmd/fyne/internal/metadata" "fyne.io/fyne/v2/cmd/fyne/internal/templates" "golang.org/x/sys/execabs" @@ -57,22 +56,15 @@ func (p *Packager) packageUNIX() error { desktop := filepath.Join(appsDir, p.Name+".desktop") deskFile, _ := os.Create(desktop) - data, err := metadata.LoadStandard(p.srcDir) - if err != nil { - return fmt.Errorf("failed to load data from FyneApp.toml: %w", err) - } - - fmt.Println(data.LinuxAndBSD) - tplData := unixData{ Name: p.Name, Exec: filepath.Base(p.exe), Icon: p.Name + filepath.Ext(p.icon), Local: local, - GenericName: data.LinuxAndBSD.GenericName, - Keywords: data.LinuxAndBSD.Keywords, - Comment: data.LinuxAndBSD.Comment, - Categories: data.LinuxAndBSD.Categories, + GenericName: p.linuxAndBSDMetadata.GenericName, + Keywords: p.linuxAndBSDMetadata.Keywords, + Comment: p.linuxAndBSDMetadata.Comment, + Categories: p.linuxAndBSDMetadata.Categories, } err = templates.DesktopFileUNIX.Execute(deskFile, tplData) if err != nil { diff --git a/cmd/fyne/internal/commands/package.go b/cmd/fyne/internal/commands/package.go index 2d99257af5..41e2902d23 100644 --- a/cmd/fyne/internal/commands/package.go +++ b/cmd/fyne/internal/commands/package.go @@ -136,7 +136,8 @@ type Packager struct { tags, category string tempDir string - customMetadata keyValueFlag + customMetadata keyValueFlag + linuxAndBSDMetadata metadata.LinuxAndBSD } // AddFlags adds the flags for interacting with the package command. @@ -379,6 +380,7 @@ func (p *Packager) validate() (err error) { p.appData.Release = p.release p.appData.mergeMetadata(data) + p.linuxAndBSDMetadata = data.LinuxAndBSD } exeName := calculateExeName(p.srcDir, p.os) From ac3498c5c4a5b407923d8f849e46d5c7db6fa1cf Mon Sep 17 00:00:00 2001 From: Jacalz Date: Wed, 7 Jun 2023 21:01:38 +0200 Subject: [PATCH 3/6] internal/template: Trim trailing newlines in app.desktop --- cmd/fyne/internal/templates/bundled.go | 2 +- cmd/fyne/internal/templates/data/app.desktop | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/fyne/internal/templates/bundled.go b/cmd/fyne/internal/templates/bundled.go index 513c5ec90b..4694963de8 100644 --- a/cmd/fyne/internal/templates/bundled.go +++ b/cmd/fyne/internal/templates/bundled.go @@ -23,7 +23,7 @@ var resourceMakefile = &fyne.StaticResource{ var resourceAppDesktop = &fyne.StaticResource{ StaticName: "app.desktop", StaticContent: []byte( - "[Desktop Entry]\nType=Application\nName={{.Name}}\n{{if ne .GenericName \"\"}}GenericName={{.GenericName}}{{end}}\nExec={{.Exec}}\nIcon={{.Name}}\n{{if ne .Comment \"\"}}Comment={{.Comment}}{{end}}\n{{if ne .Categories \"\"}}Categories={{.Categories}}{{end}}\n{{if ne .Keywords \"\"}}Keywords={{.Keywords}}{{else}}Keywords=fyne;{{end}}"), + "[Desktop Entry]\nType=Application\nName={{.Name}}\n{{if ne .GenericName \"\"}}GenericName={{.GenericName}}{{end -}}\nExec={{.Exec}}\nIcon={{.Name}}\n{{if ne .Comment \"\"}}Comment={{.Comment}}{{end -}}\n{{if ne .Categories \"\"}}Categories={{.Categories}}{{end -}}\n{{if ne .Keywords \"\"}}Keywords={{.Keywords}}{{else}}Keywords=fyne;{{end -}}"), } var resourceAppManifest = &fyne.StaticResource{ StaticName: "app.manifest", diff --git a/cmd/fyne/internal/templates/data/app.desktop b/cmd/fyne/internal/templates/data/app.desktop index 95f6a833bc..a4a25de00a 100644 --- a/cmd/fyne/internal/templates/data/app.desktop +++ b/cmd/fyne/internal/templates/data/app.desktop @@ -1,9 +1,9 @@ [Desktop Entry] Type=Application Name={{.Name}} -{{if ne .GenericName ""}}GenericName={{.GenericName}}{{end}} +{{if ne .GenericName ""}}GenericName={{.GenericName}}{{end -}} Exec={{.Exec}} Icon={{.Name}} -{{if ne .Comment ""}}Comment={{.Comment}}{{end}} -{{if ne .Categories ""}}Categories={{.Categories}}{{end}} -{{if ne .Keywords ""}}Keywords={{.Keywords}}{{else}}Keywords=fyne;{{end}} \ No newline at end of file +{{if ne .Comment ""}}Comment={{.Comment}}{{end -}} +{{if ne .Categories ""}}Categories={{.Categories}}{{end -}} +{{if ne .Keywords ""}}Keywords={{.Keywords}}{{else}}Keywords=fyne;{{end -}} \ No newline at end of file From cf505a5b8e9d7de75e6ced9c684f9d40a2b96ea7 Mon Sep 17 00:00:00 2001 From: Jacalz Date: Sat, 17 Jun 2023 12:46:49 +0200 Subject: [PATCH 4/6] templates: Fix some issues with app.desktop having incorrect formatting --- cmd/fyne/internal/templates/bundled.go | 2 +- cmd/fyne/internal/templates/data/app.desktop | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/cmd/fyne/internal/templates/bundled.go b/cmd/fyne/internal/templates/bundled.go index 4694963de8..64765a296e 100644 --- a/cmd/fyne/internal/templates/bundled.go +++ b/cmd/fyne/internal/templates/bundled.go @@ -23,7 +23,7 @@ var resourceMakefile = &fyne.StaticResource{ var resourceAppDesktop = &fyne.StaticResource{ StaticName: "app.desktop", StaticContent: []byte( - "[Desktop Entry]\nType=Application\nName={{.Name}}\n{{if ne .GenericName \"\"}}GenericName={{.GenericName}}{{end -}}\nExec={{.Exec}}\nIcon={{.Name}}\n{{if ne .Comment \"\"}}Comment={{.Comment}}{{end -}}\n{{if ne .Categories \"\"}}Categories={{.Categories}}{{end -}}\n{{if ne .Keywords \"\"}}Keywords={{.Keywords}}{{else}}Keywords=fyne;{{end -}}"), + "[Desktop Entry]\nType=Application\nName={{.Name}}\n{{- if ne .GenericName \"\"}}\nGenericName={{.GenericName}}{{end}}\nExec={{.Exec}}\nIcon={{.Name}}\n{{- if ne .Comment \"\"}}\nComment={{.Comment}}{{end}}\n{{- if ne .Categories \"\"}}\nCategories={{.Categories}}{{end}}\n{{if ne .Keywords \"\"}}Keywords={{.Keywords}}{{else}}Keywords=fyne;{{end}}"), } var resourceAppManifest = &fyne.StaticResource{ StaticName: "app.manifest", diff --git a/cmd/fyne/internal/templates/data/app.desktop b/cmd/fyne/internal/templates/data/app.desktop index a4a25de00a..4ed258386a 100644 --- a/cmd/fyne/internal/templates/data/app.desktop +++ b/cmd/fyne/internal/templates/data/app.desktop @@ -1,9 +1,12 @@ [Desktop Entry] Type=Application Name={{.Name}} -{{if ne .GenericName ""}}GenericName={{.GenericName}}{{end -}} +{{- if ne .GenericName ""}} +GenericName={{.GenericName}}{{end}} Exec={{.Exec}} Icon={{.Name}} -{{if ne .Comment ""}}Comment={{.Comment}}{{end -}} -{{if ne .Categories ""}}Categories={{.Categories}}{{end -}} -{{if ne .Keywords ""}}Keywords={{.Keywords}}{{else}}Keywords=fyne;{{end -}} \ No newline at end of file +{{- if ne .Comment ""}} +Comment={{.Comment}}{{end}} +{{- if ne .Categories ""}} +Categories={{.Categories}}{{end}} +{{if ne .Keywords ""}}Keywords={{.Keywords}}{{else}}Keywords=fyne;{{end}} \ No newline at end of file From da177727b2d7ed5bbab9378f2a3ab8ecf19a51d2 Mon Sep 17 00:00:00 2001 From: Jacalz Date: Sat, 17 Jun 2023 12:47:20 +0200 Subject: [PATCH 5/6] commands: Use TOML arrays for categories and keywords --- cmd/fyne/internal/commands/package-unix.go | 13 +++++++++++-- cmd/fyne/internal/commands/package-unix_test.go | 13 +++++++++++++ cmd/fyne/internal/metadata/data.go | 8 ++++---- cmd/fyne_demo/FyneApp.toml | 4 ++-- 4 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 cmd/fyne/internal/commands/package-unix_test.go diff --git a/cmd/fyne/internal/commands/package-unix.go b/cmd/fyne/internal/commands/package-unix.go index 82871ef28b..66171b9dd7 100644 --- a/cmd/fyne/internal/commands/package-unix.go +++ b/cmd/fyne/internal/commands/package-unix.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "path/filepath" + "strings" "fyne.io/fyne/v2/cmd/fyne/internal/templates" @@ -62,9 +63,9 @@ func (p *Packager) packageUNIX() error { Icon: p.Name + filepath.Ext(p.icon), Local: local, GenericName: p.linuxAndBSDMetadata.GenericName, - Keywords: p.linuxAndBSDMetadata.Keywords, + Keywords: formatDesktopFileList(p.linuxAndBSDMetadata.Keywords), Comment: p.linuxAndBSDMetadata.Comment, - Categories: p.linuxAndBSDMetadata.Categories, + Categories: formatDesktopFileList(p.linuxAndBSDMetadata.Categories), } err = templates.DesktopFileUNIX.Execute(deskFile, tplData) if err != nil { @@ -90,3 +91,11 @@ func (p *Packager) packageUNIX() error { return nil } + +func formatDesktopFileList(items []string) string { + if len(items) == 0 { + return "" + } + + return strings.Join(items, ";") + ";" +} diff --git a/cmd/fyne/internal/commands/package-unix_test.go b/cmd/fyne/internal/commands/package-unix_test.go new file mode 100644 index 0000000000..8b78fa5bb9 --- /dev/null +++ b/cmd/fyne/internal/commands/package-unix_test.go @@ -0,0 +1,13 @@ +package commands + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestFormatDesktopFileList(t *testing.T) { + assert.Equal(t, "", formatDesktopFileList([]string{})) + assert.Equal(t, "One;", formatDesktopFileList([]string{"One"})) + assert.Equal(t, "One;Two;", formatDesktopFileList([]string{"One", "Two"})) +} diff --git a/cmd/fyne/internal/metadata/data.go b/cmd/fyne/internal/metadata/data.go index 544464c1dd..e0dc89e396 100644 --- a/cmd/fyne/internal/metadata/data.go +++ b/cmd/fyne/internal/metadata/data.go @@ -19,8 +19,8 @@ type AppDetails struct { // LinuxAndBSD describes specific metadata for desktop files on Linux and BSD. type LinuxAndBSD struct { - GenericName string `toml:",omitempty"` - Categories string `toml:",omitempty"` - Comment string `toml:",omitempty"` - Keywords string `toml:",omitempty"` + GenericName string `toml:",omitempty"` + Categories []string `toml:",omitempty"` + Comment string `toml:",omitempty"` + Keywords []string `toml:",omitempty"` } diff --git a/cmd/fyne_demo/FyneApp.toml b/cmd/fyne_demo/FyneApp.toml index 46800970a2..81b042d81e 100644 --- a/cmd/fyne_demo/FyneApp.toml +++ b/cmd/fyne_demo/FyneApp.toml @@ -13,6 +13,6 @@ [LinuxAndBSD] GenericName = "Fyne Demo" - Categories = "Development;" + Categories = ["Development"] Comment = "A demo of Fyne and its capabilities." - Keywords = "demo;fyne;" + Keywords = ["demo", "fyne"] From 36e4b7f1f6d47e21ff69feb94a1a5e516ed2a173 Mon Sep 17 00:00:00 2001 From: Jacalz Date: Tue, 20 Jun 2023 19:38:50 +0200 Subject: [PATCH 6/6] Use a better GenericName for fyne_demo --- cmd/fyne_demo/FyneApp.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/fyne_demo/FyneApp.toml b/cmd/fyne_demo/FyneApp.toml index 81b042d81e..6300dc49aa 100644 --- a/cmd/fyne_demo/FyneApp.toml +++ b/cmd/fyne_demo/FyneApp.toml @@ -12,7 +12,7 @@ HelperText = "This binary was built without debug symbols" [LinuxAndBSD] - GenericName = "Fyne Demo" + GenericName = "Toolkit Demo" Categories = ["Development"] Comment = "A demo of Fyne and its capabilities." Keywords = ["demo", "fyne"]