diff --git a/bitwarden/lua/bitwarden/init.lua b/bitwarden/lua/bitwarden/init.lua index adcafde..33b2b31 100644 --- a/bitwarden/lua/bitwarden/init.lua +++ b/bitwarden/lua/bitwarden/init.lua @@ -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+). diff --git a/keepassxc/lua/keepassxc/init.lua b/keepassxc/lua/keepassxc/init.lua index 8d966b7..4518b14 100644 --- a/keepassxc/lua/keepassxc/init.lua +++ b/keepassxc/lua/keepassxc/init.lua @@ -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) diff --git a/passwords/lua/passwords/init.lua b/passwords/lua/passwords/init.lua index 8c7e1f2..0a3c619 100644 --- a/passwords/lua/passwords/init.lua +++ b/passwords/lua/passwords/init.lua @@ -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) @@ -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 @@ -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 @@ -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 diff --git a/passwords/test/passwords_spec.lua b/passwords/test/passwords_spec.lua index ddb7e2b..94ac1fc 100644 --- a/passwords/test/passwords_spec.lua +++ b/passwords/test/passwords_spec.lua @@ -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") + 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")