diff --git a/src/runtime/http/connection.go b/src/runtime/http/connection.go new file mode 100644 index 00000000..1f81932f --- /dev/null +++ b/src/runtime/http/connection.go @@ -0,0 +1,14 @@ +package http + +import ( + "net" + "time" +) + +// if we can connect to google within 200ms, we are connected +// otherwise, let's consider being offline +func IsConnected() bool { + timeout := 200 * time.Millisecond + _, err := net.DialTimeout("tcp", "google.com:80", timeout) + return err == nil +} diff --git a/src/upgrade/notice.go b/src/upgrade/notice.go index a2a7ba0c..c785303f 100644 --- a/src/upgrade/notice.go +++ b/src/upgrade/notice.go @@ -7,6 +7,7 @@ import ( "github.com/jandedobbeleer/oh-my-posh/src/build" "github.com/jandedobbeleer/oh-my-posh/src/runtime" + "github.com/jandedobbeleer/oh-my-posh/src/runtime/http" ) type release struct { @@ -67,6 +68,10 @@ func Notice(env runtime.Environment, force bool) (string, bool) { return "", false } + if !http.IsConnected() { + return "", false + } + // never validate when we install using the Windows Store if env.Getenv("POSH_INSTALLER") == "ws" { return "", false