Skip to content

Commit

Permalink
desktop/desktopentry: update comments and tests based on review
Browse files Browse the repository at this point in the history
  • Loading branch information
jhenstridge authored and mvo5 committed Sep 6, 2023
1 parent 4850a32 commit a39ba05
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
14 changes: 9 additions & 5 deletions desktop/desktopentry/desktopentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"github.com/snapcore/snapd/strutil"
)

// DesktopEntry represents a freedesktop.org desktop entry file
// DesktopEntry represents a freedesktop.org desktop entry file.
//
// The various fields are as defined in the specification:
// https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html
Expand All @@ -47,7 +47,7 @@ type DesktopEntry struct {
Actions map[string]*Action
}

// Action represents an application action defined in a desktop entry file
// Action represents an application action defined in a desktop entry file.
type Action struct {
Name string
Icon string
Expand All @@ -66,7 +66,7 @@ func splitList(value string) []string {
return strings.FieldsFunc(value, func(r rune) bool { return r == ';' })
}

// Read parses a desktop entry file
// Read parses a desktop entry file.
func Read(filename string) (*DesktopEntry, error) {
f, err := os.Open(filename)
if err != nil {
Expand Down Expand Up @@ -152,6 +152,8 @@ func parse(filename string, r io.Reader) (*DesktopEntry, error) {
de.GnomeAutostartEnabled = value == "true"
case "Actions":
actions = splitList(value)
default:
// Ignore all other keys
}
case desktopActionGroup:
switch key {
Expand All @@ -161,6 +163,8 @@ func parse(filename string, r io.Reader) (*DesktopEntry, error) {
currentAction.Icon = value
case "Exec":
currentAction.Exec = value
default:
// Ignore all other keys
}
}
}
Expand Down Expand Up @@ -208,7 +212,7 @@ func (de *DesktopEntry) ShouldAutostart(currentDesktop []string) bool {
return true
}

// ExpandExec returns the command line used to launch this desktop entry
// ExpandExec returns the command line used to launch this desktop entry.
//
// Macros will be expanded, with the %f, %F, %u, and %U macros using
// the provided list of URIs
Expand All @@ -220,7 +224,7 @@ func (de *DesktopEntry) ExpandExec(uris []string) ([]string, error) {
}

// ExpandActionExec returns the command line used to launch the named
// action of the desktop entry
// action of the desktop entry.
func (de *DesktopEntry) ExpandActionExec(action string, uris []string) ([]string, error) {
if de.Actions[action] == nil {
return nil, fmt.Errorf("desktop file %q does not have action %q", de.Filename, action)
Expand Down
4 changes: 2 additions & 2 deletions desktop/desktopentry/expand_exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ func (s *desktopentrySuite) TestExpandExecHelper(c *C) {
// Special characters within URIs are preserved in the
// final command line.
in: `foo %f`,
uris: []string{"file:///special%20chars%27%22%25%20%24foo"},
out: []string{"foo", `/special chars'"% $foo`},
uris: []string{"file:///special%20chars%5c%27%22%25%20%24foo"},
out: []string{"foo", `/special chars\'"% $foo`},
}} {
c.Logf("tc %d", i)

Expand Down

0 comments on commit a39ba05

Please sign in to comment.