T1.7: Create src/platform/desktop; move desktop integration

Move desktop_linux.go and desktop_other.go from src/core to the new
src/platform/desktop package. Update src/gui to import and use the
new package location.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
mixeme
2026-06-18 22:37:47 +03:00
parent 16d818d03d
commit 794ed8061c
3 changed files with 4 additions and 3 deletions
+65
View File
@@ -0,0 +1,65 @@
//go:build linux
package desktop
import (
"fmt"
"os"
"path/filepath"
"strconv"
)
func InstallDesktopIntegration(appID string, executablePath string, icon []byte) (string, error) {
dataHome, err := xdgDataHome()
if err != nil {
return "", err
}
// The taskbar can only show the application icon reliably when the desktop
// environment can match the window app id to an installed .desktop file and
// icon. Use the user's XDG data directory so portable builds do not need root
// access or a package manager install step.
iconPath := filepath.Join(dataHome, "icons", "hicolor", "256x256", "apps", "gosentry.png")
if err := writeUserFile(iconPath, icon, 0o644); err != nil {
return "", err
}
desktopPath := filepath.Join(dataHome, "applications", appID+".desktop")
desktopFile := fmt.Sprintf(`[Desktop Entry]
Type=Application
Name=GoSentry
Comment=GoSentry desktop scheduler
Exec=%s
Icon=%s
Terminal=false
Categories=Utility;
StartupWMClass=%s
`, quoteDesktopExec(executablePath), iconPath, appID)
if err := writeUserFile(desktopPath, []byte(desktopFile), 0o644); err != nil {
return "", err
}
return iconPath, nil
}
func quoteDesktopExec(path string) string {
return strconv.Quote(path)
}
func xdgDataHome() (string, error) {
dataHome := os.Getenv("XDG_DATA_HOME")
if dataHome == "" {
home, err := os.UserHomeDir()
if err != nil {
return "", err
}
dataHome = filepath.Join(home, ".local", "share")
}
return dataHome, nil
}
func writeUserFile(path string, data []byte, perm os.FileMode) error {
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
return err
}
return os.WriteFile(path, data, perm)
}
+7
View File
@@ -0,0 +1,7 @@
//go:build !linux
package desktop
func InstallDesktopIntegration(appID string, executablePath string, icon []byte) (string, error) {
return "", nil
}