summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorne0ndrag0n <ne0ndrag0n@users.noreply.github.com>2022-10-03 20:09:34 -0400
committerLinus Groh <mail@linusgroh.de>2022-10-14 11:23:06 +0200
commit2affe67c7540785e64c54e322b42323c78168f84 (patch)
tree7b5f81d75938cb91453c78d419cc760c07f192ce
parent7fc22896ee0f417a618143c83967019d2eba5761 (diff)
downloadserenity-2affe67c7540785e64c54e322b42323c78168f84.zip
Settings: Support for launching settings apps as root
-rw-r--r--Userland/Applications/Settings/main.cpp32
1 files changed, 24 insertions, 8 deletions
diff --git a/Userland/Applications/Settings/main.cpp b/Userland/Applications/Settings/main.cpp
index 9f3acbac66..7665168375 100644
--- a/Userland/Applications/Settings/main.cpp
+++ b/Userland/Applications/Settings/main.cpp
@@ -21,6 +21,12 @@
#include <stdio.h>
#include <unistd.h>
+// Modeled after PlaylistWidget.
+enum class SettingsAppsModelCustomRole {
+ _DONOTUSE = (int)GUI::ModelRole::Custom,
+ RequiresRoot
+};
+
class SettingsAppsModel final : public GUI::Model {
public:
SettingsAppsModel()
@@ -45,21 +51,26 @@ public:
virtual GUI::Variant data(GUI::ModelIndex const& index, GUI::ModelRole role) const override
{
auto& app = m_apps[index.row()];
- if (role == GUI::ModelRole::Icon) {
+ if (role == GUI::ModelRole::Icon)
return app->icon();
- }
+
if (role == GUI::ModelRole::Display) {
String name;
- if (app->name().ends_with(" Settings"sv)) {
+
+ if (app->name().ends_with(" Settings"sv))
name = app->name().substring(0, app->name().length() - " Settings"sv.length());
- } else {
+ else
name = app->name();
- }
+
return name;
}
- if (role == GUI::ModelRole::Custom) {
+
+ if (role == GUI::ModelRole::Custom)
return app->executable();
- }
+
+ if (role == static_cast<GUI::ModelRole>(SettingsAppsModelCustomRole::RequiresRoot))
+ return app->requires_root();
+
return {};
}
@@ -101,10 +112,15 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
icon_view->on_activation = [&](GUI::ModelIndex const& index) {
auto executable = model->data(index, GUI::ModelRole::Custom).as_string();
+ auto requires_root = model->data(index, static_cast<GUI::ModelRole>(SettingsAppsModelCustomRole::RequiresRoot)).as_bool();
auto launch_origin_rect = icon_view->to_widget_rect(icon_view->content_rect(index)).translated(icon_view->screen_relative_rect().location());
setenv("__libgui_launch_origin_rect", String::formatted("{},{},{},{}", launch_origin_rect.x(), launch_origin_rect.y(), launch_origin_rect.width(), launch_origin_rect.height()).characters(), 1);
- GUI::Process::spawn_or_show_error(window, executable);
+
+ if (requires_root)
+ GUI::Process::spawn_or_show_error(window, "/bin/Escalator"sv, Array { executable });
+ else
+ GUI::Process::spawn_or_show_error(window, executable);
};
auto statusbar = TRY(main_widget->try_add<GUI::Statusbar>());