mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:47:44 +00:00
Applets/ClipboardHistory: Add persistent storage
Clipboard entries are now preserved upon reboot :^). Unfortunately, it only supports data with the mimetype "text/". This is done by writing all entries as a JSON object in a file located in ~/.data. Co-authored-by: Sagittarius-a <sagittarius-a@users.noreply.github.com>
This commit is contained in:
parent
c09d0c4816
commit
07c6cebbab
5 changed files with 143 additions and 7 deletions
|
@ -6,6 +6,8 @@
|
|||
|
||||
#include "ClipboardHistoryModel.h"
|
||||
#include <LibConfig/Client.h>
|
||||
#include <LibCore/Directory.h>
|
||||
#include <LibCore/StandardPaths.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibGUI/Action.h>
|
||||
#include <LibGUI/Application.h>
|
||||
|
@ -17,14 +19,22 @@
|
|||
|
||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
{
|
||||
TRY(Core::System::pledge("stdio recvfd sendfd rpath unix"));
|
||||
TRY(Core::System::pledge("stdio recvfd sendfd rpath unix cpath wpath"));
|
||||
auto app = TRY(GUI::Application::create(arguments));
|
||||
auto clipboard_config = TRY(Core::ConfigFile::open_for_app("ClipboardHistory"));
|
||||
|
||||
auto const default_path = DeprecatedString::formatted("{}/{}", Core::StandardPaths::data_directory(), "Clipboard/ClipboardHistory.json"sv);
|
||||
auto const clipboard_file_path = clipboard_config->read_entry("Clipboard", "ClipboardFilePath", default_path);
|
||||
auto const parent_path = LexicalPath(clipboard_file_path);
|
||||
TRY(Core::Directory::create(parent_path.dirname(), Core::Directory::CreateDirectories::Yes));
|
||||
|
||||
Config::pledge_domain("ClipboardHistory");
|
||||
Config::monitor_domain("ClipboardHistory");
|
||||
|
||||
TRY(Core::System::pledge("stdio recvfd sendfd rpath"));
|
||||
TRY(Core::System::pledge("stdio recvfd sendfd rpath cpath wpath"));
|
||||
TRY(Core::System::unveil("/res", "r"));
|
||||
TRY(Core::System::unveil(parent_path.dirname(), "rwc"sv));
|
||||
|
||||
TRY(Core::System::unveil(nullptr, nullptr));
|
||||
auto app_icon = TRY(GUI::Icon::try_create_default_icon("edit-copy"sv));
|
||||
|
||||
|
@ -36,6 +46,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto table_view = TRY(main_window->set_main_widget<GUI::TableView>());
|
||||
auto model = ClipboardHistoryModel::create();
|
||||
|
||||
TRY(model->read_from_file(clipboard_file_path));
|
||||
|
||||
auto data_and_type = GUI::Clipboard::the().fetch_data_and_type();
|
||||
if (!(data_and_type.data.is_empty() && data_and_type.mime_type.is_empty() && data_and_type.metadata.is_empty()))
|
||||
model->add_item(data_and_type);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue