go-desktopenv

module
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2026 License: MIT

README

go-desktopenv

Go


What a packaged Go desktop app needs to reach its desktop: xdg-desktop-portal calls, Flatpak detection and host commands, per-user folders, console-less Windows children, Desktop Entry Exec values, an AppImage-free child environment, installed fonts, the system accent colour, the UI language, Windows shortcut files, URL scheme handling, browser native messaging, start-at-sign-in, revealing a path, the desktop wallpaper and Windows Firewall rules. Module github.com/Rethunk-Tech/go-desktopenv, sixteen packages: portal, flatpak, userdirs, desktopentry, nowindow, hostenv, fonts, sysaccent, locale, lnk, schemehandler, nativemessaging, autostart, reveal, wallpaper and firewall. Import only the ones you need; portal pulls in godbus, lnk and firewall go-ole on Windows, nowindow, fonts, sysaccent, locale, schemehandler, nativemessaging, autostart, wallpaper and firewall golang.org/x/sys on Windows, and schemehandler, nativemessaging, hostenv and reveal go-safefs. The rest pull in no third-party code.

A Flatpak app needs --talk-name=org.freedesktop.Flatpak for flatpak; portals need nothing extra. A portal call waits on a user dialog until its context ends, so set a deadline. RetrieveSecret works only inside a Flatpak.

Quick start

go get github.com/Rethunk-Tech/go-desktopenv

A worked example and the contracts: HUMANS.md.

Features

  • portal: autostart, launchers, the per-app secret, desktop settings and notifications (with click and button actions), each bounded by your context
  • flatpak: detect a sandbox, run or build a command for the host, end the host child on cancel
  • userdirs: config and data folders per home, honouring only absolute environment values for the real home
  • desktopentry: escape, build and read Desktop Entry Exec= values, write a file from keys, and rewrite one key
  • nowindow: no console window for a console child of a Windows GUI process
  • hostenv: a child process's environment without what an AppImage's AppRun injected; Launchable is $APPIMAGE when exe runs from that AppImage's $APPDIR mount, else exe
  • fonts: the installed font families, from fontconfig or the Windows registry
  • sysaccent: the desktop's accent colour as #rrggbb, from the DWM or the Settings portal
  • reveal: show a path in the system file manager (xdg-open, or explorer with comma-safe quoting); wallpaper: the desktop wallpaper path (GNOME gsettings, dark variant by colour-scheme, or Windows HKCU Desktop Wallpaper)
  • locale: the user's UI language as a BCP-47-ish tag, from the Windows preferred UI languages or LC_ALL, LC_MESSAGES and LANG
  • lnk: write a Windows .lnk with target, arguments, working folder, icon and description, read its arguments, list a folder's shortcuts
  • schemehandler: register a program for URL schemes (desktop entry and xdg-mime defaults, or HKCU classes), yield to an AppImage integrator's entry, hand each scheme back to its previous handler, forward a URL to that handler, and report who owns a scheme
  • nativemessaging: write, remove and check browser native-messaging host manifests for Chromium-family browsers and Firefox, and read and write the length-prefixed stdio frames
  • autostart: enable, disable and report start-at-sign-in (XDG autostart or the Background portal inside a Flatpak, HKCU Run on Windows)
  • firewall: read Windows Firewall profile types, check and add an inbound allow rule for a program, and self-elevate the add through runas

Documentation

Doc Audience
HUMANS.md Running and using the package
AGENTS.md Internals, invariants, and why
CONTRIBUTING.md Process — commits, tests, docs
SECURITY.md Vulnerability disclosure
CHANGELOG.md Release notes

License

MIT — see LICENSE. © 2026 Rethunk.Tech, LLC.

Directories

Path Synopsis
Package autostart starts a program at sign-in, or stops doing so.
Package autostart starts a program at sign-in, or stops doing so.
Package desktopentry escapes and reads the string values of a freedesktop Desktop Entry file, writes one from its keys, and rewrites a single key while keeping the rest.
Package desktopentry escapes and reads the string values of a freedesktop Desktop Entry file, writes one from its keys, and rewrites a single key while keeping the rest.
Package firewall reads Windows Firewall profile types and inbound rules for a program, adds an inbound allow rule, and self-elevates that add through ShellExecuteExW runas.
Package firewall reads Windows Firewall profile types and inbound rules for a program, adds an inbound allow rule, and self-elevates that add through ShellExecuteExW runas.
Package flatpak detects a Flatpak sandbox and runs commands on the host from inside one.
Package flatpak detects a Flatpak sandbox and runs commands on the host from inside one.
Package fonts lists the font families installed on this computer.
Package fonts lists the font families installed on this computer.
Package hostenv gives child processes the environment the program was started from, minus what an AppImage's AppRun injected for the bundle's own libraries.
Package hostenv gives child processes the environment the program was started from, minus what an AppImage's AppRun injected for the bundle's own libraries.
internal
hostfile
Package hostfile reaches the user's desktop configuration (mimeapps.list, browser manifests) where it lives: the plain file call outside a Flatpak, a host sh script through flatpak-spawn inside one, which is not granted those files.
Package hostfile reaches the user's desktop configuration (mimeapps.list, browser manifests) where it lives: the plain file call outside a Flatpak, a host sh script through flatpak-spawn inside one, which is not granted those files.
Package lnk writes and reads Windows .lnk shortcut files, the Windows counterpart of package desktopentry.
Package lnk writes and reads Windows .lnk shortcut files, the Windows counterpart of package desktopentry.
Package locale reads the language the user has chosen for their desktop.
Package locale reads the language the user has chosen for their desktop.
Package nativemessaging lets a browser extension start this program as a native-messaging host: it writes and removes the host manifests Chromium-family browsers and Firefox look for, reports whether each installed browser's manifest points at the program, and reads and writes the stdio frames the browser exchanges with the host.
Package nativemessaging lets a browser extension start this program as a native-messaging host: it writes and removes the host manifests Chromium-family browsers and Firefox look for, reports whether each installed browser's manifest points at the program, and reads and writes the stdio frames the browser exchanges with the host.
Package nowindow starts console programs from a GUI process without a console window.
Package nowindow starts console programs from a GUI process without a console window.
Package portal calls the xdg-desktop-portal interfaces a Flatpak app uses instead of writing host folders: the Background portal for starting at sign-in, DynamicLauncher for desktop launchers, Secret for a per-app master secret, Settings for desktop appearance values, and Notification for desktop notifications.
Package portal calls the xdg-desktop-portal interfaces a Flatpak app uses instead of writing host folders: the Background portal for starting at sign-in, DynamicLauncher for desktop launchers, Secret for a per-app master secret, Settings for desktop appearance values, and Notification for desktop notifications.
Package reveal shows a path in the system file manager.
Package reveal shows a path in the system file manager.
Package schemehandler registers a program as the user's handler of URL schemes, hands each scheme back to the handler it replaced, and forwards a URL to that handler.
Package schemehandler registers a program as the user's handler of URL schemes, hands each scheme back to the handler it replaced, and forwards a URL to that handler.
Package sysaccent reads the accent colour the operating system's desktop is set to.
Package sysaccent reads the accent colour the operating system's desktop is set to.
Package userdirs answers where a user's config and data folders are for a given home.
Package userdirs answers where a user's config and data folders are for a given home.
Package wallpaper reads the path of the desktop wallpaper.
Package wallpaper reads the path of the desktop wallpaper.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL