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

Specify custom desktop file fields in FyneApp.toml #3958

Merged
merged 7 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 11 additions & 2 deletions cmd/fyne/internal/commands/package-unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

"fyne.io/fyne/v2/cmd/fyne/internal/templates"

Expand Down Expand Up @@ -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 {
Expand All @@ -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, ";") + ";"
}
13 changes: 13 additions & 0 deletions cmd/fyne/internal/commands/package-unix_test.go
Original file line number Diff line number Diff line change
@@ -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"}))
}
8 changes: 4 additions & 4 deletions cmd/fyne/internal/metadata/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
2 changes: 1 addition & 1 deletion cmd/fyne/internal/templates/bundled.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions cmd/fyne/internal/templates/data/app.desktop
Original file line number Diff line number Diff line change
@@ -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 -}}
{{- if ne .Comment ""}}
Comment={{.Comment}}{{end}}
{{- if ne .Categories ""}}
Categories={{.Categories}}{{end}}
{{if ne .Keywords ""}}Keywords={{.Keywords}}{{else}}Keywords=fyne;{{end}}
4 changes: 2 additions & 2 deletions cmd/fyne_demo/FyneApp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@

[LinuxAndBSD]
andydotxyz marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we make it "Linux,BSD" or "Linux&BSD" it will be machine parsable if we decide to match go's approach to this logic :).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that but it does not seem to be supported. I tried +, ,, and & before opening this PR but neither seem to be supported.

GenericName = "Fyne Demo"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is generic name, and how often should it differ from the Name specified in the details section above?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Rymdport, I have "File Transfer" as GenericName. Just like Firefox has "Web Browser". I hope that helps.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yea thanks. I guess maybe it should be "demo app" or "developer tools" so it's clearer why they are different in this example?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. I'll get that fixed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps "Toolkit Demo" even?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good

Categories = "Development;"
Categories = ["Development"]
Comment = "A demo of Fyne and its capabilities."
Keywords = "demo;fyne;"
Keywords = ["demo", "fyne"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice