-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecoder.go
49 lines (42 loc) · 1.13 KB
/
decoder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package LinuxApps
import (
"errors"
"fmt"
jj "github.com/cloudfoundry-attic/jibber_jabber"
"gopkg.in/ini.v1"
)
func decodeDesktopFile(filepath string) (*AppInfo, error) {
cfg, err := ini.Load(filepath)
if err != nil {
return nil, err
}
entry := cfg.Section("Desktop Entry")
isNoDisplay := entry.Key("NoDisplay").Value()
if isNoDisplay == "true" {
return nil, errors.New("app not to be displayed")
}
name := entry.Key("Name").Value()
description := entry.Key("Comment").Value()
execName := entry.Key("Exec").Value()
iconName := entry.Key("Icon").Value()
// Get info compatible with the System-Language
userLanguage, err := jj.DetectLanguage()
if err == nil {
// Get name
nameKey := entry.Key(fmt.Sprintf("Name[%s]", userLanguage))
if nameKey != nil && nameKey.Value() != "" {
name = nameKey.Value()
}
// Get description
descriptionKey := entry.Key(fmt.Sprintf("Comment[%s]", userLanguage))
if descriptionKey != nil && descriptionKey.Value() != "" {
description = descriptionKey.Value()
}
}
return &AppInfo{
Name: name,
Description: description,
ExecName: execName,
IconName: iconName,
}, nil
}