mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 00:31:14 +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:
parent
0d328f3c86
commit
b4eed25872
Notes:
sideshowbarker
2024-07-17 21:11:54 +09:00
Author: https://github.com/creator1creeper1 Commit: https://github.com/SerenityOS/serenity/commit/b4eed258720 Pull-request: https://github.com/SerenityOS/serenity/pull/11677 Reviewed-by: https://github.com/bgianfo
|
@ -211,13 +211,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
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(',');
|
||||
|
||||
dbgln("Create applet: {} with spec '{}'", (int)graph_type, spec);
|
||||
|
||||
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 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->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();
|
||||
applet_windows.append(move(window));
|
||||
|
||||
return {};
|
||||
};
|
||||
|
||||
if (cpu)
|
||||
create_applet(GraphType::CPU, cpu);
|
||||
TRY(create_applet(GraphType::CPU, cpu));
|
||||
if (memory)
|
||||
create_applet(GraphType::Memory, memory);
|
||||
TRY(create_applet(GraphType::Memory, memory));
|
||||
|
||||
TRY(Core::System::unveil("/res", "r"));
|
||||
TRY(Core::System::unveil("/proc/stat", "r"));
|
||||
|
|
Loading…
Reference in a new issue