feat(watcher): add macOS autostart support via launchd

This commit is contained in:
Mathis Maquenne
2025-06-23 20:03:56 -04:00
parent 31d8a3b04f
commit a619b37922
3 changed files with 97 additions and 1 deletions
+37
View File
@@ -0,0 +1,37 @@
package watcher
import (
"os"
"path/filepath"
"runtime"
"strings"
)
func EnsureAutostart() error {
if isAutostartInstalled() || isTemporaryExecutable() {
return nil
}
return installAutostart()
}
func isAutostartInstalled() bool {
switch runtime.GOOS {
case "darwin":
path := filepath.Join(os.Getenv("HOME"), "Library", "LaunchAgents", "com.godeez.watch.plist")
_, err := os.Stat(path)
return err == nil
default:
return false
}
}
func isTemporaryExecutable() bool {
exe, err := os.Executable()
if err != nil {
return true
}
return strings.Contains(exe, "go-build")
}