import QtQuick import Quickshell import Quickshell.Services.Polkit Item { id: root property bool active: false property bool completed: false property bool authorized: false property bool cancelled: false property string error: "" property var request: ({ }) property var lastAction: ({ }) readonly property bool nativeActionRoute: true readonly property var boundedActions: ["submit", "deny", "cancel", "fail", "clear"] readonly property var buttons: ["deny", "cancel", "confirm"] readonly property var polkitAgent: polkitAgentLoader.item function privilegeSurfacePanelContract() { return { "source": "Quickshell Polkit manual agent.qml plus Nuguland Polkit.qml plus Nuguland PolkitService.qml", "ownedBy": "shell.qml inline PrivilegeSurface", "isolatedSecuritySurface": true, "requestIdentityCard": true, "secretPromptField": true, "denyCancelConfirmRow": true, "failureShakeSlot": true, "noDecorativeDistraction": true, "serviceFedOnly": true, "nativePolkitFlow": true, "actions": buttons, "requestParts": ["app", "actionId", "message", "prompt", "responseVisible"] }; } function stateObject() { return { "backend": "Privilege.qml", "usesNativePolkitAgent": true, "nativeActionRoute": nativeActionRoute, "agentPath": "/org/nuguland/PolkitAgent", "agentRegistered": !!(polkitAgent && polkitAgent.isRegistered), "agentActive": !!(polkitAgent && polkitAgent.isActive), "helperProcesses": [], "serviceOwnedActions": true, "boundedActions": boundedActions, "surface": "isolated-fullscreen-security-surface", "keyboardFocus": true, "escapeCancels": true, "decorativeDistraction": false, "buttons": buttons, "privilegeSurfacePanelContract": privilegeSurfacePanelContract(), "active": active, "completed": completed, "authorized": authorized, "cancelled": cancelled, "request": request, "error": error, "lastAction": lastAction }; } function stateJson() { return JSON.stringify(stateObject()); } function finish(granted) { active = false; completed = true; authorized = !!granted; cancelled = false; error = ""; } function submit(secret) { const length = String(secret).length; const flow = polkitAgent ? polkitAgent.flow : null; if (flow && flow.isResponseRequired) flow.submit(String(secret)); else error = "no-active-polkit-flow"; lastAction = { "kind": "submit", "secretLength": length, "nativeActionRoute": nativeActionRoute }; return stateJson(); } function deny() { const flow = polkitAgent ? polkitAgent.flow : null; if (flow) flow.cancelAuthenticationRequest(); active = false; completed = true; authorized = false; cancelled = false; error = ""; lastAction = { "kind": "deny", "nativeActionRoute": nativeActionRoute }; return stateJson(); } function cancel() { const flow = polkitAgent ? polkitAgent.flow : null; if (flow) flow.cancelAuthenticationRequest(); active = false; completed = false; authorized = false; cancelled = true; error = ""; lastAction = { "kind": "cancel", "nativeActionRoute": nativeActionRoute }; return stateJson(); } function fail(message) { active = true; completed = false; authorized = false; cancelled = false; error = String(message); lastAction = { "kind": "fail", "message": error }; return stateJson(); } function clear() { active = false; completed = false; authorized = false; cancelled = false; request = ({ }); error = ""; lastAction = { "kind": "clear" }; return stateJson(); } Loader { id: polkitAgentLoader active: true sourceComponent: PolkitAgent { path: "/org/nuguland/PolkitAgent" } } Connections { function onAuthenticationRequestStarted() { const flow = polkitAgent ? polkitAgent.flow : null; root.active = true; root.completed = false; root.authorized = false; root.cancelled = false; root.error = ""; root.request = { "app": flow ? (flow.iconName || "polkit") : "polkit", "actionId": flow ? flow.actionId : "", "message": flow ? flow.message : "Authentication required", "prompt": flow ? (flow.inputPrompt || "Password") : "Password", "responseVisible": flow ? !!flow.responseVisible : false }; root.lastAction = { "kind": "native-request", "actionId": root.request.actionId, "nativeActionRoute": true }; } target: polkitAgent } Connections { function onAuthenticationSucceeded() { root.finish(true); } function onAuthenticationFailed() { root.fail("Authentication failed"); } function onAuthenticationRequestCancelled() { root.cancel(); } target: !polkitAgent ? null : polkitAgent.flow } }