mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-29 14:14:45 +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 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 path_to_load = path.is_empty() ? default_path : path;
|
||||||
auto open_or_error = [&]() -> ErrorOr<void> {
|
if (!path_to_load.is_empty()) {
|
||||||
if (path_to_load.is_empty())
|
auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window, path_to_load);
|
||||||
return {};
|
if (!response.is_error()) {
|
||||||
auto file = TRY(FileSystemAccessClient::Client::the().request_file_read_only_approved(window, path_to_load));
|
if (auto result = font_editor->open_file(path, response.value().release_stream()); result.is_error())
|
||||||
return TRY(font_editor->open_file(path, file.release_stream()));
|
font_editor->show_error(result.release_error(), "Opening"sv, path_to_load);
|
||||||
}();
|
}
|
||||||
if (open_or_error.is_error())
|
}
|
||||||
font_editor->show_error(open_or_error.release_error(), "Opening"sv, path_to_load);
|
|
||||||
|
|
||||||
return app->exec();
|
return app->exec();
|
||||||
}
|
}
|
||||||
|
@ -55,8 +55,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||||||
if (arguments.argc > 1) {
|
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.
|
// 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);
|
auto response = FileSystemAccessClient::Client::the().request_file(window, arguments.strings[1], Core::File::OpenMode::ReadWrite);
|
||||||
if (response.is_error())
|
if (!response.is_error())
|
||||||
return 1;
|
|
||||||
hex_editor_widget->open_file(response.value().filename(), response.value().release_stream());
|
hex_editor_widget->open_file(response.value().filename(), response.value().release_stream());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,9 +75,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||||||
|
|
||||||
if (!image_file.is_empty()) {
|
if (!image_file.is_empty()) {
|
||||||
auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window, image_file);
|
auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window, image_file);
|
||||||
if (response.is_error())
|
if (!response.is_error())
|
||||||
return 1;
|
|
||||||
main_widget->open_image(response.release_value());
|
main_widget->open_image(response.release_value());
|
||||||
|
else
|
||||||
|
TRY(main_widget->create_default_image());
|
||||||
} else {
|
} else {
|
||||||
TRY(main_widget->create_default_image());
|
TRY(main_widget->create_default_image());
|
||||||
}
|
}
|
||||||
|
@ -76,19 +76,20 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||||||
if (!file_to_edit.is_empty()) {
|
if (!file_to_edit.is_empty()) {
|
||||||
auto filename = TRY(String::from_utf8(file_to_edit));
|
auto filename = TRY(String::from_utf8(file_to_edit));
|
||||||
FileArgument parsed_argument(filename);
|
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());
|
auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window, parsed_argument.filename().to_deprecated_string());
|
||||||
|
|
||||||
if (response.is_error()) {
|
if (response.is_error()) {
|
||||||
if (response.error().code() == ENOENT)
|
if (response.error().code() == ENOENT)
|
||||||
text_widget->open_nonexistent_file(parsed_argument.filename().to_deprecated_string());
|
text_widget->open_nonexistent_file(parsed_argument.filename().to_deprecated_string());
|
||||||
else
|
|
||||||
return 1;
|
|
||||||
} else {
|
} else {
|
||||||
TRY(text_widget->read_file(response.value().filename(), response.value().stream()));
|
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->editor().set_cursor_and_focus_line(parsed_argument.line().value_or(1) - 1, parsed_argument.column().value_or(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
text_widget->update_title();
|
text_widget->update_title();
|
||||||
|
FileSystemAccessClient::Client::the().set_silence_errors(FileSystemAccessClient::ErrorFlag::None);
|
||||||
}
|
}
|
||||||
text_widget->update_statusbar();
|
text_widget->update_statusbar();
|
||||||
|
|
||||||
|
@ -53,9 +53,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||||||
app->event_loop().deferred_invoke(
|
app->event_loop().deferred_invoke(
|
||||||
[&window, &path, &main_widget]() {
|
[&window, &path, &main_widget]() {
|
||||||
auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window, path.value().to_deprecated_string());
|
auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window, path.value().to_deprecated_string());
|
||||||
if (response.is_error())
|
if (!response.is_error()) {
|
||||||
GUI::MessageBox::show_error(window, DeprecatedString::formatted("Opening \"{}\" failed: {}", path.value(), response.error()));
|
|
||||||
else {
|
|
||||||
auto load_from_file_result = main_widget->load_from_file(response.value().filename(), response.value().release_stream());
|
auto load_from_file_result = main_widget->load_from_file(response.value().filename(), response.value().release_stream());
|
||||||
if (load_from_file_result.is_error())
|
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()));
|
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