Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat(wsl): detect wsl #36

Merged
merged 4 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
6 changes: 4 additions & 2 deletions src/PkgAuthentication.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
14 changes: 14 additions & 0 deletions src/helpers.jl
Original file line number Diff line number Diff line change
@@ -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
Loading