From 3a1902198370ff0d19a5cb97805eec2a6743f1a6 Mon Sep 17 00:00:00 2001 From: Frank Hunleth Date: Thu, 15 Apr 2021 08:51:27 -0400 Subject: [PATCH] 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. --- lib/livebook/config.ex | 8 ++++++++ lib/livebook_web/live/home_live.ex | 2 +- .../live/session_live/persistence_component.ex | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/livebook/config.ex b/lib/livebook/config.ex index a110caff9..8fa76ae0c 100644 --- a/lib/livebook/config.ex +++ b/lib/livebook/config.ex @@ -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 diff --git a/lib/livebook_web/live/home_live.ex b/lib/livebook_web/live/home_live.ex index 305543ac0..354b11dea 100644 --- a/lib/livebook_web/live/home_live.ex +++ b/lib/livebook_web/live/home_live.ex @@ -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) diff --git a/lib/livebook_web/live/session_live/persistence_component.ex b/lib/livebook_web/live/session_live/persistence_component.ex index c534cb51d..20dcfc4bc 100644 --- a/lib/livebook_web/live/session_live/persistence_component.ex +++ b/lib/livebook_web/live/session_live/persistence_component.ex @@ -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