mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-09-12 07:54:49 +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()
|
:wx.subscribe_events()
|
||||||
state = %{frame: frame}
|
state = %{frame: frame}
|
||||||
|
|
||||||
Livebook.Utils.browser_open(LivebookWeb.Endpoint.access_url())
|
|
||||||
|
|
||||||
{frame, state}
|
{frame, state}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -54,20 +52,33 @@ if Mix.target() == :app do
|
||||||
{:stop, :shutdown, state}
|
{:stop, :shutdown, state}
|
||||||
end
|
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
|
# 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.
|
# 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
|
# [1] https://developer.apple.com/documentation/xcode/allowing-apps-and-websites-to-link-to-your-content
|
||||||
@impl true
|
@impl true
|
||||||
def handle_info({:open_url, url}, state) do
|
def handle_info({:open_url, 'livebook://' ++ rest}, state) do
|
||||||
'livebook://' ++ rest = url
|
"https://#{rest}"
|
||||||
import_livebook("https://#{rest}")
|
|> Livebook.Utils.notebook_import_url()
|
||||||
|
|> Livebook.Utils.browser_open()
|
||||||
|
|
||||||
{:noreply, state}
|
{:noreply, state}
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def handle_info({:open_file, path}, state) do
|
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}
|
{:noreply, state}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -83,12 +94,6 @@ if Mix.target() == :app do
|
||||||
{:noreply, state}
|
{:noreply, state}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp import_livebook(url) do
|
|
||||||
url
|
|
||||||
|> Livebook.Utils.notebook_import_url()
|
|
||||||
|> Livebook.Utils.browser_open()
|
|
||||||
end
|
|
||||||
|
|
||||||
defp fixup_macos_menubar(frame, title) do
|
defp fixup_macos_menubar(frame, title) do
|
||||||
menubar = :wxMenuBar.new()
|
menubar = :wxMenuBar.new()
|
||||||
:wxFrame.setMenuBar(frame, menubar)
|
:wxFrame.setMenuBar(frame, menubar)
|
||||||
|
|
Loading…
Add table
Reference in a new issue