Skip to content

Commit

Permalink
Merge pull request from GHSA-564w-97r7-c6p9
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmach authored and jonatanklosko committed Jun 20, 2023
1 parent 95fac57 commit 2e11b59
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
30 changes: 27 additions & 3 deletions lib/livebook/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,25 @@ defmodule Livebook.Utils do
"data:#{mime};base64,#{data}"
end

@doc """
Expands URL received from the Desktop App for opening in the browser.
"""
def expand_desktop_url("") do
LivebookWeb.Endpoint.access_url()
end

def expand_desktop_url("/settings") do
to_string(%{LivebookWeb.Endpoint.access_struct_url() | path: "/settings"})
end

def expand_desktop_url("file://" <> path) do
notebook_open_url(path)
end

def expand_desktop_url("livebook://" <> rest) do
notebook_import_url("https://#{rest}")
end

@doc """
Opens the given `url` in the browser.
"""
Expand All @@ -316,10 +335,15 @@ defmodule Livebook.Utils do

{:unix, _} ->
cond do
System.find_executable("xdg-open") -> {"xdg-open", [url]}
System.find_executable("xdg-open") ->
{"xdg-open", [url]}

# When inside WSL
System.find_executable("cmd.exe") -> {"cmd.exe", win_cmd_args}
true -> nil
System.find_executable("cmd.exe") ->
{"cmd.exe", win_cmd_args}

true ->
nil
end
end

Expand Down
25 changes: 4 additions & 21 deletions lib/livebook_app.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ if Mix.target() == :app do

@impl true
def handle_info({:event, "open", url}, state) do
open(url)
url
|> Livebook.Utils.expand_desktop_url()
|> Livebook.Utils.browser_open()

{:noreply, state}
end

Expand All @@ -24,25 +27,5 @@ if Mix.target() == :app do
Livebook.Config.shutdown()
{:noreply, state}
end

defp open("") do
open(LivebookWeb.Endpoint.access_url())
end

defp open("file://" <> path) do
path
|> Livebook.Utils.notebook_open_url()
|> open()
end

defp open("livebook://" <> rest) do
"https://#{rest}"
|> Livebook.Utils.notebook_import_url()
|> open()
end

defp open(url) do
Livebook.Utils.browser_open(url)
end
end
end

0 comments on commit 2e11b59

Please sign in to comment.