launcher: completely hide disabled actions

This commit is contained in:
2 * r + 2 * t 2025-06-16 00:42:09 +10:00
parent 68874082b4
commit a44910d397
3 changed files with 16 additions and 37 deletions

View file

@ -4,7 +4,7 @@ JsonObject {
property int maxShown: 8 property int maxShown: 8
property int maxWallpapers: 9 // Warning: even numbers look bad property int maxWallpapers: 9 // Warning: even numbers look bad
property string actionPrefix: ">" property string actionPrefix: ">"
property bool allowDangerousActions: false // Allow actions that can change the system state, like shutdown, reboot and logout property bool enableDangerousActions: false // Allow actions that can cause losing data, like shutdown, reboot and logout
property JsonObject sizes: JsonObject { property JsonObject sizes: JsonObject {
property int itemWidth: 600 property int itemWidth: 600

View file

@ -31,9 +31,7 @@ Item {
MaterialIcon { MaterialIcon {
id: icon id: icon
text: root.modelData?.disabled text: root.modelData?.icon ?? ""
? "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
@ -50,18 +48,14 @@ Item {
StyledText { StyledText {
id: name id: name
text: root.modelData?.disabled text: root.modelData?.name ?? ""
? (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?.disabled text: root.modelData?.desc ?? ""
? (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,33 +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 disabled: !Config.launcher.enableDangerousActions
disabledReason: qsTr("Enable dangerous actions in config/LauncherConfig.qml first")
function onClicked(list: AppList): void { function onClicked(list: AppList): void {
root.handleDangerousAction(list, shutdown); list.visibilities.launcher = false;
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 disabled: !Config.launcher.enableDangerousActions
disabledReason: qsTr("Enable dangerous actions in config/LauncherConfig.qml first")
function onClicked(list: AppList): void { function onClicked(list: AppList): void {
root.handleDangerousAction(list, reboot); list.visibilities.launcher = false;
reboot.running = true;
} }
}, },
Action { Action {
name: qsTr("Logout") name: qsTr("Logout")
desc: qsTr("Logout of the current session") desc: qsTr("Log out of the current session")
icon: "exit_to_app" icon: "exit_to_app"
disabled: !LauncherConfig.allowDangerousActions disabled: !Config.launcher.enableDangerousActions
disabledReason: qsTr("Enable dangerous actions in config/LauncherConfig.qml first")
function onClicked(list: AppList): void { function onClicked(list: AppList): void {
root.handleDangerousAction(list, logout); list.visibilities.launcher = false;
logout.running = true;
} }
}, },
Action { Action {
@ -122,7 +122,7 @@ Singleton {
} }
] ]
readonly property list<var> preppedActions: list.map(a => ({ readonly property list<var> preppedActions: list.filter(a => !a.disabled).map(a => ({
name: Fuzzy.prepare(a.name), name: Fuzzy.prepare(a.name),
desc: Fuzzy.prepare(a.desc), desc: Fuzzy.prepare(a.desc),
action: a action: a
@ -140,21 +140,6 @@ Singleton {
list.search.text = `${Config.launcher.actionPrefix}${text} `; list.search.text = `${Config.launcher.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