From 12d49fab4e3d33631f5152c400f991b664ca5616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Mon, 21 Sep 2020 18:05:00 +0200 Subject: [PATCH] Fix a bug: wait for promise before displaying message for clipboard pasted password --- chrome_addon/popup/popup.js | 12 ++++++++---- firefox_webextension/popup/popup.js | 18 ++++++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/chrome_addon/popup/popup.js b/chrome_addon/popup/popup.js index 8dd6242..6fdda46 100644 --- a/chrome_addon/popup/popup.js +++ b/chrome_addon/popup/popup.js @@ -69,14 +69,18 @@ function _query_tabs_get_password(tabs) function(arg) { debug("Response to setPassword " + arg); - if (arg == "" || force_copy) + if (arg === "" || force_copy) { - navigator.clipboard.writeText(response.password); - notify("Password pasted into clipboard", ""); + navigator.clipboard.writeText(response.password).then(function() { + notify("Password pasted into clipboard", ""); + window.close(); + }); } else + { notify("Password filled", ""); - window.close(); + window.close(); + } } ); } diff --git a/firefox_webextension/popup/popup.js b/firefox_webextension/popup/popup.js index ec09312..6fdda46 100644 --- a/firefox_webextension/popup/popup.js +++ b/firefox_webextension/popup/popup.js @@ -21,6 +21,8 @@ var username_filled = false function _query_tabs_get_password(tabs) { + var force_copy = false; + if (tabs.length <= 0) return; var username = document.getElementById("gPassUsername").value; @@ -32,6 +34,10 @@ function _query_tabs_get_password(tabs) document.getElementById("gPassMasterKey").value = ""; var do_submit = !mkey.startsWith("@_") && username_filled; + + if (mkey.startsWith("@_")) + force_copy = true; + if (mkey.startsWith("@@") || mkey.startsWith("@_")) mkey = mkey.substring(2); @@ -63,14 +69,18 @@ function _query_tabs_get_password(tabs) function(arg) { debug("Response to setPassword " + arg); - if (arg == "") + if (arg === "" || force_copy) { - navigator.clipboard.writeText(response.password); - notify("Password pasted into clipboard", ""); + navigator.clipboard.writeText(response.password).then(function() { + notify("Password pasted into clipboard", ""); + window.close(); + }); } else + { notify("Password filled", ""); - window.close(); + window.close(); + } } ); }