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 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
24 changes: 23 additions & 1 deletion 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 All @@ -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 {
Expand Down Expand Up @@ -52,7 +57,16 @@ 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}
tplData := unixData{
Name: p.Name,
Exec: filepath.Base(p.exe),
Icon: p.Name + filepath.Ext(p.icon),
Local: local,
GenericName: p.linuxAndBSDMetadata.GenericName,
Keywords: formatDesktopFileList(p.linuxAndBSDMetadata.Keywords),
Comment: p.linuxAndBSDMetadata.Comment,
Categories: formatDesktopFileList(p.linuxAndBSDMetadata.Categories),
}
err = templates.DesktopFileUNIX.Execute(deskFile, tplData)
if err != nil {
return fmt.Errorf("failed to write desktop entry string: %w", err)
Expand All @@ -77,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"}))
}
4 changes: 3 additions & 1 deletion cmd/fyne/internal/commands/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,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.
Expand Down Expand Up @@ -378,6 +379,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)
Expand Down
9 changes: 9 additions & 0 deletions cmd/fyne/internal/metadata/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"`
}
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.

7 changes: 7 additions & 0 deletions cmd/fyne/internal/templates/data/app.desktop
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
[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}}
12 changes: 9 additions & 3 deletions cmd/fyne_demo/FyneApp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
Name = "Fyne Demo"
ID = "io.fyne.demo"
Version = "2.3.0"
Build = 10
Build = 11

[Development]
HelperText = "This binary was built with debug symbol"
HelperText = "This binary was built with debug symbols"

[Release]
HelperText = "This binary was built without debug symbol"
HelperText = "This binary was built without debug symbols"

[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 = "Toolkit Demo"
Categories = ["Development"]
Comment = "A demo of Fyne and its capabilities."
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