Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bitwarden/lua/bitwarden/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function M.new(opts)
function(err) cb(nil, err) end)
end
local function ask()
progress("waiting for your master password")
progress("waiting for your master password", nil, nil, true)
rt.ui.input({ prompt = "Bitwarden master password", secret = true }, with)
end
-- The master password saved on the Plugins tab, from the OS keyring (riptide 0.4+).
Expand Down
2 changes: 1 addition & 1 deletion keepassxc/lua/keepassxc/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function M.new(opts)
end
cached = nil
local function ask()
progress("waiting for the database password")
progress("waiting for the database password", nil, nil, true)
rt.ui.input({ prompt = "KeePassXC database password", secret = true }, function(password)
if not password then
return cb(nil)
Expand Down
30 changes: 26 additions & 4 deletions passwords/lua/passwords/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ local bound = {}

-- A password manager plugin's backend: find(host, cb, progress) gives cb a
-- list of { label, saved = { addresses, names or path parts }, ... } or
-- (nil, err), and may call progress(text, n, total) as it works;
-- (nil, err), and may call progress(text, n, total, asking) as it works, with
-- asking true just before it asks for a password;
-- get(entry, cb) gives cb { username, password } or (nil, why); forget(),
-- if any, drops an unlocked session. `backend` nil removes one.
function M.register(name, backend)
Expand Down Expand Up @@ -65,13 +66,24 @@ local function status_lines(s)
return lines
end

-- Whether a float shown now would take the keyboard from a question: riptide
-- leaves a newly shown float with the keyboard while it asks something.
local function asking(s)
local mode = rt.mode()
if mode == "prompt" or mode == "yesno" then return true end
for _, row in ipairs(s.rows) do
if row.asking then return true end
end
return false
end

local function draw(s, timeout)
if status ~= s then return end
local lines = status_lines(s)
M.status = lines
if s.float then
if s.float:is_open() then s.float:update({ lines = lines, timeout = timeout }) end
elseif s.shown or timeout then
elseif (s.shown or timeout) and not asking(s) then
s.float = rt.ui.float({ title = "passwords", lines = lines, position = "top-right", width = 64, timeout = timeout })
end
end
Expand Down Expand Up @@ -137,9 +149,14 @@ local function ask_backend(s, name, host, done)
end
draw(s)
done({ name = name, entries = entries, err = err })
end, function(text, n, total)
end, function(text, n, total, asks)
if answered then return end
row.text, row.n, row.total = text, n, total
row.text, row.n, row.total, row.asking = text, n, total, asks == true
-- A float still being shown when the question opens would take its keyboard.
if row.asking and s.float then
s.float:close()
s.float = nil
end
draw(s)
end)
end
Expand Down Expand Up @@ -187,6 +204,11 @@ local function use(choice, host, what)
end)
end

-- Whether the status float is open, for the tests.
function M.status_open()
return status ~= nil and status.float ~= nil and status.float:is_open()
end

-- The open picker page, if any.
local picker

Expand Down
25 changes: 25 additions & 0 deletions passwords/test/passwords_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,31 @@ describe("passwords", function()
wait_until(function() return status():find("✓ Filled here", 1, true) end)
end)

it("shows no status float while a password manager asks for its password", function()
-- A float shown during a question takes riptide's keyboard from it.
local typed
passwords().register("one", {
find = function(_, cb, progress)
progress("waiting for your master password", nil, nil, true)
rt.ui.input({ prompt = "Master password", secret = true }, function(text)
typed = text
progress("unlocking the vault")
rt.defer(800, function() cb({ login("here", { "plugin-test.localhost" }, "ann", "pw-ann") }) end)
end)
end,
get = function(entry, cb) cb(entry.login) end,
})
passwords().register("two", fake({}, 3000))
run("password-fill")
wait(800)
assert.falsy(passwords().status_open(), "no float during the question")
keys("hunter2<Return>")
wait_until(function() return typed ~= nil end)
assert.equals("hunter2", typed)
wait_until(function() return passwords().status_open() end)
wait_field("pass", "pw-ann")
end)

it("says when no login is saved for the site", function()
passwords().register("one", fake({}))
run("password-fill")
Expand Down
Loading