-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlinux.go
More file actions
56 lines (47 loc) · 1.25 KB
/
linux.go
File metadata and controls
56 lines (47 loc) · 1.25 KB
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
50
51
52
53
54
55
56
package main
import (
"fmt"
"log"
"os"
"os/user"
"path/filepath"
"runtime"
)
const linuxDesktopTemplate = `
[Desktop Entry]
Name=badger-gui
Exec=%s
Icon=badger-gui
Type=Application
Categories=Network;Social;
`
func setLinuxDesktopIcon(iconData []byte) {
if runtime.GOOS != "linux" {
return
}
if os.Getenv("SNAP") != "" { // snap package
return
}
currentUser, err := user.Current()
if err != nil {
panic(err)
}
homeDir := currentUser.HomeDir
desktopDir := filepath.Join(homeDir, ".local", "share", "applications")
iconDir := filepath.Join(homeDir, ".local", "share", "icons", "hicolor", "512x512", "apps")
_ = os.MkdirAll(desktopDir, 0755)
_ = os.MkdirAll(iconDir, 0755)
execPath, err := os.Executable()
if err != nil {
log.Fatalf("setting icon: unable to determine executable path: %v", err)
}
desktopFile := filepath.Join(desktopDir, "badger-gui.desktop")
content := fmt.Sprintf(linuxDesktopTemplate, execPath)
if err := os.WriteFile(desktopFile, []byte(content), 0644); err != nil {
log.Fatalf("setting icon: write .desktop file fail: %v", err)
}
iconPath := filepath.Join(iconDir, "badger-gui.png")
if err := os.WriteFile(iconPath, iconData, 0644); err != nil {
log.Fatalf("setting icon: write icon file fail: %v", err)
}
}