launcher: add opt-in for dangerous actions

This commit is contained in:
Tim Hämisch 2025-06-13 18:04:45 +02:00
parent 5fb727a4c8
commit 0bcee304e5
3 changed files with 39 additions and 12 deletions

View file

@ -8,6 +8,7 @@ Singleton {
readonly property int maxWallpapers: 9 // Warning: even numbers look bad readonly property int maxWallpapers: 9 // Warning: even numbers look bad
readonly property string actionPrefix: ">" readonly property string actionPrefix: ">"
readonly property Sizes sizes: Sizes {} readonly property Sizes sizes: Sizes {}
readonly property bool allowDangerousActions: false // Allow actions that can change the system state, like shutdown, reboot and logout
component Sizes: QtObject { component Sizes: QtObject {
readonly property int itemWidth: 600 readonly property int itemWidth: 600

View file

@ -31,7 +31,9 @@ Item {
MaterialIcon { MaterialIcon {
id: icon id: icon
text: root.modelData?.icon ?? "" text: root.modelData?.disabled
? "disabled_by_default"
: (root.modelData?.icon ?? "")
font.pointSize: Appearance.font.size.extraLarge font.pointSize: Appearance.font.size.extraLarge
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
@ -48,14 +50,18 @@ Item {
StyledText { StyledText {
id: name id: name
text: root.modelData?.name ?? "" text: root.modelData?.disabled
? (root.modelData?.name ?? "") + " - Disabled"
: (root.modelData?.name ?? "")
font.pointSize: Appearance.font.size.normal font.pointSize: Appearance.font.size.normal
} }
StyledText { StyledText {
id: desc id: desc
text: root.modelData?.desc ?? "" text: root.modelData?.disabled
? (root.modelData?.disabledReason ?? "")
: (root.modelData?.desc ?? "")
font.pointSize: Appearance.font.size.small font.pointSize: Appearance.font.size.small
color: Colours.alpha(Colours.palette.m3outline, true) color: Colours.alpha(Colours.palette.m3outline, true)

View file

@ -71,30 +71,33 @@ Singleton {
name: qsTr("Shutdown") name: qsTr("Shutdown")
desc: qsTr("Shutdown the system") desc: qsTr("Shutdown the system")
icon: "power_settings_new" icon: "power_settings_new"
disabled: !LauncherConfig.allowDangerousActions
disabledReason: qsTr("Enable dangerous actions in config/LauncherConfig.qml first")
function onClicked(list: AppList): void { function onClicked(list: AppList): void {
list.visibilities.launcher = false; root.handleDangerousAction(list, shutdown);
shutdown.running = true;
} }
}, },
Action { Action {
name: qsTr("Reboot") name: qsTr("Reboot")
desc: qsTr("Reboot the system") desc: qsTr("Reboot the system")
icon: "cached" icon: "cached"
disabled: !LauncherConfig.allowDangerousActions
disabledReason: qsTr("Enable dangerous actions in config/LauncherConfig.qml first")
function onClicked(list: AppList): void { function onClicked(list: AppList): void {
list.visibilities.launcher = false; root.handleDangerousAction(list, reboot);
reboot.running = true;
} }
}, },
Action { Action {
name: qsTr("Logout") name: qsTr("Logout")
desc: qsTr("Logout of the current session") desc: qsTr("Logout of the current session")
icon: "logout" icon: "exit_to_app"
disabled: !LauncherConfig.allowDangerousActions
disabledReason: qsTr("Enable dangerous actions in config/LauncherConfig.qml first")
function onClicked(list: AppList): void { function onClicked(list: AppList): void {
list.visibilities.launcher = false; root.handleDangerousAction(list, logout);
logout.running = true;
} }
}, },
Action { Action {
@ -137,6 +140,21 @@ Singleton {
list.search.text = `${LauncherConfig.actionPrefix}${text} `; list.search.text = `${LauncherConfig.actionPrefix}${text} `;
} }
function handleDangerousAction(list: AppList, process: QtObject): void {
list.visibilities.launcher = false;
if (!LauncherConfig.allowDangerousActions) {
dangerousActions.running = true;
return;
}
process.running = true;
}
Process {
id: dangerousActions
command: ["notify-send", "Quickshell", qsTr("Enable dangerous actions in config/LauncherConfig.qml to use this action."), "-i", "dialog-warning"]
}
Process { Process {
id: shutdown id: shutdown
@ -152,7 +170,7 @@ Singleton {
Process { Process {
id: logout id: logout
command: ["sh", "-c", "(uwsm stop | grep -q 'Compositor is not running' && loginctl terminate-user $USER) || uwsm stop"] command: ["hyprctl", "dispatch", "exit", "1"]
} }
Process { Process {
@ -171,6 +189,8 @@ Singleton {
required property string name required property string name
required property string desc required property string desc
required property string icon required property string icon
property bool disabled
property string disabledReason
function onClicked(list: AppList): void { function onClicked(list: AppList): void {
} }