File tree 2 files changed +31
-24
lines changed
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
300
300
"data:#{ mime } ;base64,#{ data } "
301
301
end
302
302
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
+
303
322
@ doc """
304
323
Opens the given `url` in the browser.
305
324
"""
@@ -316,10 +335,15 @@ defmodule Livebook.Utils do
316
335
317
336
{ :unix , _ } ->
318
337
cond do
319
- System . find_executable ( "xdg-open" ) -> { "xdg-open" , [ url ] }
338
+ System . find_executable ( "xdg-open" ) ->
339
+ { "xdg-open" , [ url ] }
340
+
320
341
# 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
323
347
end
324
348
end
325
349
Original file line number Diff line number Diff line change @@ -15,7 +15,10 @@ if Mix.target() == :app do
15
15
16
16
@ impl true
17
17
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
+
19
22
{ :noreply , state }
20
23
end
21
24
@@ -24,25 +27,5 @@ if Mix.target() == :app do
24
27
Livebook.Config . shutdown ( )
25
28
{ :noreply , state }
26
29
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
47
30
end
48
31
end
You can’t perform that action at this time.
0 commit comments