mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 01:20:25 +00:00
Settings: Support for launching settings apps as root
This commit is contained in:
parent
7fc22896ee
commit
2affe67c75
Notes:
sideshowbarker
2024-07-17 06:09:44 +09:00
Author: https://github.com/ne0ndrag0n Commit: https://github.com/SerenityOS/serenity/commit/2affe67c75 Pull-request: https://github.com/SerenityOS/serenity/pull/15446 Reviewed-by: https://github.com/ADKaster ✅ Reviewed-by: https://github.com/linusg Reviewed-by: https://github.com/timschumi ✅
1 changed files with 24 additions and 8 deletions
|
@ -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,9 +112,14 @@ 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);
|
||||
|
||||
if (requires_root)
|
||||
GUI::Process::spawn_or_show_error(window, "/bin/Escalator"sv, Array { executable });
|
||||
else
|
||||
GUI::Process::spawn_or_show_error(window, executable);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue