1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-07 22:15:38 -05:00

polkit: simplify service usage

This commit is contained in:
bbedward
2025-10-31 11:51:11 -04:00
parent 3b5a951431
commit 7252d1e4d7
6 changed files with 259 additions and 184 deletions

View File

@@ -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