mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-08-05 21:18:30 -04:00
powermenu: support user-defined custom power buttons (#2916)
This commit is contained in:
@@ -973,6 +973,7 @@ Singleton {
|
||||
property string customPowerActionHibernate: ""
|
||||
property string customPowerActionReboot: ""
|
||||
property string customPowerActionPowerOff: ""
|
||||
property var customPowerButtons: []
|
||||
|
||||
property bool updaterHideWidget: false
|
||||
property bool updaterCheckOnStart: false
|
||||
|
||||
@@ -526,6 +526,7 @@ var SPEC = {
|
||||
customPowerActionHibernate: { def: "" },
|
||||
customPowerActionReboot: { def: "" },
|
||||
customPowerActionPowerOff: { def: "" },
|
||||
customPowerButtons: { def: [] },
|
||||
|
||||
updaterHideWidget: { def: false },
|
||||
updaterCheckOnStart: { def: false },
|
||||
|
||||
@@ -129,6 +129,13 @@ DankModal {
|
||||
switchUserRequested();
|
||||
return;
|
||||
}
|
||||
if (action.startsWith("custom:")) {
|
||||
const button = (SettingsData.customPowerButtons || [])[parseInt(action.slice(7), 10)];
|
||||
close();
|
||||
if (button?.command)
|
||||
Quickshell.execDetached(["sh", "-c", button.command]);
|
||||
return;
|
||||
}
|
||||
close();
|
||||
root.powerActionRequested(action, "", "");
|
||||
}
|
||||
@@ -172,13 +179,14 @@ DankModal {
|
||||
|
||||
function updateVisibleActions() {
|
||||
const allActions = SettingsData.powerMenuActions || ["reboot", "logout", "poweroff", "lock", "suspend", "restart"];
|
||||
const customButtons = SettingsData.customPowerButtons || [];
|
||||
visibleActions = allActions.filter(action => {
|
||||
if (action === "hibernate" && !SessionService.hibernateSupported)
|
||||
return false;
|
||||
if (action === "softreboot" && !SessionService.softRebootSupported)
|
||||
return false;
|
||||
return true;
|
||||
});
|
||||
}).concat(customButtons.map((button, i) => "custom:" + i));
|
||||
|
||||
if (!SettingsData.powerMenuGridLayout)
|
||||
return;
|
||||
@@ -218,6 +226,14 @@ DankModal {
|
||||
}
|
||||
|
||||
function getActionData(action) {
|
||||
if (action.startsWith("custom:")) {
|
||||
const button = (SettingsData.customPowerButtons || [])[parseInt(action.slice(7), 10)];
|
||||
return {
|
||||
"icon": button?.icon || "terminal",
|
||||
"label": button?.label || button?.command || "",
|
||||
"key": ""
|
||||
};
|
||||
}
|
||||
switch (action) {
|
||||
case "reboot":
|
||||
return {
|
||||
@@ -688,6 +704,7 @@ DankModal {
|
||||
height: 16
|
||||
radius: 4
|
||||
color: Theme.onSurface_12
|
||||
visible: gridButtonRect.actionData.key !== ""
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
|
||||
StyledText {
|
||||
@@ -820,6 +837,7 @@ DankModal {
|
||||
height: 20
|
||||
radius: 4
|
||||
color: Theme.onSurface_12
|
||||
visible: listButtonRect.actionData.key !== ""
|
||||
anchors {
|
||||
right: parent.right
|
||||
rightMargin: Theme.spacingM
|
||||
|
||||
Reference in New Issue
Block a user