package keyring import ( "fmt" "runtime" ) // CheckDependencies checks whether the native credential service answered a // bounded read. It never writes a probe value or starts an unlock prompt at // application startup; callers should invoke it only for keyring UI actions. func CheckDependencies() error { status := DetectStatus() if status.ActiveBackend != BackendNone { return nil } if runtime.GOOS == "linux" { return fmt.Errorf("%w: %s\n\nSetup: %s", ErrDaemonNotRunning, status.Error, status.InstallHint) } return fmt.Errorf("%w: %s", ErrNoBackend, status.Error) } // NeedsInstallPrompt reports whether explicit keyring setup is needed. It is // retained for API compatibility; the application no longer calls it during // startup or package update discovery. func NeedsInstallPrompt() bool { return DetectStatus().ActiveBackend == BackendNone } // CanUseKeyring reports whether the native credential store responds. func CanUseKeyring() bool { return CheckDependencies() == nil } // GetSetupInstructions returns setup guidance when the native store cannot be // reached. Linux uses the freedesktop Secret Service protocol for both GNOME // Keyring and current KDE Wallet implementations. func GetSetupInstructions() string { status := DetectStatus() if status.ActiveBackend != BackendNone { return "" } if runtime.GOOS != "linux" { return "The operating system credential store is unavailable: " + status.Error } return fmt.Sprintf( "The desktop Secret Service is unavailable or locked.\n\n%s\n\nLog in to a desktop session, unlock its keyring, and try again.", status.InstallHint, ) } // ValidateSetup returns a read-only, bounded diagnostic. It deliberately does // not create and delete a test credential. func ValidateSetup() (bool, string) { status := DetectStatus() if status.ActiveBackend == BackendNone { return false, fmt.Sprintf("Native keyring unavailable: %s. %s", status.Error, status.InstallHint) } return true, fmt.Sprintf( "Native keyring is responding. Active backend: %s, Desktop: %s, Distro: %s", status.ActiveBackend, status.DesktopEnv, status.Distro, ) }