File tree 2 files changed +31
-30
lines changed
2 files changed +31
-30
lines changed Original file line number Diff line number Diff line change @@ -307,6 +307,25 @@ defmodule Livebook.Utils do
307
307
"data:#{ mime } ;base64,#{ data } "
308
308
end
309
309
310
+ @ doc """
311
+ Expands URL received from the Desktop App for opening in the browser.
312
+ """
313
+ def expand_desktop_url ( "" ) do
314
+ LivebookWeb.Endpoint . access_url ( )
315
+ end
316
+
317
+ def expand_desktop_url ( "/settings" ) do
318
+ to_string ( % { LivebookWeb.Endpoint . access_struct_url ( ) | path: "/settings" } )
319
+ end
320
+
321
+ def expand_desktop_url ( "file://" <> path ) do
322
+ notebook_open_url ( path )
323
+ end
324
+
325
+ def expand_desktop_url ( "livebook://" <> rest ) do
326
+ notebook_import_url ( "https://#{ rest } " )
327
+ end
328
+
310
329
@ doc """
311
330
Opens the given `url` in the browser.
312
331
"""
@@ -323,10 +342,15 @@ defmodule Livebook.Utils do
323
342
324
343
{ :unix , _ } ->
325
344
cond do
326
- System . find_executable ( "xdg-open" ) -> { "xdg-open" , [ url ] }
345
+ System . find_executable ( "xdg-open" ) ->
346
+ { "xdg-open" , [ url ] }
347
+
327
348
# When inside WSL
328
- System . find_executable ( "cmd.exe" ) -> { "cmd.exe" , win_cmd_args }
329
- true -> nil
349
+ System . find_executable ( "cmd.exe" ) ->
350
+ { "cmd.exe" , win_cmd_args }
351
+
352
+ true ->
353
+ nil
330
354
end
331
355
end
332
356
Original file line number Diff line number Diff line change @@ -18,7 +18,10 @@ if Mix.target() == :app do
18
18
19
19
@ impl true
20
20
def handle_info ( { :event , "open" , url } , state ) do
21
- open ( url )
21
+ url
22
+ |> Livebook.Utils . expand_desktop_url ( )
23
+ |> Livebook.Utils . browser_open ( )
24
+
22
25
{ :noreply , state }
23
26
end
24
27
@@ -27,31 +30,5 @@ if Mix.target() == :app do
27
30
Livebook.Config . shutdown ( )
28
31
{ :noreply , state }
29
32
end
30
-
31
- defp open ( "" ) do
32
- open ( LivebookWeb.Endpoint . access_url ( ) )
33
- end
34
-
35
- defp open ( "file://" <> path ) do
36
- path
37
- |> Livebook.Utils . notebook_open_url ( )
38
- |> open ( )
39
- end
40
-
41
- defp open ( "livebook://" <> rest ) do
42
- "https://#{ rest } "
43
- |> Livebook.Utils . notebook_import_url ( )
44
- |> open ( )
45
- end
46
-
47
- defp open ( "/settings" ) do
48
- % { LivebookWeb.Endpoint . access_struct_url ( ) | path: "/settings" }
49
- |> to_string ( )
50
- |> open ( )
51
- end
52
-
53
- defp open ( url ) do
54
- Livebook.Utils . browser_open ( url )
55
- end
56
33
end
57
34
end
You can’t perform that action at this time.
0 commit comments