mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:17:34 +00:00
Settings: Support for launching settings apps as root
This commit is contained in:
parent
7fc22896ee
commit
2affe67c75
1 changed files with 24 additions and 8 deletions
|
@ -21,6 +21,12 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
// Modeled after PlaylistWidget.
|
||||||
|
enum class SettingsAppsModelCustomRole {
|
||||||
|
_DONOTUSE = (int)GUI::ModelRole::Custom,
|
||||||
|
RequiresRoot
|
||||||
|
};
|
||||||
|
|
||||||
class SettingsAppsModel final : public GUI::Model {
|
class SettingsAppsModel final : public GUI::Model {
|
||||||
public:
|
public:
|
||||||
SettingsAppsModel()
|
SettingsAppsModel()
|
||||||
|
@ -45,21 +51,26 @@ public:
|
||||||
virtual GUI::Variant data(GUI::ModelIndex const& index, GUI::ModelRole role) const override
|
virtual GUI::Variant data(GUI::ModelIndex const& index, GUI::ModelRole role) const override
|
||||||
{
|
{
|
||||||
auto& app = m_apps[index.row()];
|
auto& app = m_apps[index.row()];
|
||||||
if (role == GUI::ModelRole::Icon) {
|
if (role == GUI::ModelRole::Icon)
|
||||||
return app->icon();
|
return app->icon();
|
||||||
}
|
|
||||||
if (role == GUI::ModelRole::Display) {
|
if (role == GUI::ModelRole::Display) {
|
||||||
String name;
|
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());
|
name = app->name().substring(0, app->name().length() - " Settings"sv.length());
|
||||||
} else {
|
else
|
||||||
name = app->name();
|
name = app->name();
|
||||||
}
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
if (role == GUI::ModelRole::Custom) {
|
|
||||||
|
if (role == GUI::ModelRole::Custom)
|
||||||
return app->executable();
|
return app->executable();
|
||||||
}
|
|
||||||
|
if (role == static_cast<GUI::ModelRole>(SettingsAppsModelCustomRole::RequiresRoot))
|
||||||
|
return app->requires_root();
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,9 +112,14 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
|
|
||||||
icon_view->on_activation = [&](GUI::ModelIndex const& index) {
|
icon_view->on_activation = [&](GUI::ModelIndex const& index) {
|
||||||
auto executable = model->data(index, GUI::ModelRole::Custom).as_string();
|
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());
|
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);
|
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);
|
||||||
|
|
||||||
|
if (requires_root)
|
||||||
|
GUI::Process::spawn_or_show_error(window, "/bin/Escalator"sv, Array { executable });
|
||||||
|
else
|
||||||
GUI::Process::spawn_or_show_error(window, executable);
|
GUI::Process::spawn_or_show_error(window, executable);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue