diff --git a/Project.toml b/Project.toml index 99d35a6..d9e3618 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "PkgAuthentication" uuid = "4722fa14-9d28-45f9-a1e2-a38605bd88f0" authors = ["Sebastian Pfitzner", "contributors"] -version = "2.0.3" +version = "2.1.0" [deps] Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6" diff --git a/src/PkgAuthentication.jl b/src/PkgAuthentication.jl index a5ff8bc..28850ae 100644 --- a/src/PkgAuthentication.jl +++ b/src/PkgAuthentication.jl @@ -6,6 +6,8 @@ import Pkg import Random import TOML +include("helpers.jl") + const pkg_server_env_var_name = "JULIA_PKG_SERVER" ## abstract state types @@ -520,8 +522,8 @@ function open_browser(url::AbstractString) @debug "error executing browser hook" exception=(err, catch_backtrace()) return false end - elseif Sys.iswindows() - run(`cmd /c "start $url"`; wait=false) + elseif Sys.iswindows() || detectwsl() + run(`cmd.exe /c "start $url"`; wait=false) elseif Sys.isapple() run(`open $url`; wait=false) elseif Sys.islinux() || Sys.isbsd() diff --git a/src/helpers.jl b/src/helpers.jl new file mode 100644 index 0000000..6a9eda9 --- /dev/null +++ b/src/helpers.jl @@ -0,0 +1,14 @@ +@static if isdefined(Sys, :detectwsl) + const detectwsl = Sys.detectwsl +else + # Borrowed from Julia (MIT license) + # https://github.com/JuliaLang/julia/blob/726c816b9590d748345fb615b76b685c79eafd0d/base/sysinfo.jl#L549-L555 + # https://github.com/JuliaLang/julia/pull/57069 + function detectwsl() + # We use the same approach as canonical/snapd do to detect WSL + islinux() && ( + isfile("/proc/sys/fs/binfmt_misc/WSLInterop") + || isdir("/run/WSL") + ) + end +end