Skip to content
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
2 changes: 2 additions & 0 deletions cmd/fyne/internal/commands/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type appData struct {
Release, rawIcon bool
CustomMetadata map[string]string
Migrations map[string]bool
OpenWith *metadata.OpenWith
VersionAtLeast2_3 bool
VersionAtLeast2_6 bool
}
Expand Down Expand Up @@ -50,4 +51,5 @@ func (a *appData) mergeMetadata(data *metadata.FyneApp) {
a.appendCustomMetadata(data.Development)
}
a.Migrations = data.Migrations
a.OpenWith = data.OpenWith
}
11 changes: 10 additions & 1 deletion cmd/fyne/internal/commands/package-unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type unixData struct {
Comment string
Keywords string
ExecParams string
MimeTypes string

SourceRepo, SourceDir string
}
Expand Down Expand Up @@ -60,6 +61,13 @@ func (p *Packager) packageUNIX() error {
return fmt.Errorf("failed to copy icon: %w", err)
}

mimes := ""
openWith := ""
if p.OpenWith != nil && p.OpenWith.MimeTypes != "" {
mimes = p.OpenWith.MimeTypes
openWith = " %F"
}

appsDir := util.EnsureSubDir(shareDir, "applications")
desktop := filepath.Join(appsDir, p.AppID+".desktop")
deskFile, err := os.Create(desktop)
Expand All @@ -76,14 +84,15 @@ func (p *Packager) packageUNIX() error {
tplData := unixData{
Name: p.Name,
AppID: p.AppID,
Exec: filepath.Base(p.exe),
Exec: filepath.Base(p.exe) + openWith,
Icon: iconName,
Local: local,
GenericName: linuxBSD.GenericName,
Keywords: formatDesktopFileList(linuxBSD.Keywords),
Comment: linuxBSD.Comment,
Categories: formatDesktopFileList(linuxBSD.Categories),
ExecParams: linuxBSD.ExecParams,
MimeTypes: mimes,
}

if p.sourceMetadata != nil {
Expand Down
13 changes: 13 additions & 0 deletions cmd/fyne/internal/commands/package-unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,16 @@ func TestDesktopFileSource(t *testing.T) {
assert.True(t, strings.Contains(buf.String(), "Repo=https://example.com"))
assert.True(t, strings.Contains(buf.String(), "Dir=cmd/name"))
}

func TestDesktopFileOpenWith(t *testing.T) {
tplData := unixData{
Name: "Testing",
Exec: "tester",
MimeTypes: "text/plain",
}
buf := &bytes.Buffer{}

err := templates.DesktopFileUNIX.Execute(buf, tplData)
assert.Nil(t, err)
assert.True(t, strings.Contains(buf.String(), "MimeType=text/plain"))
}
5 changes: 5 additions & 0 deletions cmd/fyne/internal/metadata/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type FyneApp struct {
Development map[string]string `toml:",omitempty"`
Release map[string]string `toml:",omitempty"`
Source *AppSource `toml:",omitempty"`
OpenWith *OpenWith `toml:",omitempty"`

Choose a reason for hiding this comment

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

I am late on review but shouldn't the naming on this be more like CanOpen *ContentTypes? "OpenWith" sounds more like the OS side of the equation, where the user is choosing which app it wants to associate with a given file type. This is advertising to the OS what types you can open.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks Drew, that is a great point. I will refactor on the landed code.

LinuxAndBSD *LinuxAndBSD `toml:",omitempty"`
Languages []string `toml:",omitempty"`
Migrations map[string]bool `toml:",omitempty"`
Expand All @@ -33,3 +34,7 @@ type LinuxAndBSD struct {
Keywords []string `toml:",omitempty"`
ExecParams string `toml:",omitempty"`
}

type OpenWith struct {
MimeTypes string `toml:",omitempty"`
}
4 changes: 4 additions & 0 deletions cmd/fyne/internal/templates/data/entry.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Comment={{.Comment}}{{end}}
{{- if ne .Categories ""}}
Categories={{.Categories}}{{end}}
Keywords={{if ne .Keywords ""}}{{.Keywords}}{{else}}fyne;{{end}}
{{if or (ne .MimeTypes "") (ne .MimeTypes "") -}}
MimeType={{.MimeTypes}}

{{end -}}

{{if or (ne .SourceRepo "") (ne .SourceDir "") -}}
[X-Fyne Source]
Expand Down
Loading