1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-25 05:52:50 -05:00

powermenu: make customizable + add dms restart

This commit is contained in:
bbedward
2025-11-12 15:29:39 -05:00
parent 494d90be22
commit b17c14a07b
13 changed files with 858 additions and 470 deletions

View File

@@ -12,9 +12,12 @@ DankModal {
property int selectedRow: 0
property int selectedCol: 0
property int selectedIndex: selectedRow * 3 + selectedCol
property int selectedIndex: selectedRow * gridColumns + selectedCol
property rect parentBounds: Qt.rect(0, 0, 0, 0)
property var parentScreen: null
property var visibleActions: []
property int gridColumns: 3
property int gridRows: 2
signal powerActionRequested(string action, string title, string message)
signal lockRequested
@@ -33,9 +36,100 @@ DankModal {
open()
}
function updateVisibleActions() {
const allActions = SettingsData.powerMenuActions || ["reboot", "logout", "poweroff", "lock", "suspend", "restart"]
visibleActions = allActions.filter(action => {
if (action === "hibernate" && !SessionService.hibernateSupported)
return false
return true
})
const count = visibleActions.length
switch (count) {
case 0:
gridColumns = 1
gridRows = 1
break
case 1:
case 2:
case 3:
gridColumns = 1
gridRows = count
break
case 4:
gridColumns = 2
gridRows = 2
break
default:
gridColumns = 3
gridRows = Math.ceil(count / 3)
break
}
}
function getDefaultActionIndex() {
const defaultAction = SettingsData.powerMenuDefaultAction || "logout"
const index = visibleActions.indexOf(defaultAction)
return index >= 0 ? index : 0
}
function getActionAtIndex(index) {
const actions = ["reboot", "logout", "poweroff", "lock", "suspend", SessionService.hibernateSupported ? "hibernate" : "restart"]
return actions[index]
if (index < 0 || index >= visibleActions.length)
return ""
return visibleActions[index]
}
function getActionData(action) {
switch (action) {
case "reboot":
return {
"icon": "restart_alt",
"label": I18n.tr("Reboot"),
"key": "R"
}
case "logout":
return {
"icon": "logout",
"label": I18n.tr("Log Out"),
"key": "X"
}
case "poweroff":
return {
"icon": "power_settings_new",
"label": I18n.tr("Power Off"),
"key": "P"
}
case "lock":
return {
"icon": "lock",
"label": I18n.tr("Lock"),
"key": "L"
}
case "suspend":
return {
"icon": "bedtime",
"label": I18n.tr("Suspend"),
"key": "S"
}
case "hibernate":
return {
"icon": "ac_unit",
"label": I18n.tr("Hibernate"),
"key": "H"
}
case "restart":
return {
"icon": "refresh",
"label": I18n.tr("Restart DMS"),
"key": "D"
}
default:
return {
"icon": "help",
"label": action,
"key": "?"
}
}
}
function selectOption(action) {
@@ -79,7 +173,7 @@ DankModal {
}
shouldBeVisible: false
width: 550
width: Math.min(550, gridColumns * 180 + Theme.spacingS * (gridColumns - 1) + Theme.spacingL * 2)
height: contentLoader.item ? contentLoader.item.implicitHeight : 300
enableShadow: true
screen: parentScreen
@@ -92,32 +186,33 @@ DankModal {
}
return Qt.point(0, 0)
}
onBackgroundClicked: () => {
return close()
}
onBackgroundClicked: () => close()
onOpened: () => {
selectedRow = 0
selectedCol = 1
updateVisibleActions()
const defaultIndex = getDefaultActionIndex()
selectedRow = Math.floor(defaultIndex / gridColumns)
selectedCol = defaultIndex % gridColumns
Qt.callLater(() => modalFocusScope.forceActiveFocus())
}
Component.onCompleted: updateVisibleActions()
modalFocusScope.Keys.onPressed: event => {
switch (event.key) {
case Qt.Key_Left:
selectedCol = (selectedCol - 1 + 3) % 3
selectedCol = (selectedCol - 1 + gridColumns) % gridColumns
event.accepted = true
break
case Qt.Key_Right:
selectedCol = (selectedCol + 1) % 3
selectedCol = (selectedCol + 1) % gridColumns
event.accepted = true
break
case Qt.Key_Up:
case Qt.Key_Backtab:
selectedRow = (selectedRow - 1 + 2) % 2
selectedRow = (selectedRow - 1 + gridRows) % gridRows
event.accepted = true
break
case Qt.Key_Down:
case Qt.Key_Tab:
selectedRow = (selectedRow + 1) % 2
selectedRow = (selectedRow + 1) % gridRows
event.accepted = true
break
case Qt.Key_Return:
@@ -127,25 +222,28 @@ DankModal {
break
case Qt.Key_N:
if (event.modifiers & Qt.ControlModifier) {
selectedCol = (selectedCol + 1) % 3
selectedCol = (selectedCol + 1) % gridColumns
event.accepted = true
}
break
case Qt.Key_P:
if (event.modifiers & Qt.ControlModifier) {
selectedCol = (selectedCol - 1 + 3) % 3
if (!(event.modifiers & Qt.ControlModifier)) {
selectOption("poweroff")
event.accepted = true
} else {
selectedCol = (selectedCol - 1 + gridColumns) % gridColumns
event.accepted = true
}
break
case Qt.Key_J:
if (event.modifiers & Qt.ControlModifier) {
selectedRow = (selectedRow + 1) % 2
selectedRow = (selectedRow + 1) % gridRows
event.accepted = true
}
break
case Qt.Key_K:
if (event.modifiers & Qt.ControlModifier) {
selectedRow = (selectedRow - 1 + 2) % 2
selectedRow = (selectedRow - 1 + gridRows) % gridRows
event.accepted = true
}
break
@@ -157,10 +255,6 @@ DankModal {
selectOption("logout")
event.accepted = true
break
case Qt.Key_P:
selectOption("poweroff")
event.accepted = true
break
case Qt.Key_L:
selectOption("lock")
event.accepted = true
@@ -170,7 +264,11 @@ DankModal {
event.accepted = true
break
case Qt.Key_H:
selectOption(SessionService.hibernateSupported ? "hibernate" : "restart")
selectOption("hibernate")
event.accepted = true
break
case Qt.Key_D:
selectOption("restart")
event.accepted = true
break
}
@@ -179,52 +277,64 @@ DankModal {
content: Component {
Item {
anchors.fill: parent
implicitHeight: mainColumn.implicitHeight + Theme.spacingL * 2
implicitHeight: buttonGrid.implicitHeight + Theme.spacingL * 2
Column {
id: mainColumn
anchors.fill: parent
anchors.margins: Theme.spacingL
spacing: Theme.spacingM
Grid {
id: buttonGrid
anchors.centerIn: parent
columns: root.gridColumns
columnSpacing: Theme.spacingS
rowSpacing: Theme.spacingS
Grid {
width: parent.width
columns: 3
columnSpacing: Theme.spacingS
rowSpacing: Theme.spacingS
Repeater {
model: root.visibleActions
Rectangle {
id: rebootButton
width: (parent.width - Theme.spacingS * 2) / 3
required property int index
required property string modelData
readonly property var actionData: root.getActionData(modelData)
readonly property bool isSelected: root.selectedIndex === index
readonly property bool showWarning: modelData === "reboot" || modelData === "poweroff"
width: (root.width - Theme.spacingL * 2 - Theme.spacingS * (root.gridColumns - 1)) / root.gridColumns
height: 100
radius: Theme.cornerRadius
color: {
if (root.selectedIndex === 0) {
if (isSelected)
return Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.12)
} else if (rebootArea.containsMouse) {
if (mouseArea.containsMouse)
return Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.08)
} else {
return Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.08)
}
return Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.08)
}
border.color: root.selectedIndex === 0 ? Theme.primary : "transparent"
border.width: root.selectedIndex === 0 ? 2 : 0
border.color: isSelected ? Theme.primary : "transparent"
border.width: isSelected ? 2 : 0
Column {
anchors.centerIn: parent
spacing: Theme.spacingS
DankIcon {
name: "restart_alt"
name: parent.parent.actionData.icon
size: Theme.iconSize + 8
color: rebootArea.containsMouse ? Theme.warning : Theme.surfaceText
color: {
if (parent.parent.showWarning && mouseArea.containsMouse) {
return parent.parent.modelData === "poweroff" ? Theme.error : Theme.warning
}
return Theme.surfaceText
}
anchors.horizontalCenter: parent.horizontalCenter
}
StyledText {
text: I18n.tr("Reboot")
text: parent.parent.actionData.label
font.pixelSize: Theme.fontSizeMedium
color: rebootArea.containsMouse ? Theme.warning : Theme.surfaceText
color: {
if (parent.parent.showWarning && mouseArea.containsMouse) {
return parent.parent.modelData === "poweroff" ? Theme.error : Theme.warning
}
return Theme.surfaceText
}
font.weight: Font.Medium
anchors.horizontalCenter: parent.horizontalCenter
}
@@ -237,7 +347,7 @@ DankModal {
anchors.horizontalCenter: parent.horizontalCenter
StyledText {
text: "R"
text: parent.parent.parent.actionData.key
font.pixelSize: Theme.fontSizeSmall - 1
color: Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.6)
font.weight: Font.Medium
@@ -247,351 +357,17 @@ DankModal {
}
MouseArea {
id: rebootArea
id: mouseArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: () => {
root.selectedRow = 0
root.selectedCol = 0
selectOption("reboot")
}
onClicked: {
root.selectedRow = Math.floor(index / root.gridColumns)
root.selectedCol = index % root.gridColumns
root.selectOption(modelData)
}
}
}
Rectangle {
id: logoutButton
width: (parent.width - Theme.spacingS * 2) / 3
height: 100
radius: Theme.cornerRadius
color: {
if (root.selectedIndex === 1) {
return Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.12)
} else if (logoutArea.containsMouse) {
return Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.08)
} else {
return Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.08)
}
}
border.color: root.selectedIndex === 1 ? Theme.primary : "transparent"
border.width: root.selectedIndex === 1 ? 2 : 0
Column {
anchors.centerIn: parent
spacing: Theme.spacingS
DankIcon {
name: "logout"
size: Theme.iconSize + 8
color: Theme.surfaceText
anchors.horizontalCenter: parent.horizontalCenter
}
StyledText {
text: I18n.tr("Log Out")
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceText
font.weight: Font.Medium
anchors.horizontalCenter: parent.horizontalCenter
}
Rectangle {
width: 20
height: 16
radius: 4
color: Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.1)
anchors.horizontalCenter: parent.horizontalCenter
StyledText {
text: "X"
font.pixelSize: Theme.fontSizeSmall - 1
color: Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.6)
font.weight: Font.Medium
anchors.centerIn: parent
}
}
}
MouseArea {
id: logoutArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: () => {
root.selectedRow = 0
root.selectedCol = 1
selectOption("logout")
}
}
}
Rectangle {
id: poweroffButton
width: (parent.width - Theme.spacingS * 2) / 3
height: 100
radius: Theme.cornerRadius
color: {
if (root.selectedIndex === 2) {
return Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.12)
} else if (poweroffArea.containsMouse) {
return Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.08)
} else {
return Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.08)
}
}
border.color: root.selectedIndex === 2 ? Theme.primary : "transparent"
border.width: root.selectedIndex === 2 ? 2 : 0
Column {
anchors.centerIn: parent
spacing: Theme.spacingS
DankIcon {
name: "power_settings_new"
size: Theme.iconSize + 8
color: poweroffArea.containsMouse ? Theme.error : Theme.surfaceText
anchors.horizontalCenter: parent.horizontalCenter
}
StyledText {
text: I18n.tr("Power Off")
font.pixelSize: Theme.fontSizeMedium
color: poweroffArea.containsMouse ? Theme.error : Theme.surfaceText
font.weight: Font.Medium
anchors.horizontalCenter: parent.horizontalCenter
}
Rectangle {
width: 20
height: 16
radius: 4
color: Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.1)
anchors.horizontalCenter: parent.horizontalCenter
StyledText {
text: "P"
font.pixelSize: Theme.fontSizeSmall - 1
color: Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.6)
font.weight: Font.Medium
anchors.centerIn: parent
}
}
}
MouseArea {
id: poweroffArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: () => {
root.selectedRow = 0
root.selectedCol = 2
selectOption("poweroff")
}
}
}
Rectangle {
id: lockButton
width: (parent.width - Theme.spacingS * 2) / 3
height: 100
radius: Theme.cornerRadius
color: {
if (root.selectedIndex === 3) {
return Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.12)
} else if (lockArea.containsMouse) {
return Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.08)
} else {
return Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.08)
}
}
border.color: root.selectedIndex === 3 ? Theme.primary : "transparent"
border.width: root.selectedIndex === 3 ? 2 : 0
Column {
anchors.centerIn: parent
spacing: Theme.spacingS
DankIcon {
name: "lock"
size: Theme.iconSize + 8
color: Theme.surfaceText
anchors.horizontalCenter: parent.horizontalCenter
}
StyledText {
text: I18n.tr("Lock")
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceText
font.weight: Font.Medium
anchors.horizontalCenter: parent.horizontalCenter
}
Rectangle {
width: 20
height: 16
radius: 4
color: Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.1)
anchors.horizontalCenter: parent.horizontalCenter
StyledText {
text: "L"
font.pixelSize: Theme.fontSizeSmall - 1
color: Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.6)
font.weight: Font.Medium
anchors.centerIn: parent
}
}
}
MouseArea {
id: lockArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: () => {
root.selectedRow = 1
root.selectedCol = 0
selectOption("lock")
}
}
}
Rectangle {
id: suspendButton
width: (parent.width - Theme.spacingS * 2) / 3
height: 100
radius: Theme.cornerRadius
color: {
if (root.selectedIndex === 4) {
return Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.12)
} else if (suspendArea.containsMouse) {
return Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.08)
} else {
return Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.08)
}
}
border.color: root.selectedIndex === 4 ? Theme.primary : "transparent"
border.width: root.selectedIndex === 4 ? 2 : 0
Column {
anchors.centerIn: parent
spacing: Theme.spacingS
DankIcon {
name: "bedtime"
size: Theme.iconSize + 8
color: Theme.surfaceText
anchors.horizontalCenter: parent.horizontalCenter
}
StyledText {
text: I18n.tr("Suspend")
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceText
font.weight: Font.Medium
anchors.horizontalCenter: parent.horizontalCenter
}
Rectangle {
width: 20
height: 16
radius: 4
color: Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.1)
anchors.horizontalCenter: parent.horizontalCenter
StyledText {
text: "S"
font.pixelSize: Theme.fontSizeSmall - 1
color: Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.6)
font.weight: Font.Medium
anchors.centerIn: parent
}
}
}
MouseArea {
id: suspendArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: () => {
root.selectedRow = 1
root.selectedCol = 1
selectOption("suspend")
}
}
}
Rectangle {
id: hibernateOrRestartButton
width: (parent.width - Theme.spacingS * 2) / 3
height: 100
radius: Theme.cornerRadius
color: {
if (root.selectedIndex === 5) {
return Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.12)
} else if (hibernateRestartArea.containsMouse) {
return Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.08)
} else {
return Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.08)
}
}
border.color: root.selectedIndex === 5 ? Theme.primary : "transparent"
border.width: root.selectedIndex === 5 ? 2 : 0
Column {
anchors.centerIn: parent
spacing: Theme.spacingS
DankIcon {
name: SessionService.hibernateSupported ? "ac_unit" : "refresh"
size: Theme.iconSize + 8
color: Theme.surfaceText
anchors.horizontalCenter: parent.horizontalCenter
}
StyledText {
text: SessionService.hibernateSupported ? I18n.tr("Hibernate") : I18n.tr("Restart")
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceText
font.weight: Font.Medium
anchors.horizontalCenter: parent.horizontalCenter
}
Rectangle {
width: 20
height: 16
radius: 4
color: Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.1)
anchors.horizontalCenter: parent.horizontalCenter
StyledText {
text: "H"
font.pixelSize: Theme.fontSizeSmall - 1
color: Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.6)
font.weight: Font.Medium
anchors.centerIn: parent
}
}
}
MouseArea {
id: hibernateRestartArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: () => {
root.selectedRow = 1
root.selectedCol = 2
selectOption(SessionService.hibernateSupported ? "hibernate" : "restart")
}
}
}
}
Item {
height: Theme.spacingS
}
}
}

