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:
parent
d392c38a73
commit
8fbb39803e
Notes:
github-actions[bot]
2024-09-03 18:14:51 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/8fbb39803e3 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1219
2 changed files with 27 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Badge.h>
|
||||
#include <AK/ByteString.h>
|
||||
#include <AK/LexicalPath.h>
|
||||
#include <AK/Optional.h>
|
||||
#include <AK/Swift.h>
|
||||
#include <LibCore/EventLoop.h>
|
||||
#include <LibCore/Forward.h>
|
||||
|
@ -45,6 +48,8 @@ public:
|
|||
void update_process_statistics();
|
||||
String generate_process_statistics_html();
|
||||
|
||||
ErrorOr<LexicalPath> path_for_downloaded_file(StringView file) const;
|
||||
|
||||
protected:
|
||||
template<DerivedFrom<Application> ApplicationType>
|
||||
static NonnullOwnPtr<ApplicationType> create(Main::Arguments& arguments, URL::URL new_tab_page_url)
|
||||
|
@ -62,6 +67,8 @@ protected:
|
|||
virtual void create_platform_arguments(Core::ArgsParser&) { }
|
||||
virtual void create_platform_options(ChromeOptions&, WebContentOptions&) { }
|
||||
|
||||
virtual Optional<ByteString> ask_user_for_download_folder() const { return {}; }
|
||||
|
||||
private:
|
||||
void initialize(Main::Arguments const& arguments, URL::URL new_tab_page_url);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue