File tree Expand file tree Collapse file tree 2 files changed +31
-24
lines changed Expand file tree Collapse file tree 2 files changed +31
-24
lines changed Original file line number Diff line number Diff line change @@ -300,6 +300,25 @@ defmodule Livebook.Utils do
300300 "data:#{ mime } ;base64,#{ data } "
301301 end
302302
303+ @ doc """
304+ Expands URL received from the Desktop App for opening in the browser.
305+ """
306+ def expand_desktop_url ( "" ) do
307+ LivebookWeb.Endpoint . access_url ( )
308+ end
309+
310+ def expand_desktop_url ( "/settings" ) do
311+ to_string ( % { LivebookWeb.Endpoint . access_struct_url ( ) | path: "/settings" } )
312+ end
313+
314+ def expand_desktop_url ( "file://" <> path ) do
315+ notebook_open_url ( path )
316+ end
317+
318+ def expand_desktop_url ( "livebook://" <> rest ) do
319+ notebook_import_url ( "https://#{ rest } " )
320+ end
321+
303322 @ doc """
304323 Opens the given `url` in the browser.
305324 """
@@ -316,10 +335,15 @@ defmodule Livebook.Utils do
316335
317336 { :unix , _ } ->
318337 cond do
319- System . find_executable ( "xdg-open" ) -> { "xdg-open" , [ url ] }
338+ System . find_executable ( "xdg-open" ) ->
339+ { "xdg-open" , [ url ] }
340+
320341 # When inside WSL
321- System . find_executable ( "cmd.exe" ) -> { "cmd.exe" , win_cmd_args }
322- true -> nil
342+ System . find_executable ( "cmd.exe" ) ->
343+ { "cmd.exe" , win_cmd_args }
344+
345+ true ->
346+ nil
323347 end
324348 end
325349
Original file line number Diff line number Diff line change @@ -15,7 +15,10 @@ if Mix.target() == :app do
1515
1616 @ impl true
1717 def handle_info ( { :event , "open" , url } , state ) do
18- open ( url )
18+ url
19+ |> Livebook.Utils . expand_desktop_url ( )
20+ |> Livebook.Utils . browser_open ( )
21+
1922 { :noreply , state }
2023 end
2124
@@ -24,25 +27,5 @@ if Mix.target() == :app do
2427 Livebook.Config . shutdown ( )
2528 { :noreply , state }
2629 end
27-
28- defp open ( "" ) do
29- open ( LivebookWeb.Endpoint . access_url ( ) )
30- end
31-
32- defp open ( "file://" <> path ) do
33- path
34- |> Livebook.Utils . notebook_open_url ( )
35- |> open ( )
36- end
37-
38- defp open ( "livebook://" <> rest ) do
39- "https://#{ rest } "
40- |> Livebook.Utils . notebook_import_url ( )
41- |> open ( )
42- end
43-
44- defp open ( url ) do
45- Livebook.Utils . browser_open ( url )
46- end
4730 end
4831end
You can’t perform that action at this time.
0 commit comments