mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-08-06 13:38:28 -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 customPowerActionHibernate: ""
|
||||||
property string customPowerActionReboot: ""
|
property string customPowerActionReboot: ""
|
||||||
property string customPowerActionPowerOff: ""
|
property string customPowerActionPowerOff: ""
|
||||||
|
property var customPowerButtons: []
|
||||||
|
|
||||||
property bool updaterHideWidget: false
|
property bool updaterHideWidget: false
|
||||||
property bool updaterCheckOnStart: false
|
property bool updaterCheckOnStart: false
|
||||||
|
|||||||
@@ -526,6 +526,7 @@ var SPEC = {
|
|||||||
customPowerActionHibernate: { def: "" },
|
customPowerActionHibernate: { def: "" },
|
||||||
customPowerActionReboot: { def: "" },
|
customPowerActionReboot: { def: "" },
|
||||||
customPowerActionPowerOff: { def: "" },
|
customPowerActionPowerOff: { def: "" },
|
||||||
|
customPowerButtons: { def: [] },
|
||||||
|
|
||||||
updaterHideWidget: { def: false },
|
updaterHideWidget: { def: false },
|
||||||
updaterCheckOnStart: { def: false },
|
updaterCheckOnStart: { def: false },
|
||||||
|
|||||||
@@ -129,6 +129,13 @@ DankModal {
|
|||||||
switchUserRequested();
|
switchUserRequested();
|
||||||
return;
|
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();
|
close();
|
||||||
root.powerActionRequested(action, "", "");
|
root.powerActionRequested(action, "", "");
|
||||||
}
|
}
|
||||||
@@ -172,13 +179,14 @@ DankModal {
|
|||||||
|
|
||||||
function updateVisibleActions() {
|
function updateVisibleActions() {
|
||||||
const allActions = SettingsData.powerMenuActions || ["reboot", "logout", "poweroff", "lock", "suspend", "restart"];
|
const allActions = SettingsData.powerMenuActions || ["reboot", "logout", "poweroff", "lock", "suspend", "restart"];
|
||||||
|
const customButtons = SettingsData.customPowerButtons || [];
|
||||||
visibleActions = allActions.filter(action => {
|
visibleActions = allActions.filter(action => {
|
||||||
if (action === "hibernate" && !SessionService.hibernateSupported)
|
if (action === "hibernate" && !SessionService.hibernateSupported)
|
||||||
return false;
|
return false;
|
||||||
if (action === "softreboot" && !SessionService.softRebootSupported)
|
if (action === "softreboot" && !SessionService.softRebootSupported)
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
});
|
}).concat(customButtons.map((button, i) => "custom:" + i));
|
||||||
|
|
||||||
if (!SettingsData.powerMenuGridLayout)
|
if (!SettingsData.powerMenuGridLayout)
|
||||||
return;
|
return;
|
||||||
@@ -218,6 +226,14 @@ DankModal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getActionData(action) {
|
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) {
|
switch (action) {
|
||||||
case "reboot":
|
case "reboot":
|
||||||
return {
|
return {
|
||||||
@@ -688,6 +704,7 @@ DankModal {
|
|||||||
height: 16
|
height: 16
|
||||||
radius: 4
|
radius: 4
|
||||||
color: Theme.onSurface_12
|
color: Theme.onSurface_12
|
||||||
|
visible: gridButtonRect.actionData.key !== ""
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
|
||||||
StyledText {
|
StyledText {
|
||||||
@@ -820,6 +837,7 @@ DankModal {
|
|||||||
height: 20
|
height: 20
|
||||||
radius: 4
|
radius: 4
|
||||||
color: Theme.onSurface_12
|
color: Theme.onSurface_12
|
||||||
|
visible: listButtonRect.actionData.key !== ""
|
||||||
anchors {
|
anchors {
|
||||||
right: parent.right
|
right: parent.right
|
||||||
rightMargin: Theme.spacingM
|
rightMargin: Theme.spacingM
|
||||||
|
|||||||
Reference in New Issue
Block a user