mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-28 05:35:52 +03:00
Applications: Improve FSAC error message handling
Fixes apps showing redundant error messages and terminating unnecessarily on failed file requests. It's nicer to drop the user off at the equivalent of a default document on failure if possible. Also fixes TextEditor not showing response errors for missing files in the recently opened list.
This commit is contained in:
parent
fef594708e
commit
444470b238
Notes:
sideshowbarker
2024-07-18 02:47:59 +09:00
Author: https://github.com/thankyouverycool Commit: https://github.com/SerenityOS/serenity/commit/444470b238 Pull-request: https://github.com/SerenityOS/serenity/pull/18910
@ -59,14 +59,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
|
||||
auto default_path = TRY(String::from_deprecated_string(Config::read_string("FontEditor"sv, "Defaults"sv, "Font"sv, {})));
|
||||
auto path_to_load = path.is_empty() ? default_path : path;
|
||||
auto open_or_error = [&]() -> ErrorOr<void> {
|
||||
if (path_to_load.is_empty())
|
||||
return {};
|
||||
auto file = TRY(FileSystemAccessClient::Client::the().request_file_read_only_approved(window, path_to_load));
|
||||
return TRY(font_editor->open_file(path, file.release_stream()));
|
||||
}();
|
||||
if (open_or_error.is_error())
|
||||
font_editor->show_error(open_or_error.release_error(), "Opening"sv, path_to_load);
|
||||
if (!path_to_load.is_empty()) {
|
||||
auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window, path_to_load);
|
||||
if (!response.is_error()) {
|
||||
if (auto result = font_editor->open_file(path, response.value().release_stream()); result.is_error())
|
||||
font_editor->show_error(result.release_error(), "Opening"sv, path_to_load);
|
||||
}
|
||||
}
|
||||
|
||||
return app->exec();
|
||||
}
|
||||
|
@ -55,9 +55,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
if (arguments.argc > 1) {
|
||||
// FIXME: Using `try_request_file_read_only_approved` doesn't work here since the file stored in the editor is only readable.
|
||||
auto response = FileSystemAccessClient::Client::the().request_file(window, arguments.strings[1], Core::File::OpenMode::ReadWrite);
|
||||
if (response.is_error())
|
||||
return 1;
|
||||
hex_editor_widget->open_file(response.value().filename(), response.value().release_stream());
|
||||
if (!response.is_error())
|
||||
hex_editor_widget->open_file(response.value().filename(), response.value().release_stream());
|
||||
}
|
||||
|
||||
return app->exec();
|
||||
|
@ -75,9 +75,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
|
||||
if (!image_file.is_empty()) {
|
||||
auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window, image_file);
|
||||
if (response.is_error())
|
||||
return 1;
|
||||
main_widget->open_image(response.release_value());
|
||||
if (!response.is_error())
|
||||
main_widget->open_image(response.release_value());
|
||||
else
|
||||
TRY(main_widget->create_default_image());
|
||||
} else {
|
||||
TRY(main_widget->create_default_image());
|
||||
}
|
||||
|
@ -76,19 +76,20 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
if (!file_to_edit.is_empty()) {
|
||||
auto filename = TRY(String::from_utf8(file_to_edit));
|
||||
FileArgument parsed_argument(filename);
|
||||
|
||||
FileSystemAccessClient::Client::the().set_silence_errors(FileSystemAccessClient::ErrorFlag::NoEntries);
|
||||
auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window, parsed_argument.filename().to_deprecated_string());
|
||||
|
||||
if (response.is_error()) {
|
||||
if (response.error().code() == ENOENT)
|
||||
text_widget->open_nonexistent_file(parsed_argument.filename().to_deprecated_string());
|
||||
else
|
||||
return 1;
|
||||
} else {
|
||||
TRY(text_widget->read_file(response.value().filename(), response.value().stream()));
|
||||
text_widget->editor().set_cursor_and_focus_line(parsed_argument.line().value_or(1) - 1, parsed_argument.column().value_or(0));
|
||||
}
|
||||
|
||||
text_widget->update_title();
|
||||
FileSystemAccessClient::Client::the().set_silence_errors(FileSystemAccessClient::ErrorFlag::None);
|
||||
}
|
||||
text_widget->update_statusbar();
|
||||
|
||||
|
@ -53,9 +53,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
app->event_loop().deferred_invoke(
|
||||
[&window, &path, &main_widget]() {
|
||||
auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window, path.value().to_deprecated_string());
|
||||
if (response.is_error())
|
||||
GUI::MessageBox::show_error(window, DeprecatedString::formatted("Opening \"{}\" failed: {}", path.value(), response.error()));
|
||||
else {
|
||||
if (!response.is_error()) {
|
||||
auto load_from_file_result = main_widget->load_from_file(response.value().filename(), response.value().release_stream());
|
||||
if (load_from_file_result.is_error())
|
||||
GUI::MessageBox::show_error(window, DeprecatedString::formatted("Loading theme from file has failed: {}", load_from_file_result.error()));
|
||||
|
Loading…
Reference in New Issue
Block a user