1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 02:27:43 +00:00

Applets/ResourceGraph: Propagate errors in create_applet

We now return an error if we fail to parse the applet spec in the
expected format. We can now also use try_set_main_widget instead of
set_main_widget.
This commit is contained in:
creator1creeper1 2022-01-06 20:32:04 +01:00 committed by Brian Gianforcaro
parent 0d328f3c86
commit b4eed25872

View file

@ -211,13 +211,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
NonnullRefPtrVector<GUI::Window> applet_windows; NonnullRefPtrVector<GUI::Window> applet_windows;
auto create_applet = [&](GraphType graph_type, StringView spec) { auto create_applet = [&](GraphType graph_type, StringView spec) -> ErrorOr<void> {
auto parts = spec.split_view(','); auto parts = spec.split_view(',');
dbgln("Create applet: {} with spec '{}'", (int)graph_type, spec); dbgln("Create applet: {} with spec '{}'", (int)graph_type, spec);
if (parts.size() != 2) if (parts.size() != 2)
return; return Error::from_string_literal("ResourceGraph: Applet spec is not composed of exactly 2 comma-separated parts"sv);
auto name = parts[0]; auto name = parts[0];
auto graph_color = Gfx::Color::from_string(parts[1]); auto graph_color = Gfx::Color::from_string(parts[1]);
@ -227,15 +227,17 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
window->set_window_type(GUI::WindowType::Applet); window->set_window_type(GUI::WindowType::Applet);
window->resize(GraphWidget::history_size + 2, 15); window->resize(GraphWidget::history_size + 2, 15);
window->set_main_widget<GraphWidget>(graph_type, graph_color, Optional<Gfx::Color> {}); auto graph_widget = TRY(window->try_set_main_widget<GraphWidget>(graph_type, graph_color, Optional<Gfx::Color> {}));
window->show(); window->show();
applet_windows.append(move(window)); applet_windows.append(move(window));
return {};
}; };
if (cpu) if (cpu)
create_applet(GraphType::CPU, cpu); TRY(create_applet(GraphType::CPU, cpu));
if (memory) if (memory)
create_applet(GraphType::Memory, memory); TRY(create_applet(GraphType::Memory, memory));
TRY(Core::System::unveil("/res", "r")); TRY(Core::System::unveil("/res", "r"));
TRY(Core::System::unveil("/proc/stat", "r")); TRY(Core::System::unveil("/proc/stat", "r"));