mirror of
https://github.com/jahruz67/wisp-open.git
synced 2026-08-08 18:14:08 +00:00
7
This commit is contained in:
@@ -11,15 +11,38 @@ const appName = "wis-free-v3"
|
||||
|
||||
// desktopFileTemplate is filled with execLine built from the absolute binary path.
|
||||
// Paths with spaces must be quoted per the Desktop Entry spec.
|
||||
const desktopFileTemplate = `[Desktop Entry]
|
||||
const baseDesktopFileTemplate = `[Desktop Entry]
|
||||
Type=Application
|
||||
Name=WIS Free V3
|
||||
%s
|
||||
Terminal=false
|
||||
Categories=Utility;
|
||||
X-GNOME-Autostart-enabled=true
|
||||
`
|
||||
|
||||
const autostartDesktopFileTemplate = baseDesktopFileTemplate + "X-GNOME-Autostart-enabled=true\n"
|
||||
|
||||
func EnsureDesktopFile() error {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
appsDir := filepath.Join(home, ".local", "share", "applications")
|
||||
if err := os.MkdirAll(appsDir, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
desktopPath := filepath.Join(appsDir, appName+".desktop")
|
||||
|
||||
exePath, err := getExecutablePath()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
content := fmt.Sprintf(baseDesktopFileTemplate, desktopExecField(exePath))
|
||||
return os.WriteFile(desktopPath, []byte(content), 0644)
|
||||
}
|
||||
|
||||
func getAutostartPath() (string, error) {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
@@ -80,7 +103,7 @@ func AddToStartup() error {
|
||||
return fmt.Errorf("failed to get executable path: %w", err)
|
||||
}
|
||||
|
||||
content := fmt.Sprintf(desktopFileTemplate, desktopExecField(exePath))
|
||||
content := fmt.Sprintf(autostartDesktopFileTemplate, desktopExecField(exePath))
|
||||
if err := os.WriteFile(autostartPath, []byte(content), 0644); err != nil {
|
||||
return fmt.Errorf("failed to write autostart file: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user