Support config of the root path for storing notebooks (#191)

This adds a `:root_path` key to the application environment so that
file dialogs can default to known location where notebooks are stored.
This commit is contained in:
Frank Hunleth 2021-04-15 08:51:27 -04:00 committed by GitHub
parent a9c8e20775
commit 3a19021983
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 2 deletions

View file

@ -12,4 +12,12 @@ defmodule Livebook.Config do
{:longnames, _name} -> false
end
end
@doc """
Return the root path for persisting notebooks.
"""
@spec root_path() :: binary()
def root_path() do
Application.get_env(:livebook, :root_path, File.cwd!())
end
end

View file

@ -160,7 +160,7 @@ defmodule LivebookWeb.HomeLive do
def handle_info(_message, socket), do: {:noreply, socket}
defp default_path(), do: File.cwd!() <> "/"
defp default_path(), do: Livebook.Config.root_path() <> "/"
defp sort_session_summaries(session_summaries) do
Enum.sort_by(session_summaries, & &1.notebook_name)

View file

@ -89,7 +89,7 @@ defmodule LivebookWeb.SessionLive.PersistenceComponent do
end
defp default_path() do
File.cwd!() |> Path.join("notebook")
Livebook.Config.root_path() |> Path.join("notebook")
end
defp path_savable?(nil, _running_paths), do: true