mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-01-19 21:38:13 +08:00
Switch importing to opening files in the desktop app (#995)
This commit is contained in:
parent
44659dfb19
commit
1d03f59d2e
1 changed files with 17 additions and 12 deletions
|
@ -37,8 +37,6 @@ if Mix.target() == :app do
|
|||
:wx.subscribe_events()
|
||||
state = %{frame: frame}
|
||||
|
||||
Livebook.Utils.browser_open(LivebookWeb.Endpoint.access_url())
|
||||
|
||||
{frame, state}
|
||||
end
|
||||
|
||||
|
@ -54,20 +52,33 @@ if Mix.target() == :app do
|
|||
{:stop, :shutdown, state}
|
||||
end
|
||||
|
||||
# This event is triggered when the application is opened for the first time
|
||||
@impl true
|
||||
def handle_info({:new_file, ''}, state) do
|
||||
Livebook.Utils.browser_open(LivebookWeb.Endpoint.access_url())
|
||||
{:noreply, state}
|
||||
end
|
||||
|
||||
# TODO: investigate "Universal Links" [1], that is, instead of livebook://foo, we have
|
||||
# https://livebook.dev/foo, which means the link works with and without Livebook.app.
|
||||
#
|
||||
# [1] https://developer.apple.com/documentation/xcode/allowing-apps-and-websites-to-link-to-your-content
|
||||
@impl true
|
||||
def handle_info({:open_url, url}, state) do
|
||||
'livebook://' ++ rest = url
|
||||
import_livebook("https://#{rest}")
|
||||
def handle_info({:open_url, 'livebook://' ++ rest}, state) do
|
||||
"https://#{rest}"
|
||||
|> Livebook.Utils.notebook_import_url()
|
||||
|> Livebook.Utils.browser_open()
|
||||
|
||||
{:noreply, state}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_info({:open_file, path}, state) do
|
||||
import_livebook("file://#{path}")
|
||||
path
|
||||
|> List.to_string()
|
||||
|> Livebook.Utils.notebook_open_url()
|
||||
|> Livebook.Utils.browser_open()
|
||||
|
||||
{:noreply, state}
|
||||
end
|
||||
|
||||
|
@ -83,12 +94,6 @@ if Mix.target() == :app do
|
|||
{:noreply, state}
|
||||
end
|
||||
|
||||
defp import_livebook(url) do
|
||||
url
|
||||
|> Livebook.Utils.notebook_import_url()
|
||||
|> Livebook.Utils.browser_open()
|
||||
end
|
||||
|
||||
defp fixup_macos_menubar(frame, title) do
|
||||
menubar = :wxMenuBar.new()
|
||||
:wxFrame.setMenuBar(frame, menubar)
|
||||
|
|
Loading…
Reference in a new issue