View File

@@ -76,10 +76,10 @@ Item {
checked: SessionService.loginctlAvailable && SettingsData.loginctlLockIntegration
enabled: SessionService.loginctlAvailable
onToggled: checked => {
if (SessionService.loginctlAvailable) {
SettingsData.set("loginctlLockIntegration", checked)
}
}
if (SessionService.loginctlAvailable) {
SettingsData.set("loginctlLockIntegration", checked)
}
}
}
DankToggle {
@@ -185,16 +185,16 @@ Item {
}
onValueChanged: value => {
const index = timeoutOptions.indexOf(value)
if (index >= 0) {
const timeout = timeoutValues[index]
if (powerCategory.currentIndex === 0) {
SettingsData.set("acLockTimeout", timeout)
} else {
SettingsData.set("batteryLockTimeout", timeout)
}
}
}
const index = timeoutOptions.indexOf(value)
if (index >= 0) {
const timeout = timeoutValues[index]
if (powerCategory.currentIndex === 0) {
SettingsData.set("acLockTimeout", timeout)
} else {
SettingsData.set("batteryLockTimeout", timeout)
}
}
}
}
DankDropdown {
@@ -222,16 +222,16 @@ Item {
}
onValueChanged: value => {
const index = timeoutOptions.indexOf(value)
if (index >= 0) {
const timeout = timeoutValues[index]
if (powerCategory.currentIndex === 0) {
SettingsData.set("acMonitorTimeout", timeout)
} else {
SettingsData.set("batteryMonitorTimeout", timeout)
}
}
}
const index = timeoutOptions.indexOf(value)
if (index >= 0) {
const timeout = timeoutValues[index]
if (powerCategory.currentIndex === 0) {
SettingsData.set("acMonitorTimeout", timeout)
} else {
SettingsData.set("batteryMonitorTimeout", timeout)
}
}
}
}
DankDropdown {
@@ -259,16 +259,16 @@ Item {
}
onValueChanged: value => {
const index = timeoutOptions.indexOf(value)
if (index >= 0) {
const timeout = timeoutValues[index]
if (powerCategory.currentIndex === 0) {
SettingsData.set("acSuspendTimeout", timeout)
} else {
SettingsData.set("batterySuspendTimeout", timeout)
}
}
}
const index = timeoutOptions.indexOf(value)
if (index >= 0) {
const timeout = timeoutValues[index]
if (powerCategory.currentIndex === 0) {
SettingsData.set("acSuspendTimeout", timeout)
} else {
SettingsData.set("batterySuspendTimeout", timeout)
}
}
}
}
Column {
@@ -304,14 +304,14 @@ Item {
}
onSelectionChanged: (index, selected) => {
if (selected) {
if (powerCategory.currentIndex === 0) {
SettingsData.set("acSuspendBehavior", index)
} else {
SettingsData.set("batterySuspendBehavior", index)
}
}
}
if (selected) {
if (powerCategory.currentIndex === 0) {
SettingsData.set("acSuspendBehavior", index)
} else {
SettingsData.set("batterySuspendBehavior", index)
}
}
}
}
}
@@ -325,6 +325,185 @@ Item {
}
}
StyledRect {
width: parent.width
height: powerMenuCustomSection.implicitHeight + Theme.spacingL * 2
radius: Theme.cornerRadius
color: Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.3)
border.color: Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.2)
border.width: 0
Column {
id: powerMenuCustomSection
anchors.fill: parent
anchors.margins: Theme.spacingL
spacing: Theme.spacingM
Row {
width: parent.width
spacing: Theme.spacingM
DankIcon {
name: "tune"
size: Theme.iconSize
color: Theme.primary
anchors.verticalCenter: parent.verticalCenter
}
StyledText {
text: I18n.tr("Power Menu Customization")
font.pixelSize: Theme.fontSizeLarge
font.weight: Font.Medium
color: Theme.surfaceText
anchors.verticalCenter: parent.verticalCenter
}
}
StyledText {
text: I18n.tr("Customize which actions appear in the power menu")
font.pixelSize: Theme.fontSizeSmall
color: Theme.surfaceVariantText
width: parent.width
wrapMode: Text.Wrap
}
DankDropdown {
id: defaultActionDropdown
width: parent.width
addHorizontalPadding: true
text: I18n.tr("Default selected action")
options: ["Reboot", "Log Out", "Power Off", "Lock", "Suspend", "Restart DMS", "Hibernate"]
property var actionValues: ["reboot", "logout", "poweroff", "lock", "suspend", "restart", "hibernate"]
Component.onCompleted: {
const currentAction = SettingsData.powerMenuDefaultAction || "logout"
const index = actionValues.indexOf(currentAction)
currentValue = index >= 0 ? options[index] : "Log Out"
}
onValueChanged: value => {
const index = options.indexOf(value)
if (index >= 0) {
SettingsData.set("powerMenuDefaultAction", actionValues[index])
}
}
}
Column {
width: parent.width
spacing: Theme.spacingS
DankToggle {
width: parent.width
text: I18n.tr("Show Reboot")
checked: SettingsData.powerMenuActions.includes("reboot")
onToggled: checked => {
let actions = [...SettingsData.powerMenuActions]
if (checked && !actions.includes("reboot")) {
actions.push("reboot")
} else if (!checked) {
actions = actions.filter(a => a !== "reboot")
}
SettingsData.set("powerMenuActions", actions)
}
}
DankToggle {
width: parent.width
text: I18n.tr("Show Log Out")
checked: SettingsData.powerMenuActions.includes("logout")
onToggled: checked => {
let actions = [...SettingsData.powerMenuActions]
if (checked && !actions.includes("logout")) {
actions.push("logout")
} else if (!checked) {
actions = actions.filter(a => a !== "logout")
}
SettingsData.set("powerMenuActions", actions)
}
}
DankToggle {
width: parent.width
text: I18n.tr("Show Power Off")
checked: SettingsData.powerMenuActions.includes("poweroff")
onToggled: checked => {
let actions = [...SettingsData.powerMenuActions]
if (checked && !actions.includes("poweroff")) {
actions.push("poweroff")
} else if (!checked) {
actions = actions.filter(a => a !== "poweroff")
}
SettingsData.set("powerMenuActions", actions)
}
}
DankToggle {
width: parent.width
text: I18n.tr("Show Lock")
checked: SettingsData.powerMenuActions.includes("lock")
onToggled: checked => {
let actions = [...SettingsData.powerMenuActions]
if (checked && !actions.includes("lock")) {
actions.push("lock")
} else if (!checked) {
actions = actions.filter(a => a !== "lock")
}
SettingsData.set("powerMenuActions", actions)
}
}
DankToggle {
width: parent.width
text: I18n.tr("Show Suspend")
checked: SettingsData.powerMenuActions.includes("suspend")
onToggled: checked => {
let actions = [...SettingsData.powerMenuActions]
if (checked && !actions.includes("suspend")) {
actions.push("suspend")
} else if (!checked) {
actions = actions.filter(a => a !== "suspend")
}
SettingsData.set("powerMenuActions", actions)
}
}
DankToggle {
width: parent.width
text: I18n.tr("Show Restart DMS")
description: I18n.tr("Restart the DankMaterialShell")
checked: SettingsData.powerMenuActions.includes("restart")
onToggled: checked => {
let actions = [...SettingsData.powerMenuActions]
if (checked && !actions.includes("restart")) {
actions.push("restart")
} else if (!checked) {
actions = actions.filter(a => a !== "restart")
}
SettingsData.set("powerMenuActions", actions)
}
}
DankToggle {
width: parent.width
text: I18n.tr("Show Hibernate")
description: I18n.tr("Only visible if hibernate is supported by your system")
checked: SettingsData.powerMenuActions.includes("hibernate")
visible: SessionService.hibernateSupported
onToggled: checked => {
let actions = [...SettingsData.powerMenuActions]
if (checked && !actions.includes("hibernate")) {
actions.push("hibernate")
} else if (!checked) {
actions = actions.filter(a => a !== "hibernate")
}
SettingsData.set("powerMenuActions", actions)
}
}
}
}
}
StyledRect {
width: parent.width
height: powerCommandConfirmSection.implicitHeight + Theme.spacingL * 2
@@ -425,12 +604,12 @@ Item {
Component.onCompleted: {
if (SettingsData.customPowerActionLock) {
text = SettingsData.customPowerActionLock;
text = SettingsData.customPowerActionLock
}
}
onTextEdited: {
SettingsData.set("customPowerActionLock", text.trim());
SettingsData.set("customPowerActionLock", text.trim())
}
}
}
@@ -457,12 +636,12 @@ Item {
Component.onCompleted: {
if (SettingsData.customPowerActionLogout) {
text = SettingsData.customPowerActionLogout;
text = SettingsData.customPowerActionLogout
}
}
onTextEdited: {
SettingsData.set("customPowerActionLogout", text.trim());
SettingsData.set("customPowerActionLogout", text.trim())
}
}
}
@@ -489,12 +668,12 @@ Item {
Component.onCompleted: {
if (SettingsData.customPowerActionSuspend) {
text = SettingsData.customPowerActionSuspend;
text = SettingsData.customPowerActionSuspend
}
}
onTextEdited: {
SettingsData.set("customPowerActionSuspend", text.trim());
SettingsData.set("customPowerActionSuspend", text.trim())
}
}
}
@@ -521,12 +700,12 @@ Item {
Component.onCompleted: {
if (SettingsData.customPowerActionHibernate) {
text = SettingsData.customPowerActionHibernate;
text = SettingsData.customPowerActionHibernate
}
}
onTextEdited: {
SettingsData.set("customPowerActionHibernate", text.trim());
SettingsData.set("customPowerActionHibernate", text.trim())
}
}
}
@@ -553,12 +732,12 @@ Item {
Component.onCompleted: {
if (SettingsData.customPowerActionReboot) {
text = SettingsData.customPowerActionReboot;
text = SettingsData.customPowerActionReboot
}
}
onTextEdited: {
SettingsData.set("customPowerActionReboot", text.trim());
SettingsData.set("customPowerActionReboot", text.trim())
}
}
}
@@ -585,12 +764,12 @@ Item {
Component.onCompleted: {
if (SettingsData.customPowerActionPowerOff) {
text = SettingsData.customPowerActionPowerOff;
text = SettingsData.customPowerActionPowerOff
}
}
onTextEdited: {
SettingsData.set("customPowerActionPowerOff", text.trim());
SettingsData.set("customPowerActionPowerOff", text.trim())
}
}
}