Documentation ¶
Overview ¶
Generate and update .desktop (desktop entry) files for Go binaries automatically.
Install ¶
Add it to your project
go get https://github.com/mrf345/desktop-entry@latest
How it works ¶
With the default settings shown in desktopEntry.DesktopEntry the method desktopEntry.DesktopEntry.Create will check your desktopEntry.DesktopEntry.AppsPath for a .desktop file, that matches your desktopEntry.DesktopEntry.Name, if it can't find it, it'll create a new one. That will later on be updated it only when the binary path changes. See test example.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DesktopEntry ¶
type DesktopEntry struct { // Application name (required) Name string // Application version (required) Version string // Application .png icon data (required) Icon []byte // Executable type (default: Application) Type string // Semicolon separated list of categories (default: ”) Categories string // Description of the app (default: ”) Comment string // Architecture (default: x86_64) Arch string // Desktop applications path (default: ~/.local/share/applications) AppsPath string // Desktop icons path (default: ~/.icons) IconsPath string // Default permission for created files and directories (default: 0776) Perm fs.FileMode // Supported operating systems (default: []string{"linux"}) OSs []string // Update if executable path has changed (default: true) UpdateIfChanged bool // Rerun the app if desktop entry has changed (default: true) RerunIfChanged bool // Mime type to associate the desktop entry with MimeType MimeType }
func New ¶
func New(name, version string, icon []byte) *DesktopEntry
Create a new desktopEntry.DesktopEntry instance with the default options
func (*DesktopEntry) Create ¶
func (de *DesktopEntry) Create() (err error)
Creates a new desktop entry or updates an existing one if the executable paths mismatch
Example ¶
package main import ( _ "embed" "fmt" "os" desktopEntry "github.com/mrf345/desktop-entry" ) // assuming you have an existing icon.png file to embed // //go:embed icon.png var icon []byte func main() { // Create an instance and pass the required settings appName := "Desktop Entry" appVersion := "0.0.1" entry := desktopEntry.New(appName, appVersion, icon) // Some optional settings entry.Comment = "package to help creating desktop entry file for Go" entry.Categories = "accessories;Development;" entry.Arch = "arm64" // Changing the apps and icons path to `/tmp` for the test (should ignore this) os.Args[0] = "/tmp" tempDir, _ := os.MkdirTemp("", "de_example") entry.AppsPath = tempDir entry.IconsPath = tempDir defer os.RemoveAll(tempDir) // Make sure to always run it at the beginning of your main function if err := entry.Create(); err != nil { fmt.Println(err) } }
Output:
Click to show internal directories.
Click to hide internal directories.