mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-12-11 06:05:56 +08:00
Fix browser open when inside WSL (#1074)
This commit is contained in:
parent
a70f53de46
commit
6f6b7e3ee0
1 changed files with 24 additions and 5 deletions
|
|
@ -1,6 +1,8 @@
|
||||||
defmodule Livebook.Utils do
|
defmodule Livebook.Utils do
|
||||||
@moduledoc false
|
@moduledoc false
|
||||||
|
|
||||||
|
require Logger
|
||||||
|
|
||||||
@type id :: binary()
|
@type id :: binary()
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
|
@ -308,14 +310,31 @@ defmodule Livebook.Utils do
|
||||||
Opens the given `url` in the browser.
|
Opens the given `url` in the browser.
|
||||||
"""
|
"""
|
||||||
def browser_open(url) do
|
def browser_open(url) do
|
||||||
{cmd, args} =
|
win_cmd_args = ["/c", "start", String.replace(url, "&", "^&")]
|
||||||
|
|
||||||
|
cmd_args =
|
||||||
case :os.type() do
|
case :os.type() do
|
||||||
{:win32, _} -> {"cmd", ["/c", "start", String.replace(url, "&", "^&")]}
|
{:win32, _} ->
|
||||||
{:unix, :darwin} -> {"open", [url]}
|
{"cmd", win_cmd_args}
|
||||||
{:unix, _} -> {"xdg-open", [url]}
|
|
||||||
|
{:unix, :darwin} ->
|
||||||
|
{"open", [url]}
|
||||||
|
|
||||||
|
{:unix, _} ->
|
||||||
|
cond do
|
||||||
|
System.find_executable("xdg-open") -> {"xdg-open", [url]}
|
||||||
|
# When inside WSL
|
||||||
|
System.find_executable("cmd.exe") -> {"cmd.exe", win_cmd_args}
|
||||||
|
true -> nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
System.cmd(cmd, args)
|
case cmd_args do
|
||||||
|
{cmd, args} -> System.cmd(cmd, args)
|
||||||
|
nil -> Logger.warn("could not open the browser, no open command found in the system")
|
||||||
|
end
|
||||||
|
|
||||||
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue