launcher: add opt-in for dangerous actions
This commit is contained in:
parent
5fb727a4c8
commit
0bcee304e5
3 changed files with 39 additions and 12 deletions
|
|
@ -8,6 +8,7 @@ Singleton {
|
|||
readonly property int maxWallpapers: 9 // Warning: even numbers look bad
|
||||
readonly property string actionPrefix: ">"
|
||||
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 {
|
||||
readonly property int itemWidth: 600
|
||||
|
|
|
|||
|
|
@ -31,7 +31,9 @@ Item {
|
|||
MaterialIcon {
|
||||
id: icon
|
||||
|
||||
text: root.modelData?.icon ?? ""
|
||||
text: root.modelData?.disabled
|
||||
? "disabled_by_default"
|
||||
: (root.modelData?.icon ?? "")
|
||||
font.pointSize: Appearance.font.size.extraLarge
|
||||
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
|
|
@ -48,14 +50,18 @@ Item {
|
|||
StyledText {
|
||||
id: name
|
||||
|
||||
text: root.modelData?.name ?? ""
|
||||
text: root.modelData?.disabled
|
||||
? (root.modelData?.name ?? "") + " - Disabled"
|
||||
: (root.modelData?.name ?? "")
|
||||
font.pointSize: Appearance.font.size.normal
|
||||
}
|
||||
|
||||
StyledText {
|
||||
id: desc
|
||||
|
||||
text: root.modelData?.desc ?? ""
|
||||
text: root.modelData?.disabled
|
||||
? (root.modelData?.disabledReason ?? "")
|
||||
: (root.modelData?.desc ?? "")
|
||||
font.pointSize: Appearance.font.size.small
|
||||
color: Colours.alpha(Colours.palette.m3outline, true)
|
||||
|
||||
|
|
|
|||
|
|
@ -71,30 +71,33 @@ Singleton {
|
|||
name: qsTr("Shutdown")
|
||||
desc: qsTr("Shutdown the system")
|
||||
icon: "power_settings_new"
|
||||
disabled: !LauncherConfig.allowDangerousActions
|
||||
disabledReason: qsTr("Enable dangerous actions in config/LauncherConfig.qml first")
|
||||
|
||||
function onClicked(list: AppList): void {
|
||||
list.visibilities.launcher = false;
|
||||
shutdown.running = true;
|
||||
root.handleDangerousAction(list, shutdown);
|
||||
}
|
||||
},
|
||||
Action {
|
||||
name: qsTr("Reboot")
|
||||
desc: qsTr("Reboot the system")
|
||||
icon: "cached"
|
||||
disabled: !LauncherConfig.allowDangerousActions
|
||||
disabledReason: qsTr("Enable dangerous actions in config/LauncherConfig.qml first")
|
||||
|
||||
function onClicked(list: AppList): void {
|
||||
list.visibilities.launcher = false;
|
||||
reboot.running = true;
|
||||
root.handleDangerousAction(list, reboot);
|
||||
}
|
||||
},
|
||||
Action {
|
||||
name: qsTr("Logout")
|
||||
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 {
|
||||
list.visibilities.launcher = false;
|
||||
logout.running = true;
|
||||
root.handleDangerousAction(list, logout);
|
||||
}
|
||||
},
|
||||
Action {
|
||||
|
|
@ -137,6 +140,21 @@ Singleton {
|
|||
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 {
|
||||
id: shutdown
|
||||
|
||||
|
|
@ -152,8 +170,8 @@ Singleton {
|
|||
Process {
|
||||
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 {
|
||||
id: lock
|
||||
|
|
@ -171,6 +189,8 @@ Singleton {
|
|||
required property string name
|
||||
required property string desc
|
||||
required property string icon
|
||||
property bool disabled
|
||||
property string disabledReason
|
||||
|
||||
function onClicked(list: AppList): void {
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue