LibWebView: Add facilities to ask the user for a download directory

If the Downloads directory exists, we will use it (note that this will
respect the XDG_DOWNLOAD_DIR environment variable).

Otherwise, we will ask the UI layer to retrieve a download directory
from the user. This directory is not saved, so it will be re-prompted
every time. Once a proper settings UI is complete, we will of course
integrate with that for persistent settings.
This commit is contained in:
Timothy Flynn 2024-08-28 15:29:51 -04:00 committed by Tim Flynn
commit 8fbb39803e
Notes: github-actions[bot] 2024-09-03 18:14:51 +00:00
2 changed files with 27 additions and 0 deletions

View file

@ -7,7 +7,9 @@
#include <AK/Debug.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/Environment.h>
#include <LibCore/StandardPaths.h>
#include <LibCore/TimeZoneWatcher.h>
#include <LibFileSystem/FileSystem.h>
#include <LibImageDecoderClient/Client.h>
#include <LibWebView/Application.h>
#include <LibWebView/URL.h>
@ -207,4 +209,22 @@ void Application::process_did_exit(Process&& process)
}
}
ErrorOr<LexicalPath> Application::path_for_downloaded_file(StringView file) const
{
auto downloads_directory = Core::StandardPaths::downloads_directory();
if (!FileSystem::is_directory(downloads_directory)) {
auto maybe_downloads_directory = ask_user_for_download_folder();
if (!maybe_downloads_directory.has_value())
return Error::from_errno(ECANCELED);
downloads_directory = maybe_downloads_directory.release_value();
}
if (!FileSystem::is_directory(downloads_directory))
return Error::from_errno(ENOENT);
return LexicalPath::join(downloads_directory, file);
}
}