2022-01-18 00:34:38 +08:00
|
|
|
if Mix.target() == :app do
|
2022-07-07 01:27:06 +08:00
|
|
|
defmodule LivebookApp do
|
|
|
|
use GenServer
|
|
|
|
|
|
|
|
def start_link(arg) do
|
2023-01-17 04:09:47 +08:00
|
|
|
GenServer.start_link(__MODULE__, arg, name: __MODULE__)
|
2022-07-07 01:27:06 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
def init(_) do
|
2023-01-18 21:11:40 +08:00
|
|
|
{:ok, pid} = ElixirKit.start()
|
|
|
|
ref = Process.monitor(pid)
|
2023-01-20 00:15:42 +08:00
|
|
|
|
|
|
|
ElixirKit.publish("url", LivebookWeb.Endpoint.access_url())
|
|
|
|
|
2023-01-18 21:11:40 +08:00
|
|
|
{:ok, %{ref: ref}}
|
2022-07-07 01:27:06 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
@impl true
|
2023-01-17 04:09:47 +08:00
|
|
|
def handle_info({:event, "open", url}, state) do
|
2023-06-20 19:13:38 +08:00
|
|
|
url
|
|
|
|
|> Livebook.Utils.expand_desktop_url()
|
|
|
|
|> Livebook.Utils.browser_open()
|
|
|
|
|
2022-07-07 01:27:06 +08:00
|
|
|
{:noreply, state}
|
|
|
|
end
|
|
|
|
|
2023-01-18 21:11:40 +08:00
|
|
|
@impl true
|
|
|
|
def handle_info({:DOWN, ref, :process, _, :shutdown}, state) when ref == state.ref do
|
|
|
|
Livebook.Config.shutdown()
|
|
|
|
{:noreply, state}
|
|
|
|
end
|
2022-07-07 01:27:06 +08:00
|
|
|
end
|
2022-01-18 00:34:38 +08:00
|
|
|
end
|