diff --git a/dotfiles/quickshell/HyprChrome/Widgets/Askpass/AskpassPrompt.qml b/dotfiles/quickshell/HyprChrome/Widgets/Askpass/AskpassPrompt.qml index 27bd58f..cab72b3 100644 --- a/dotfiles/quickshell/HyprChrome/Widgets/Askpass/AskpassPrompt.qml +++ b/dotfiles/quickshell/HyprChrome/Widgets/Askpass/AskpassPrompt.qml @@ -64,6 +64,8 @@ Scope { root.promptText = message === "" ? "Password:" : message; root.fifoPath = fifo; root.failed = false; + vault.invalidate(); + vault.refresh(); return "ok"; } @@ -101,12 +103,22 @@ Scope { if (!root.active) return; + vault.invalidate(); root.pendingSecret = secret + "\n"; writer.command = ["sh", "-c", "IFS= read -r line; printf %s \"$line\" > \"$1\"", "sh", root.fifoPath]; writer.running = true; root.fifoPath = ""; } + ProtonPass { + id: vault + + onFetched: secret => { + content.response = secret; + content.focusInput(); + } + } + // Opening a fifo for writing BLOCKS until a reader attaches, which is why // this is a subprocess rather than a FileView: the helper's `cat` is that // reader, and blocking the QML thread on it would freeze the shell. @@ -149,7 +161,7 @@ Scope { id: content anchors.horizontalCenter: parent.horizontalCenter - y: Math.max(32, Math.round(parent.height / 3 - height / 2)) + y: Math.max(32, Math.round(parent.height / 3 - content.dialogHeight / 2)) width: 520 // Deliberately the polkit dialog's own content component: this is a @@ -168,6 +180,17 @@ Scope { responseVisible: false failed: root.failed + credentialsEnabled: true + credentials: vault.entries + credentialsStatus: vault.listStatus + fetchStatus: vault.fetchStatus + + onCredentialRequested: entry => vault.fetch(entry) + onPickerOpened: { + if (vault.entries.length === 0) + vault.refresh(); + } + onSubmitted: value => root.submit(value) onCancelled: root.dismiss() } diff --git a/dotfiles/quickshell/HyprChrome/Widgets/Polkit/PolkitPanel.qml b/dotfiles/quickshell/HyprChrome/Widgets/Polkit/PolkitPanel.qml index 57451ec..5e17f89 100644 --- a/dotfiles/quickshell/HyprChrome/Widgets/Polkit/PolkitPanel.qml +++ b/dotfiles/quickshell/HyprChrome/Widgets/Polkit/PolkitPanel.qml @@ -26,6 +26,8 @@ Item { property string panelId: "" property string title: "" property string meta: "" + // Header strip only: body and header rule hidden. + property bool collapsed: false property int chamfer: 16 property int padding: 14 @@ -54,7 +56,7 @@ Item { default property alias content: body.data - implicitHeight: Math.round(body.y + body.height + panel.padding) + implicitHeight: panel.collapsed ? panel.headerHeight : Math.round(body.y + body.height + panel.padding) Shape { id: panelShape @@ -181,6 +183,7 @@ Item { // Header rule. Rectangle { + visible: !panel.collapsed x: 1 y: panel.headerHeight width: parent.width - 2 @@ -194,6 +197,7 @@ Item { Item { id: body + visible: !panel.collapsed x: panel.padding y: panel.headerHeight + panel.headerGap width: Math.max(0, panel.width - panel.padding * 2) diff --git a/dotfiles/quickshell/HyprChrome/Widgets/Polkit/PolkitPrompt.qml b/dotfiles/quickshell/HyprChrome/Widgets/Polkit/PolkitPrompt.qml index 2674bff..41d5d4c 100644 --- a/dotfiles/quickshell/HyprChrome/Widgets/Polkit/PolkitPrompt.qml +++ b/dotfiles/quickshell/HyprChrome/Widgets/Polkit/PolkitPrompt.qml @@ -87,9 +87,22 @@ Scope { // never appears. Leaving it orphaned costs one hung caller; cancelling it // costs the prompt as well. onFlowChanged: { + vault.invalidate(); if (root.flow) { content.clearResponse(); content.focusInput(); + // Prefetched so Tab is instant; the list stays from the last + // request while this refreshes. + vault.refresh(); + } + } + + ProtonPass { + id: vault + + onFetched: secret => { + content.response = secret; + content.focusInput(); } } @@ -194,7 +207,7 @@ Scope { // line appears. Floored at the same margin the width leaves, so a // tall prompt on a short output cannot be pushed off the top. anchors.horizontalCenter: parent.horizontalCenter - y: Math.max(32, Math.round(parent.height / 3 - height / 2)) + y: Math.max(32, Math.round(parent.height / 3 - content.dialogHeight / 2)) width: 520 message: root.flow ? root.flow.message : "" @@ -209,6 +222,17 @@ Scope { supplementaryIsError: root.flow ? root.flow.supplementaryIsError : false failed: root.flow ? root.flow.failed : false + credentialsEnabled: true + credentials: vault.entries + credentialsStatus: vault.listStatus + fetchStatus: vault.fetchStatus + + onCredentialRequested: entry => vault.fetch(entry) + onPickerOpened: { + if (vault.entries.length === 0) + vault.refresh(); + } + onSubmitted: value => { if (root.flow) root.flow.submit(value); @@ -235,8 +259,10 @@ Scope { enabled: root.flow !== null function onFailedChanged() { - if (root.flow.failed) + if (root.flow.failed) { + vault.invalidate(); content.clearResponse(); + } } // Re-focus when the conversation asks for something. This is load diff --git a/dotfiles/quickshell/HyprChrome/Widgets/Polkit/PolkitPromptContent.qml b/dotfiles/quickshell/HyprChrome/Widgets/Polkit/PolkitPromptContent.qml index 135594f..329807d 100644 --- a/dotfiles/quickshell/HyprChrome/Widgets/Polkit/PolkitPromptContent.qml +++ b/dotfiles/quickshell/HyprChrome/Widgets/Polkit/PolkitPromptContent.qml @@ -46,15 +46,163 @@ Item { property alias response: responseInput.text + // Masking override from the eye toggle; reset with the field, so a + // revealed password never carries over to the next request. + property bool revealed: false + + // Proton Pass logins, in their own panel under the dialog, collapsed until + // Tab. Entries need only `title` and `vault`; the adapter fetches the + // password for the one picked, so no secret is ever in this list. Off by + // default, as in the headless render. + property bool credentialsEnabled: false + property var credentials: [] + // Picker-only: loading / listing failure. fetchStatus shows regardless — + // it is what explains an empty field after a pick. + property string credentialsStatus: "" + property string fetchStatus: "" + property bool pickerOpen: false + property int pickerIndex: 0 + + // Vault the list is narrowed to; "" is all of them. Kept across requests, + // so a vault picked once stays picked. + property string vaultFilter: "" + property bool overflowMenuOpen: false + + // Height of the dialog alone. The adapters position on this rather than + // implicitHeight, so expanding the vault panel grows downward instead of + // shifting the dialog up under the cursor. + readonly property real dialogHeight: panel.implicitHeight + + readonly property var vaultNames: { + const names = []; + for (const c of root.credentials) + if (!names.includes(c.vault)) + names.push(c.vault); + return names.sort((a, b) => a.toLowerCase() < b.toLowerCase() ? -1 : a.toLowerCase() > b.toLowerCase() ? 1 : 0); + } + readonly property var vaultOptions: [""].concat(root.vaultNames) + + // A remembered vault that no longer exists falls back to all. + readonly property string activeVault: root.vaultNames.includes(root.vaultFilter) ? root.vaultFilter : "" + + // Title A–Z within the chosen vault (or across all of them). + readonly property var shownCredentials: { + const q = filterInput.text.toLowerCase(); + return root.credentials + .filter(c => (root.activeVault === "" || c.vault === root.activeVault) + && (q === "" || c.title.toLowerCase().includes(q))) + .sort((a, b) => { + const ta = a.title.toLowerCase(), tb = b.title.toLowerCase(); + return ta < tb ? -1 : ta > tb ? 1 : 0; + }); + } + + function vaultLabel(name) { + return name === "" ? "ALL" : name.toUpperCase(); + } + + function vaultCount(name) { + return name === "" ? root.credentials.length : root.credentials.filter(c => c.vault === name).length; + } + + function tabText(name) { + return root.vaultLabel(name) + " " + root.vaultCount(name); + } + + // Tabs are sized from FontMetrics rather than their own implicitWidth, so + // how many fit is known before any are laid out — the overflow split + // would otherwise depend on the very tabs it decides to create. + function tabWidth(text) { + return Math.ceil(tabMetrics.advanceWidth(text) + text.length * tabMetrics.font.letterSpacing) + 16; + } + + // How many leading vault options get a tab of their own; the rest go in + // the overflow menu, which is always the last tab. + // + // The overflow tab names the selected vault when it holds it, so it is + // sized for "MORE" first and, if the selection lands in the overflow, + // re-split for that label. Shrinking can only push the selection further + // into the overflow, so the second pass is final. + readonly property int fittingTabs: { + const avail = tabStrip.width; + const widths = root.vaultOptions.map(v => root.tabWidth(root.tabText(v))); + if (widths.reduce((a, b) => a + b, 0) <= avail) + return widths.length; + const split = reserve => { + let used = reserve, k = 0; + while (k < widths.length && used + widths[k] <= avail) + used += widths[k++]; + return Math.max(1, k); + }; + const k = split(root.tabWidth("MORE ▾")); + return root.vaultOptions.indexOf(root.activeVault) >= k + ? split(root.tabWidth(root.tabText(root.activeVault) + " ▾")) : k; + } + readonly property var overflowVaults: root.vaultOptions.slice(root.fittingTabs) + signal submitted(string value) signal cancelled signal identityRequested(int index) + signal credentialRequested(var entry) + signal pickerOpened function focusInput() { responseInput.forceActiveFocus(); } - function clearResponse() { responseInput.text = ""; } + function clearResponse() { + responseInput.text = ""; + root.revealed = false; + root.closePicker(); + } + + function openPicker() { + if (!root.credentialsEnabled) + return; + filterInput.text = ""; + root.pickerIndex = 0; + root.overflowMenuOpen = false; + root.pickerOpen = true; + filterInput.forceActiveFocus(); + root.pickerOpened(); + } + + function closePicker() { + if (!root.pickerOpen) + return; + root.overflowMenuOpen = false; + root.pickerOpen = false; + root.focusInput(); + } + + function selectVault(index) { + root.vaultFilter = root.vaultOptions[index] || ""; + root.overflowMenuOpen = false; + root.pickerIndex = 0; + pickerList.positionViewAtBeginning(); + filterInput.forceActiveFocus(); + } + + function cycleVault(delta) { + const n = root.vaultOptions.length; + root.selectVault((Math.max(0, root.vaultOptions.indexOf(root.activeVault)) + delta + n) % n); + } + + function pick(index) { + const entry = root.shownCredentials[index]; + if (!entry) + return; + root.closePicker(); + root.credentialRequested(entry); + } + + function movePicker(delta) { + const n = root.shownCredentials.length; + if (n > 0) + root.pickerIndex = (root.pickerIndex + delta + n) % n; + } + + onPickerIndexChanged: pickerList.positionViewAtIndex(root.pickerIndex, ListView.Contain) implicitWidth: 520 - implicitHeight: panel.implicitHeight + implicitHeight: stack.implicitHeight // Escape reaches here by propagating up the focus chain from the TextInput, // which does not consume it — so cancelling works whether or not the input @@ -72,185 +220,558 @@ Item { elide: Text.ElideRight } - PolkitPanel { - id: panel + // A vault tab. Sized by the caller from tabWidth(), not by its label: the + // overflow split is computed before any tab exists. + component VaultTab: Item { + id: tab + + property string label: "" + property bool current: false + + signal clicked + + MicroText { + anchors.centerIn: parent + text: tab.label + color: tab.current ? Theme.accent + : tabArea.containsMouse ? Theme.text : Theme.muted + } + + Rectangle { + visible: tab.current + anchors.bottom: parent.bottom + width: parent.width + height: 2 + color: Theme.accent + } + + MouseArea { + id: tabArea + + anchors.fill: parent + hoverEnabled: true + cursorShape: Qt.PointingHandCursor + onClicked: tab.clicked() + } + } + + Column { + id: stack width: root.width - panelId: "PKT" - title: "AUTHORIZATION REQUIRED" - // The action id is the one piece that says WHAT is being authorized - // independently of the (localizable, often vague) message. - meta: root.actionId + // Clears the detached corner caps between the two panels. + spacing: 14 - // The body slot decides the width and the layout's implicitHeight - // becomes its height, so a wrapped message or an extra pam_info line - // grows the panel instead of being clipped. - ColumnLayout { - width: parent.width - spacing: 10 + PolkitPanel { + id: panel - // ---- what is being asked ---- - RowLayout { - Layout.fillWidth: true + width: root.width + panelId: "PKT" + title: "AUTHORIZATION REQUIRED" + // The action id is the one piece that says WHAT is being authorized + // independently of the (localizable, often vague) message. + meta: root.actionId + + // The body slot decides the width and the layout's implicitHeight + // becomes its height, so a wrapped message or an extra pam_info line + // grows the panel instead of being clipped. + ColumnLayout { + width: parent.width spacing: 10 - IconImage { - visible: root.showIcon && root.iconName !== "" - implicitSize: 32 - source: root.showIcon && root.iconName !== "" - ? Quickshell.iconPath(root.iconName, "dialog-password") - : "" - } - - Text { - Layout.fillWidth: true - wrapMode: Text.Wrap - text: root.message - color: Theme.text - font.family: Theme.displayFont - font.pixelSize: 13 - font.letterSpacing: 0.6 - } - } - - // ---- identity ---- - // Single identity: stated, not offered. Several: chips, because a - // combo box would be the only QtQuick.Controls widget in the rail. - MicroText { - Layout.fillWidth: true - visible: root.identities.length === 1 - text: "AS " + (root.identities.length === 1 - ? root.identities[0].displayName : "") - } - - Flow { - Layout.fillWidth: true - visible: root.identities.length > 1 - spacing: 6 - - Repeater { - model: root.identities - - Rectangle { - id: chip - - required property int index - required property var modelData - - readonly property bool current: chip.index === root.selectedIdentity - - width: chipLabel.implicitWidth + 14 - height: chipLabel.implicitHeight + 8 - color: chip.current ? Theme.accent : "transparent" - border.width: 1 - border.color: chip.current ? Theme.accent : Theme.disabled - - Text { - id: chipLabel - anchors.centerIn: parent - text: chip.modelData.displayName - color: chip.current ? Theme.surface : Theme.muted - font.family: Theme.microFont - font.pixelSize: 9 - font.letterSpacing: 0.8 - } - - MouseArea { - anchors.fill: parent - onClicked: root.identityRequested(chip.index) - } - } - } - } - - // ---- the conversation ---- - Rectangle { - Layout.fillWidth: true - implicitHeight: 34 - color: Theme.selection - border.width: 1 - border.color: root.failed ? Theme.hot : Theme.hair - + // ---- what is being asked ---- RowLayout { - anchors.fill: parent - anchors.leftMargin: 10 - anchors.rightMargin: 10 + Layout.fillWidth: true spacing: 10 - Text { - text: ">_" - color: root.responseRequired ? Theme.accent : Theme.disabled - font.family: Theme.displayFont - font.pixelSize: 15 - font.bold: true + IconImage { + visible: root.showIcon && root.iconName !== "" + implicitSize: 32 + source: root.showIcon && root.iconName !== "" + ? Quickshell.iconPath(root.iconName, "dialog-password") + : "" } - TextInput { - id: responseInput + Text { + Layout.fillWidth: true + wrapMode: Text.Wrap + text: root.message + color: Theme.text + font.family: Theme.displayFont + font.pixelSize: 13 + font.letterSpacing: 0.6 + } + } + + // ---- identity ---- + // Single identity: stated, not offered. Several: chips, because a + // combo box would be the only QtQuick.Controls widget in the rail. + MicroText { + Layout.fillWidth: true + visible: root.identities.length === 1 + text: "AS " + (root.identities.length === 1 + ? root.identities[0].displayName : "") + } + + Flow { + Layout.fillWidth: true + visible: root.identities.length > 1 + spacing: 6 + + Repeater { + model: root.identities + + Rectangle { + id: chip + + required property int index + required property var modelData + + readonly property bool current: chip.index === root.selectedIdentity + + width: chipLabel.implicitWidth + 14 + height: chipLabel.implicitHeight + 8 + color: chip.current ? Theme.accent : "transparent" + border.width: 1 + border.color: chip.current ? Theme.accent : Theme.disabled + + Text { + id: chipLabel + anchors.centerIn: parent + text: chip.modelData.displayName + color: chip.current ? Theme.surface : Theme.muted + font.family: Theme.microFont + font.pixelSize: 9 + font.letterSpacing: 0.8 + } + + MouseArea { + anchors.fill: parent + onClicked: root.identityRequested(chip.index) + } + } + } + } + + // ---- the conversation ---- + Rectangle { + Layout.fillWidth: true + implicitHeight: 34 + color: Theme.selection + border.width: 1 + border.color: root.failed ? Theme.hot : Theme.hair + + RowLayout { + anchors.fill: parent + anchors.leftMargin: 10 + anchors.rightMargin: 10 + spacing: 10 + + Text { + text: ">_" + color: root.responseRequired ? Theme.accent : Theme.disabled + font.family: Theme.displayFont + font.pixelSize: 15 + font.bold: true + } + + TextInput { + id: responseInput + + Layout.fillWidth: true + Layout.fillHeight: true + verticalAlignment: TextInput.AlignVCenter + enabled: root.responseRequired + color: Theme.text + selectionColor: Theme.accent + selectedTextColor: Theme.surface + font.family: Theme.displayFont + font.pixelSize: 14 + font.letterSpacing: 1 + clip: true + + echoMode: root.responseVisible || root.revealed + ? TextInput.Normal : TextInput.Password + passwordCharacter: "▪" + // Qt reveals the last typed character for a moment by + // default. On a screen-visible layer-shell overlay + // that is a shoulder-surfing hole, so: never. + passwordMaskDelay: 0 + + onAccepted: { + if (root.responseRequired) + root.submitted(responseInput.text); + } + + Keys.onTabPressed: event => { + root.openPicker(); + event.accepted = true; + } + + // Placeholder: TextInput has none of its own, and the + // PAM prompt ("Password:", "PIN:") is the only label + // this field gets. + Text { + anchors.verticalCenter: parent.verticalCenter + visible: responseInput.text.length === 0 + text: root.inputPrompt + color: Theme.disabled + font: responseInput.font + } + } + + // Eye toggle. Hidden when PAM already asked for echoed + // input — there is nothing left to reveal. + Text { + visible: !root.responseVisible + text: root.revealed ? "" : "" + color: root.revealed ? Theme.accent : (eyeArea.containsMouse ? Theme.text : Theme.muted) + font.family: Theme.displayFont + font.pixelSize: 14 + + MouseArea { + id: eyeArea + + anchors.fill: parent + anchors.margins: -6 + hoverEnabled: true + cursorShape: Qt.PointingHandCursor + onClicked: { + root.revealed = !root.revealed; + root.focusInput(); + } + } + } + } + } + + MicroText { + Layout.fillWidth: true + visible: root.credentialsEnabled && root.fetchStatus !== "" + text: root.fetchStatus + } + + // ---- pam_info / pam_error ---- + Text { + Layout.fillWidth: true + visible: root.supplementaryMessage !== "" + wrapMode: Text.Wrap + text: root.supplementaryMessage + color: root.supplementaryIsError ? Theme.hot : Theme.muted + font.family: Theme.microFont + font.pixelSize: 9 + font.letterSpacing: 0.7 + } + + // ---- key hints ---- + RowLayout { + Layout.fillWidth: true + spacing: 14 + + MicroText { text: "ENTER AUTHENTICATE" } + MicroText { text: "ESC CANCEL" } + Item { Layout.fillWidth: true } + MicroText { + text: root.responseVisible ? "ECHO ON" : root.revealed ? "SHOWN" : "" + color: Theme.hot + } + } + } + } + + // ---- Proton Pass ---- + // Its own panel so the dialog keeps its shape; collapsed it is the header + // strip alone. The MouseArea sits over that strip only — PolkitPanel's + // default property is the body slot, so it cannot live inside the panel. + Item { + visible: root.credentialsEnabled + width: root.width + height: vaultPanel.implicitHeight + + PolkitPanel { + id: vaultPanel + + width: parent.width + panelId: "PSS" + title: "PROTON PASS" + collapsed: !root.pickerOpen + meta: root.pickerOpen + ? root.shownCredentials.length + " / " + root.credentials.length + : "TAB OPEN" + + ColumnLayout { + width: parent.width + spacing: 6 + + // ---- vault tabs ---- + // One row; tabs that do not fit move into the overflow + // tab's menu. z above the filter and list, which the open + // menu draws over. + Item { + id: tabStrip + + z: 2 + Layout.fillWidth: true + implicitHeight: 22 + + FontMetrics { + id: tabMetrics + + font.family: Theme.microFont + font.pixelSize: 8 + font.letterSpacing: 0.9 + } + + // The rule the tabs sit on, across the full width. + Rectangle { + anchors.bottom: parent.bottom + width: parent.width + height: 1 + color: Theme.hair + } + + Row { + Repeater { + model: root.vaultOptions.slice(0, root.fittingTabs) + + VaultTab { + id: vaultTab + + required property int index + required property string modelData + + width: root.tabWidth(vaultTab.label) + height: tabStrip.height + label: root.tabText(vaultTab.modelData) + current: vaultTab.modelData === root.activeVault + onClicked: root.selectVault(vaultTab.index) + } + } + + VaultTab { + id: overflowTab + + readonly property bool holdsActive: root.overflowVaults.includes(root.activeVault) + + visible: root.overflowVaults.length > 0 + width: root.tabWidth(overflowTab.label) + height: tabStrip.height + // Names the selected vault when it is one of + // the hidden ones, so the selection stays visible. + label: (overflowTab.holdsActive ? root.tabText(root.activeVault) : "MORE") + " ▾" + current: overflowTab.holdsActive || root.overflowMenuOpen + onClicked: root.overflowMenuOpen = !root.overflowMenuOpen + + Rectangle { + visible: root.overflowMenuOpen + // Right-aligned to the tab, clamped to the strip. + x: Math.max(-overflowTab.x, overflowTab.width - width) + y: overflowTab.height + 2 + width: Math.max(180, overflowTab.width) + height: overflowColumn.implicitHeight + 2 + color: Theme.surface + border.width: 1 + border.color: Theme.accent + + Column { + id: overflowColumn + + x: 1 + y: 1 + width: parent.width - 2 + + Repeater { + model: root.overflowVaults + + Rectangle { + id: option + + required property int index + required property string modelData + + readonly property bool current: option.modelData === root.activeVault + + width: overflowColumn.width + height: 22 + color: optionArea.containsMouse ? Theme.selection : "transparent" + + Rectangle { + visible: option.current + width: 2 + height: parent.height + color: Theme.accent + } + + MicroText { + anchors.left: parent.left + anchors.leftMargin: 10 + anchors.verticalCenter: parent.verticalCenter + text: root.vaultLabel(option.modelData) + color: option.current ? Theme.accent + : optionArea.containsMouse ? Theme.text : Theme.muted + } + + MicroText { + anchors.right: parent.right + anchors.rightMargin: 8 + anchors.verticalCenter: parent.verticalCenter + text: root.vaultCount(option.modelData) + } + + MouseArea { + id: optionArea + + anchors.fill: parent + hoverEnabled: true + cursorShape: Qt.PointingHandCursor + onClicked: root.selectVault(root.fittingTabs + option.index) + } + } + } + } + } + } + } + } + + RowLayout { + Layout.fillWidth: true + spacing: 8 + + TextInput { + id: filterInput + + Layout.fillWidth: true + color: Theme.text + selectionColor: Theme.accent + selectedTextColor: Theme.surface + font.family: Theme.displayFont + font.pixelSize: 12 + clip: true + + onTextChanged: root.pickerIndex = 0 + onAccepted: root.pick(root.pickerIndex) + + // Consumed so Esc backs out of the panel instead + // of cancelling the whole request. + Keys.onEscapePressed: event => { + if (root.overflowMenuOpen) + root.overflowMenuOpen = false; + else + root.closePicker(); + event.accepted = true; + } + Keys.onTabPressed: event => { + root.cycleVault(1); + event.accepted = true; + } + Keys.onBacktabPressed: event => { + root.cycleVault(-1); + event.accepted = true; + } + Keys.onUpPressed: event => { + root.movePicker(-1); + event.accepted = true; + } + Keys.onDownPressed: event => { + root.movePicker(1); + event.accepted = true; + } + + Text { + anchors.verticalCenter: parent.verticalCenter + visible: filterInput.text.length === 0 + text: "filter logins" + color: Theme.disabled + font: filterInput.font + } + } + } + + MicroText { + Layout.fillWidth: true + visible: text !== "" + text: root.credentialsStatus !== "" ? root.credentialsStatus + : root.shownCredentials.length === 0 ? "NO MATCH" : "" + } + + ListView { + id: pickerList + + readonly property int rowHeight: 24 Layout.fillWidth: true - Layout.fillHeight: true - verticalAlignment: TextInput.AlignVCenter - enabled: root.responseRequired - color: Theme.text - selectionColor: Theme.accent - selectedTextColor: Theme.surface - font.family: Theme.displayFont - font.pixelSize: 14 - font.letterSpacing: 1 + implicitHeight: Math.min(count, 10) * rowHeight + visible: count > 0 clip: true + boundsBehavior: Flickable.StopAtBounds + model: root.shownCredentials - echoMode: root.responseVisible - ? TextInput.Normal : TextInput.Password - passwordCharacter: "▪" - // Qt reveals the last typed character for a moment by - // default. On a screen-visible layer-shell overlay - // that is a shoulder-surfing hole, so: never. - passwordMaskDelay: 0 + delegate: Rectangle { + id: row - onAccepted: { - if (root.responseRequired) - root.submitted(responseInput.text); + required property int index + required property var modelData + + readonly property bool current: row.index === root.pickerIndex + + width: pickerList.width + height: pickerList.rowHeight + color: row.current ? Theme.selection : "transparent" + + Rectangle { + visible: row.current + width: 2 + height: parent.height + color: Theme.accent + } + + RowLayout { + anchors.fill: parent + anchors.leftMargin: 10 + anchors.rightMargin: 6 + spacing: 10 + + Text { + Layout.fillWidth: true + text: row.modelData.title + elide: Text.ElideRight + color: row.current ? Theme.text : Theme.muted + font.family: Theme.displayFont + font.pixelSize: 12 + } + + // Only useful when the list spans vaults. + MicroText { + visible: root.activeVault === "" + text: row.modelData.vault.toUpperCase() + } + } + + MouseArea { + anchors.fill: parent + onClicked: root.pick(row.index) + } } + } - // Placeholder: TextInput has none of its own, and the - // PAM prompt ("Password:", "PIN:") is the only label - // this field gets. - Text { - anchors.verticalCenter: parent.verticalCenter - visible: responseInput.text.length === 0 - text: root.inputPrompt - color: Theme.disabled - font: responseInput.font - } + RowLayout { + Layout.fillWidth: true + spacing: 14 + + MicroText { text: "↑↓ SELECT" } + MicroText { text: "ENTER FILL" } + MicroText { text: "TAB VAULT" } + MicroText { text: "ESC BACK" } } } } - // ---- pam_info / pam_error ---- - Text { - Layout.fillWidth: true - visible: root.supplementaryMessage !== "" - wrapMode: Text.Wrap - text: root.supplementaryMessage - color: root.supplementaryIsError ? Theme.hot : Theme.muted - font.family: Theme.microFont - font.pixelSize: 9 - font.letterSpacing: 0.7 - } - - // ---- key hints ---- - RowLayout { - Layout.fillWidth: true - spacing: 14 - - MicroText { text: "ENTER AUTHENTICATE" } - MicroText { text: "ESC CANCEL" } - Item { Layout.fillWidth: true } - MicroText { - text: root.responseVisible ? "ECHO ON" : "" - color: Theme.hot - } + MouseArea { + width: parent.width + height: vaultPanel.headerHeight + cursorShape: Qt.PointingHandCursor + onClicked: root.pickerOpen ? root.closePicker() : root.openPicker() } } } diff --git a/dotfiles/quickshell/HyprChrome/Widgets/Polkit/ProtonPass.qml b/dotfiles/quickshell/HyprChrome/Widgets/Polkit/ProtonPass.qml new file mode 100644 index 0000000..00e9a81 --- /dev/null +++ b/dotfiles/quickshell/HyprChrome/Widgets/Polkit/ProtonPass.qml @@ -0,0 +1,176 @@ +pragma ComponentBehavior: Bound + +import QtQuick +import Quickshell +import Quickshell.Io + +// Proton Pass logins for the polkit and askpass prompts, via pass-cli. +// +// Listing never touches a secret: `item list` without --show-secrets returns +// ids and titles only. A password is fetched on its own, for one item, after +// the user picks it — and read through a SplitParser rather than a +// StdioCollector, which would keep it in its `text` property afterwards. +// +// `item list` refuses to run without a vault, so "all vaults" is one call per +// vault. Each takes ~0.8s, hence run in parallel by a single shell script. +QtObject { + id: root + + // {shareId, id, title, vault}, unsorted — the dialog orders and groups them. + property var entries: [] + // Why the list is empty or incomplete; "" when it is fine. + property string error: "" + property string fetchError: "" + + readonly property bool loading: vaults.running || items.running + readonly property bool fetching: fetcher.running + + // Shown inside the picker. + readonly property string listStatus: root.loading + ? (root.entries.length === 0 ? "LOADING VAULTS…" : "REFRESHING…") + : root.error + // Shown under the field, picker open or not. + readonly property string fetchStatus: root.fetching ? "FETCHING PASSWORD…" : root.fetchError + + // Bumped per request; a fetch that lands after it changed is dropped, so a + // slow fetch cannot fill a password into the NEXT request's field. + property int generation: 0 + property int fetchGeneration: -1 + property bool fetchGotLine: false + property var vaultNames: ({}) + + signal fetched(string secret) + + function refresh() { + if (root.loading) + return; + root.error = ""; + vaults.running = true; + } + + function invalidate() { + root.generation++; + root.fetchError = ""; + } + + function fetch(entry) { + if (!entry || root.fetching) + return; + root.fetchError = ""; + root.fetchGeneration = root.generation; + root.fetchGotLine = false; + fetcher.command = ["pass-cli", "item", "view", "--share-id", entry.shareId, + "--item-id", entry.id, "--field", "password", "--output", "human"]; + fetcher.running = true; + } + + function describe(output) { + const text = output.replace(/\x1b\[[0-9;]*m/g, ""); + if (/not found/.test(text)) + return "PASS-CLI NOT INSTALLED"; + if (/authenticated client|no session/.test(text)) + return "PASS-CLI LOGGED OUT — RUN pass-cli login"; + const lines = text.trim().split("\n"); + return lines[lines.length - 1].toUpperCase(); + } + + // Prints the vault JSON or `ERR `: one stream, so success and + // failure need no ordering between exit code and stdout. + readonly property var vaults: Process { + id: vaults + + command: ["sh", "-c", + "out=$(pass-cli vault list --output json 2>&1) && printf '%s' \"$out\" || printf 'ERR %s' \"$out\""] + + stdout: StdioCollector { + onStreamFinished: { + const body = this.text; + if (body.startsWith("ERR ")) { + root.error = root.describe(body.slice(4)); + return; + } + + let list; + try { + list = JSON.parse(body).vaults || []; + } catch (e) { + root.error = "UNREADABLE VAULT LIST"; + return; + } + const names = {}; + for (const v of list) + names[v.share_id] = v.name; + root.vaultNames = names; + if (list.length === 0) { + root.entries = []; + root.error = "NO VAULTS"; + return; + } + items.command = ["sh", "-c", items.script, "sh"].concat(list.map(v => v.share_id)); + items.running = true; + } + } + } + + // One `item list` per vault in parallel, each to its own file, then + // printed back in order under an `@@` line — concurrent writers + // on one pipe would interleave. + // + // No --filter-type: it takes ONE type, and the `darman@` machine + // logins scripts/deploy reads are `custom` items, not `login`. + readonly property var items: Process { + id: items + + readonly property string script: "d=$(mktemp -d \"${XDG_RUNTIME_DIR:-/tmp}/qs-pass.XXXXXX\") || exit 1;" + + " trap 'rm -rf \"$d\"' EXIT; i=0;" + + " for s; do i=$((i+1)); pass-cli item list --share-id \"$s\"" + + " --filter-state active --output json > \"$d/$i\" 2>/dev/null & done; wait; i=0;" + + " for s; do i=$((i+1)); printf '\\n@@%s\\n' \"$s\"; cat \"$d/$i\"; done" + + stdout: StdioCollector { + onStreamFinished: { + const found = []; + let failed = 0; + for (const chunk of this.text.split(/^@@/m)) { + const nl = chunk.indexOf("\n"); + const share = nl < 0 ? "" : chunk.slice(0, nl).trim(); + if (share === "") + continue; + try { + for (const it of JSON.parse(chunk.slice(nl + 1)).items || []) + if (it.item_type === "login" || it.item_type === "custom") + found.push({ shareId: share, id: it.id, title: it.title, vault: root.vaultNames[share] || "" }); + } catch (e) { + failed++; + } + } + root.entries = found; + root.error = failed === 0 ? (found.length === 0 ? "NO LOGINS IN ANY VAULT" : "") + : failed + " VAULT" + (failed === 1 ? "" : "S") + " FAILED TO LIST"; + } + } + } + + readonly property var fetcher: Process { + id: fetcher + + stdout: SplitParser { + splitMarker: "\n" + onRead: line => { + if (root.fetchGotLine) + return; + root.fetchGotLine = true; + if (root.fetchGeneration !== root.generation) + return; + root.fetchError = line === "" ? "THAT ITEM HAS NO PASSWORD" : ""; + if (line !== "") + root.fetched(line); + } + } + + onExited: (exitCode, exitStatus) => { + if (!root.fetchGotLine && root.fetchGeneration === root.generation) + root.fetchError = exitCode === 0 ? "THAT ITEM HAS NO PASSWORD" : "COULD NOT READ THAT ITEM"; + } + } +} diff --git a/dotfiles/quickshell/tests/PolkitPromptVaultHeadless.qml b/dotfiles/quickshell/tests/PolkitPromptVaultHeadless.qml new file mode 100644 index 0000000..92a3b0b --- /dev/null +++ b/dotfiles/quickshell/tests/PolkitPromptVaultHeadless.qml @@ -0,0 +1,49 @@ +import QtQuick +import qs.HyprChrome.Widgets.Polkit + +// Offscreen render of the polkit prompt with the Proton Pass panel expanded, +// more vaults than fit (Work, selected, sits in the open overflow menu), the +// password revealed and a failed fetch under the +// field. Credentials are deliberately out of order, to show the title sort. +// +// ./tools/quickshell-preview/render.sh \ +// tests/PolkitPromptVaultHeadless.qml \ +// .artifacts/quickshell-preview/polkit-prompt-vault.png 560 560 +PolkitPromptContent { + width: 520 + + message: "Authentication is required to install or remove software" + actionId: "org.freedesktop.packagekit.package-install" + showIcon: false + + identities: [{ id: "1000", displayName: "darman", isGroup: false }] + + responseRequired: true + inputPrompt: "Password:" + response: "hunter2" + revealed: true + + credentialsEnabled: true + credentials: [ + { title: "router admin", vault: "HomeLab" }, + { title: "proton.me", vault: "Personal" }, + { title: "darman@terra", vault: "HomeLab" }, + { title: "netcup", vault: "Work" }, + { title: "Darman@mars", vault: "HomeLab" }, + { title: "github.com", vault: "Personal" }, + { title: "root@terra", vault: "HomeLab" }, + { title: "grandma wifi", vault: "Family" }, + { title: "old forum", vault: "Archive" }, + { title: "billing portal", vault: "Clients" }, + { title: "ci deploy key", vault: "Shared Infrastructure" }, + { title: "vpn", vault: "Work" } + ] + fetchStatus: "THAT ITEM HAS NO PASSWORD" + + Component.onCompleted: { + openPicker(); + pickerIndex = 1; + vaultFilter = "Work"; + overflowMenuOpen = true; + } +}