From 7252d1e4d7d23984f142e4945c7d5b8f7d8d8a1e Mon Sep 17 00:00:00 2001 From: bbedward Date: Fri, 31 Oct 2025 11:51:11 -0400 Subject: [PATCH] polkit: simplify service usage --- Modals/PolkitAuthModal.qml | 231 ++++++++++++++------- Modules/DankBar/Widgets/LauncherButton.qml | 2 - Services/PolkitService.qml | 61 ------ Widgets/DankPopout.qml | 2 +- Widgets/StyledText.qml | 2 +- assets/danklogo.svg | 145 +++++++++---- 6 files changed, 259 insertions(+), 184 deletions(-) diff --git a/Modals/PolkitAuthModal.qml b/Modals/PolkitAuthModal.qml index 853b96b9..ba2c5917 100644 --- a/Modals/PolkitAuthModal.qml +++ b/Modals/PolkitAuthModal.qml @@ -8,9 +8,13 @@ DankModal { id: root property string passwordInput: "" + property var currentFlow: PolkitService.agent?.flow + property bool isLoading: false + property real minHeight: 240 function show() { passwordInput = "" + isLoading = false open() Qt.callLater(() => { if (contentLoader.item && contentLoader.item.passwordField) { @@ -21,11 +25,17 @@ DankModal { shouldBeVisible: false width: 420 - height: contentLoader.item ? contentLoader.item.implicitHeight + Theme.spacingM * 2 : 240 + height: Math.max(minHeight, contentLoader.item ? contentLoader.item.implicitHeight + Theme.spacingM * 2 : 240) - onShouldBeVisibleChanged: () => { - if (!shouldBeVisible) { - passwordInput = "" + Connections { + target: contentLoader.item + function onImplicitHeightChanged() { + if (shouldBeVisible && contentLoader.item) { + const newHeight = contentLoader.item.implicitHeight + Theme.spacingM * 2 + if (newHeight > minHeight) { + minHeight = newHeight + } + } } } @@ -37,32 +47,57 @@ DankModal { }) } - onBackgroundClicked: () => { - PolkitService.cancel() - close() + onClosed: { passwordInput = "" + isLoading = false + } + + onBackgroundClicked: () => { + if (currentFlow && !isLoading) { + currentFlow.cancelAuthenticationRequest() + } } Connections { - target: PolkitService + target: PolkitService.agent + enabled: PolkitService.polkitAvailable - function onAuthenticationRequested() { + function onAuthenticationRequestStarted() { show() } - function onAuthenticationCompleted() { - close() - passwordInput = "" + function onIsActiveChanged() { + if (!(PolkitService.agent?.isActive ?? false)) { + close() + } } + } + + Connections { + target: currentFlow + enabled: currentFlow !== null function onIsResponseRequiredChanged() { - if (PolkitService.isResponseRequired && root.shouldBeVisible) { + if (currentFlow.isResponseRequired) { + isLoading = false passwordInput = "" if (contentLoader.item && contentLoader.item.passwordField) { contentLoader.item.passwordField.forceActiveFocus() } } } + + function onAuthenticationSucceeded() { + close() + } + + function onAuthenticationFailed() { + isLoading = false + } + + function onAuthenticationRequestCancelled() { + close() + } } content: Component { @@ -73,89 +108,89 @@ DankModal { anchors.fill: parent focus: true - implicitHeight: mainColumn.implicitHeight + implicitHeight: headerRow.implicitHeight + mainColumn.implicitHeight + Theme.spacingM Keys.onEscapePressed: event => { - PolkitService.cancel() - close() - passwordInput = "" + if (currentFlow && !isLoading) { + currentFlow.cancelAuthenticationRequest() + } event.accepted = true } - Column { - id: mainColumn + Row { + id: headerRow anchors.left: parent.left anchors.right: parent.right anchors.top: parent.top anchors.leftMargin: Theme.spacingM anchors.rightMargin: Theme.spacingM anchors.topMargin: Theme.spacingM - spacing: Theme.spacingM - Row { - width: parent.width + Column { + width: parent.width - 40 + spacing: Theme.spacingXS + + StyledText { + text: I18n.tr("Authentication Required") + font.pixelSize: Theme.fontSizeLarge + color: Theme.surfaceText + font.weight: Font.Medium + } Column { - width: parent.width - 40 + width: parent.width spacing: Theme.spacingXS StyledText { - text: I18n.tr("Authentication Required") - font.pixelSize: Theme.fontSizeLarge - color: Theme.surfaceText - font.weight: Font.Medium - } - - Column { + text: currentFlow?.message ?? "" + font.pixelSize: Theme.fontSizeMedium + color: Theme.surfaceTextMedium width: parent.width - spacing: Theme.spacingXS - - StyledText { - text: PolkitService.message - font.pixelSize: Theme.fontSizeMedium - color: Theme.surfaceTextMedium - width: parent.width - wrapMode: Text.Wrap - } - - StyledText { - visible: PolkitService.supplementaryMessage !== "" - text: PolkitService.supplementaryMessage - font.pixelSize: Theme.fontSizeSmall - color: Theme.surfaceTextMedium - width: parent.width - wrapMode: Text.Wrap - opacity: 0.8 - } - - StyledText { - visible: PolkitService.failed - text: I18n.tr("Authentication failed, please try again") - font.pixelSize: Theme.fontSizeSmall - color: Theme.error - width: parent.width - } + wrapMode: Text.Wrap } - } - DankActionButton { - iconName: "close" - iconSize: Theme.iconSize - 4 - iconColor: Theme.surfaceText - onClicked: () => { - PolkitService.cancel() - close() - passwordInput = "" + StyledText { + visible: (currentFlow?.supplementaryMessage ?? "") !== "" + text: currentFlow?.supplementaryMessage ?? "" + font.pixelSize: Theme.fontSizeSmall + color: (currentFlow?.supplementaryIsError ?? false) ? Theme.error : Theme.surfaceTextMedium + width: parent.width + wrapMode: Text.Wrap + opacity: (currentFlow?.supplementaryIsError ?? false) ? 1 : 0.8 } } } + DankActionButton { + iconName: "close" + iconSize: Theme.iconSize - 4 + iconColor: Theme.surfaceText + enabled: !isLoading + opacity: enabled ? 1 : 0.5 + onClicked: () => { + if (currentFlow) { + currentFlow.cancelAuthenticationRequest() + } + } + } + } + + Column { + id: mainColumn + anchors.left: parent.left + anchors.right: parent.right + anchors.bottom: parent.bottom + anchors.leftMargin: Theme.spacingM + anchors.rightMargin: Theme.spacingM + anchors.bottomMargin: Theme.spacingM + spacing: Theme.spacingM + StyledText { - text: PolkitService.inputPrompt + text: currentFlow?.inputPrompt ?? "" font.pixelSize: Theme.fontSizeMedium color: Theme.surfaceText width: parent.width - visible: PolkitService.inputPrompt !== "" + visible: (currentFlow?.inputPrompt ?? "") !== "" } Rectangle { @@ -165,9 +200,11 @@ DankModal { color: Theme.surfaceHover border.color: passwordField.activeFocus ? Theme.primary : Theme.outlineStrong border.width: passwordField.activeFocus ? 2 : 1 + opacity: isLoading ? 0.5 : 1 MouseArea { anchors.fill: parent + enabled: !isLoading onClicked: () => { passwordField.forceActiveFocus() } @@ -180,22 +217,52 @@ DankModal { font.pixelSize: Theme.fontSizeMedium textColor: Theme.surfaceText text: passwordInput - echoMode: PolkitService.responseVisible ? TextInput.Normal : TextInput.Password - placeholderText: I18n.tr("Password") + echoMode: (currentFlow?.responseVisible ?? false) ? TextInput.Normal : TextInput.Password + placeholderText: "" backgroundColor: "transparent" - enabled: root.shouldBeVisible + enabled: !isLoading onTextEdited: () => { passwordInput = text } onAccepted: () => { - if (passwordInput.length > 0) { - PolkitService.submit(passwordInput) + if (passwordInput.length > 0 && currentFlow && !isLoading) { + isLoading = true + currentFlow.submit(passwordInput) passwordInput = "" } } } } + Item { + width: parent.width + height: (currentFlow?.failed ?? false) ? failedText.implicitHeight : 0 + visible: height > 0 + + StyledText { + id: failedText + text: I18n.tr("Authentication failed, please try again") + font.pixelSize: Theme.fontSizeSmall + color: Theme.error + width: parent.width + opacity: (currentFlow?.failed ?? false) ? 1 : 0 + + Behavior on opacity { + NumberAnimation { + duration: Theme.shortDuration + easing.type: Theme.standardEasing + } + } + } + + Behavior on height { + NumberAnimation { + duration: Theme.shortDuration + easing.type: Theme.standardEasing + } + } + } + Item { width: parent.width height: 40 @@ -212,6 +279,8 @@ DankModal { color: cancelArea.containsMouse ? Theme.surfaceTextHover : "transparent" border.color: Theme.surfaceVariantAlpha border.width: 1 + enabled: !isLoading + opacity: enabled ? 1 : 0.5 StyledText { id: cancelText @@ -229,10 +298,11 @@ DankModal { anchors.fill: parent hoverEnabled: true cursorShape: Qt.PointingHandCursor + enabled: parent.enabled onClicked: () => { - PolkitService.cancel() - close() - passwordInput = "" + if (currentFlow) { + currentFlow.cancelAuthenticationRequest() + } } } } @@ -242,7 +312,7 @@ DankModal { height: 36 radius: Theme.cornerRadius color: authArea.containsMouse ? Qt.darker(Theme.primary, 1.1) : Theme.primary - enabled: passwordInput.length > 0 || !PolkitService.isResponseRequired + enabled: !isLoading && (passwordInput.length > 0 || !(currentFlow?.isResponseRequired ?? true)) opacity: enabled ? 1 : 0.5 StyledText { @@ -263,8 +333,11 @@ DankModal { cursorShape: Qt.PointingHandCursor enabled: parent.enabled onClicked: () => { - PolkitService.submit(passwordInput) - passwordInput = "" + if (currentFlow && !isLoading) { + isLoading = true + currentFlow.submit(passwordInput) + passwordInput = "" + } } } diff --git a/Modules/DankBar/Widgets/LauncherButton.qml b/Modules/DankBar/Widgets/LauncherButton.qml index 4d650575..a302a8fb 100644 --- a/Modules/DankBar/Widgets/LauncherButton.qml +++ b/Modules/DankBar/Widgets/LauncherButton.qml @@ -52,8 +52,6 @@ BasePill { saturation: 0 colorization: 1 colorizationColor: Theme.effectiveLogoColor - brightness: 0.55 - contrast: 0.5 } } diff --git a/Services/PolkitService.qml b/Services/PolkitService.qml index 84e0a591..5238d042 100644 --- a/Services/PolkitService.qml +++ b/Services/PolkitService.qml @@ -10,21 +10,7 @@ Singleton { readonly property bool disablePolkitIntegration: Quickshell.env("DMS_DISABLE_POLKIT") === "1" property bool polkitAvailable: false - property var agent: null - property var currentFlow: null - property bool isActive: false - - property string message: "" - property string supplementaryMessage: "" - property string inputPrompt: "" - property bool failed: false - property bool responseVisible: false - property bool isResponseRequired: false - - signal authenticationRequested() - signal authenticationCompleted() - signal authenticationFailed() function createPolkitAgent() { try { @@ -37,30 +23,6 @@ Singleton { ` agent = Qt.createQmlObject(qmlString, root, "PolkitService.Agent") - - agent.isActiveChanged.connect(function() { - root.isActive = agent.isActive - if (agent.isActive) { - root.authenticationRequested() - } else { - root.authenticationCompleted() - } - }) - - agent.flowChanged.connect(function() { - currentFlow = agent.flow - if (currentFlow) { - updateFlowProperties() - - if (currentFlow.messageChanged) currentFlow.messageChanged.connect(() => updateFlowProperties()) - if (currentFlow.supplementaryMessageChanged) currentFlow.supplementaryMessageChanged.connect(() => updateFlowProperties()) - if (currentFlow.inputPromptChanged) currentFlow.inputPromptChanged.connect(() => updateFlowProperties()) - if (currentFlow.failedChanged) currentFlow.failedChanged.connect(() => updateFlowProperties()) - if (currentFlow.responseVisibleChanged) currentFlow.responseVisibleChanged.connect(() => updateFlowProperties()) - if (currentFlow.isResponseRequiredChanged) currentFlow.isResponseRequiredChanged.connect(() => updateFlowProperties()) - } - }) - polkitAvailable = true console.info("PolkitService: Initialized successfully") } catch (e) { @@ -69,29 +31,6 @@ Singleton { } } - function updateFlowProperties() { - if (!currentFlow) return - - message = currentFlow.message !== undefined ? currentFlow.message : "" - supplementaryMessage = currentFlow.supplementaryMessage !== undefined ? currentFlow.supplementaryMessage : "" - inputPrompt = currentFlow.inputPrompt !== undefined ? currentFlow.inputPrompt : "" - failed = currentFlow.failed !== undefined ? currentFlow.failed : false - responseVisible = currentFlow.responseVisible !== undefined ? currentFlow.responseVisible : false - isResponseRequired = currentFlow.isResponseRequired !== undefined ? currentFlow.isResponseRequired : false - } - - function submit(response) { - if (currentFlow && isResponseRequired) { - currentFlow.submit(response) - } - } - - function cancel() { - if (currentFlow) { - currentFlow.cancelAuthenticationRequest() - } - } - Component.onCompleted: { if (disablePolkitIntegration) { return diff --git a/Widgets/DankPopout.qml b/Widgets/DankPopout.qml index 54a1f985..35d7256d 100644 --- a/Widgets/DankPopout.qml +++ b/Widgets/DankPopout.qml @@ -121,7 +121,7 @@ PanelWindow { active: root.visible asynchronous: false transformOrigin: Item.Center - layer.enabled: Quickshell.env("DMS_DISABLE_LAYER") !== "true" + layer.enabled: Quickshell.env("DMS_DISABLE_LAYER") !== "true" && Quickshell.env("DMS_DISABLE_LAYER") !== "1" layer.smooth: true opacity: shouldBeVisible ? 1 : 0 transform: [scaleTransform, motionTransform] diff --git a/Widgets/StyledText.qml b/Widgets/StyledText.qml index 49a80d87..32fa55e4 100644 --- a/Widgets/StyledText.qml +++ b/Widgets/StyledText.qml @@ -47,4 +47,4 @@ Text { easing.bezierCurve: standardAnimation["easing.bezierCurve"] } } -} +} \ No newline at end of file diff --git a/assets/danklogo.svg b/assets/danklogo.svg index fa3eb34f..879bf303 100644 --- a/assets/danklogo.svg +++ b/assets/danklogo.svg @@ -1,40 +1,105 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +