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 3 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
15 changes: 14 additions & 1 deletion cmd/fyne/internal/commands/package-unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,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 +56,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: p.linuxAndBSDMetadata.Keywords,
Comment: p.linuxAndBSDMetadata.Comment,
Categories: p.linuxAndBSDMetadata.Categories,
}
err = templates.DesktopFileUNIX.Execute(deskFile, tplData)
if err != nil {
return fmt.Errorf("failed to write desktop entry string: %w", err)
Expand Down
4 changes: 3 additions & 1 deletion cmd/fyne/internal/commands/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
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.

4 changes: 4 additions & 0 deletions cmd/fyne/internal/templates/data/app.desktop
Original file line number Diff line number Diff line change
@@ -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 -}}
8 changes: 7 additions & 1 deletion 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 build with debug symbol"

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

[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;"
Copy link
Member

Choose a reason for hiding this comment

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

Is the trailing ";" optional? It doesn't seem natural to have it here.
Also should we use a more common list separator for Go developers and convert it where required for the output?

?Perhaps even making it a toml list instead of string?

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 don't know if it technically is required but the official documentation uses it.
https://freedesktop.org/wiki/Howto_desktop_files/

Copy link
Member Author

Choose a reason for hiding this comment

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

A TOML list sounds like a great idea :)

Copy link
Member

Choose a reason for hiding this comment

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

I don't know if it technically is required but the official documentation uses it.

https://freedesktop.org/wiki/Howto_desktop_files/

By using FDo formatting you still require folk to understand the spec - which we should avoid if possible just like how naming avoids it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed but I've switched to TOML lists now so it should no longer be an issue.

Comment = "A demo of Fyne and its capabilities."
Keywords = "demo;fyne;"