package sysproxy import ( "os" "path/filepath" "strings" ) // SentinelPath is written while Navis owns the OS system proxy. // Survives crash/kill so the next launch can clear a stuck proxy. func SentinelPath(cfgPath string) string { dir := filepath.Dir(strings.TrimSpace(cfgPath)) if dir == "" || dir == "." { dir, _ = os.UserConfigDir() if dir == "" { dir = os.TempDir() } dir = filepath.Join(dir, "Navis") } return filepath.Join(dir, ".navis-proxy-on") } // WriteSentinel marks that system proxy was enabled by Navis. func WriteSentinel(cfgPath, httpHostPort string) { path := SentinelPath(cfgPath) _ = os.MkdirAll(filepath.Dir(path), 0o755) _ = os.WriteFile(path, []byte(strings.TrimSpace(httpHostPort)+"\n"), 0o600) } // ClearSentinel removes the ownership marker after a clean Disable. func ClearSentinel(cfgPath string) { _ = os.Remove(SentinelPath(cfgPath)) } // HasSentinel reports whether a previous session left the proxy marked on. func HasSentinel(cfgPath string) bool { _, err := os.Stat(SentinelPath(cfgPath)) return err == nil }