diff --git a/cmd/stash/main.go b/cmd/stash/main.go index e3a54f020..57fedd0e2 100644 --- a/cmd/stash/main.go +++ b/cmd/stash/main.go @@ -76,6 +76,10 @@ func main() { defer pprof.StopCPUProfile() } + // initialise desktop.IsDesktop here so that it doesn't get affected by + // ffmpeg hardware checks later on + desktop.InitIsDesktop() + mgr, err := manager.Initialize(cfg, l) if err != nil { exitError(fmt.Errorf("manager initialization error: %w", err)) diff --git a/internal/desktop/desktop.go b/internal/desktop/desktop.go index a89a3c962..06d400793 100644 --- a/internal/desktop/desktop.go +++ b/internal/desktop/desktop.go @@ -17,6 +17,16 @@ import ( "golang.org/x/term" ) +var isDesktop bool + +// InitIsDesktop sets the value of isDesktop. +// Changed IsDesktop to be evaluated once at startup because if it is +// checked while there are open terminal sessions (such as the ffmpeg hardware +// encoding checks), it may return false. +func InitIsDesktop() { + isDesktop = isDesktopCheck() +} + type FaviconProvider interface { GetFavicon() []byte GetFaviconPng() []byte @@ -59,22 +69,33 @@ func SendNotification(title string, text string) { } func IsDesktop() bool { + return isDesktop +} + +// isDesktop tries to determine if the application is running in a desktop environment +// where desktop features like system tray and notifications should be enabled. +func isDesktopCheck() bool { if isDoubleClickLaunched() { + logger.Debug("Detected double-click launch") return true } // Check if running under root if os.Getuid() == 0 { + logger.Debug("Running as root, disabling desktop features") return false } // Check if stdin is a terminal if term.IsTerminal(int(os.Stdin.Fd())) { + logger.Debug("Running in terminal, disabling desktop features") return false } if isService() { + logger.Debug("Running as a service, disabling desktop features") return false } if IsServerDockerized() { + logger.Debug("Running in docker, disabling desktop features") return false }