From 0aceab17ad5b06ab7ffe8cd380dce9ffafd0b9f3 Mon Sep 17 00:00:00 2001 From: varjolintu Date: Thu, 12 Apr 2018 11:24:11 +0300 Subject: [PATCH] Fix showing credential update popup --- keepassxc-browser/background/browserAction.js | 14 +++++++------- keepassxc-browser/background/init.js | 7 ++++++- keepassxc-browser/background/keepass.js | 1 + keepassxc-browser/options/options.js | 6 +++--- keepassxc-browser/popups/popup_remember.js | 5 +++-- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/keepassxc-browser/background/browserAction.js b/keepassxc-browser/background/browserAction.js index c728f6d..3d0f486 100755 --- a/keepassxc-browser/background/browserAction.js +++ b/keepassxc-browser/background/browserAction.js @@ -8,7 +8,7 @@ const BLINK_TIMEOUT_REDIRECT_COUNT_DEFAULT = 1; browserAction.show = function(callback, tab) { let data = {}; - if (!page.tabs[tab.id] || page.tabs[tab.id].stack.length == 0) { + if (!page.tabs[tab.id] || page.tabs[tab.id].stack.length === 0) { browserAction.showDefault(callback, tab); return; } @@ -36,7 +36,7 @@ browserAction.update = function(interval) { let data = page.tabs[page.currentTabId].stack[page.tabs[page.currentTabId].stack.length - 1]; - if (typeof data.visibleForMilliSeconds !== 'undefined') { + if (data.visibleForMilliSeconds !== undefined) { if (data.visibleForMilliSeconds <= 0) { browserAction.stackPop(page.currentTabId); browserAction.show(null, {'id': page.currentTabId}); @@ -87,7 +87,7 @@ browserAction.showDefault = function(callback, tab) { }); }; -browserAction.stackAdd = function(callback, tab, icon, popup, level, push, visibleForMilliSeconds, visibleForPageUpdates, redirectOffset, dontShow) { +browserAction.stackAdd = function(callback, tab, icon, popup, level, push, visibleForMilliSeconds, visibleForPageUpdates, redirectOffset, dontShow) { const id = tab.id || page.currentTabId; if (!level) { @@ -103,15 +103,15 @@ browserAction.stackAdd = function(callback, tab, icon, popup, level, push, visib stackData.popup = popup; } - if (visibleForMilliSeconds) { + if (visibleForMilliSeconds !== undefined) { stackData.visibleForMilliSeconds = visibleForMilliSeconds; } - if (visibleForPageUpdates) { + if (visibleForPageUpdates !== undefined) { stackData.visibleForPageUpdates = visibleForPageUpdates; } - if (redirectOffset) { + if (redirectOffset !== undefined) { stackData.redirectOffset = redirectOffset; } @@ -181,7 +181,7 @@ browserAction.removeRememberPopup = function(callback, tab, removeImmediately) { return; } - if( page.tabs[tab.id].stack.length == 0) { + if (page.tabs[tab.id].stack.length === 0) { page.clearCredentials(tab.id); return; } diff --git a/keepassxc-browser/background/init.js b/keepassxc-browser/background/init.js index ce7fed7..0e015ce 100644 --- a/keepassxc-browser/background/init.js +++ b/keepassxc-browser/background/init.js @@ -16,7 +16,6 @@ keepass.migrateKeyRing().then(() => { // Milliseconds for intervall (e.g. to update browserAction) const _interval = 250; - /** * Generate information structure for created tab and invoke all needed * functions if tab is created in foreground @@ -71,7 +70,13 @@ browser.tabs.onActivated.addListener((activeInfo) => { * @param {object} changeInfo */ browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { + // If the tab URL has changed (e.g. logged in) clear credentials + if (changeInfo.url) { + page.clearLogins(tabId); + } + if (changeInfo.status === 'complete') { + browserAction.showDefault(null, tab); kpxcEvent.invoke(browserAction.removeRememberPopup, null, tabId, []); } }); diff --git a/keepassxc-browser/background/keepass.js b/keepassxc-browser/background/keepass.js index 0d0764a..698bb36 100755 --- a/keepassxc-browser/background/keepass.js +++ b/keepassxc-browser/background/keepass.js @@ -185,6 +185,7 @@ keepass.updateCredentials = function(callback, tab, entryId, username, password, } else if (response.error && response.errorCode) { keepass.handleError(tab, response.errorCode, response.error); + callback('error'); } else { browserAction.showDefault(null, tab); diff --git a/keepassxc-browser/options/options.js b/keepassxc-browser/options/options.js index e0fab0c..19bfbf2 100644 --- a/keepassxc-browser/options/options.js +++ b/keepassxc-browser/options/options.js @@ -122,7 +122,7 @@ options.initGeneralSettings = function() { const blinkTimeout = $.trim($('#blinkTimeout').val()); const blinkTimeoutval = blinkTimeout !== '' ? Number(blinkTimeout) : defaultSettings.blinkTimeout; - options.settings['blinkTimeout'] = String(blinkTimeoutval); + options.settings['blinkTimeout'] = blinkTimeoutval; options.saveSetting('blinkTimeout'); }); @@ -130,7 +130,7 @@ options.initGeneralSettings = function() { const blinkMinTimeout = $.trim($('#blinkMinTimeout').val()); const blinkMinTimeoutval = blinkMinTimeout !== '' ? Number(blinkMinTimeout) : defaultSettings.redirectOffset; - options.settings['blinkMinTimeout'] = String(blinkMinTimeoutval); + options.settings['blinkMinTimeout'] = blinkMinTimeoutval; options.saveSetting('blinkMinTimeout'); }); @@ -138,7 +138,7 @@ options.initGeneralSettings = function() { const allowedRedirect = $.trim($('#allowedRedirect').val()); const allowedRedirectval = allowedRedirect !== '' ? Number(allowedRedirect) : defaultSettings.redirectAllowance; - options.settings['allowedRedirect'] = String(allowedRedirectval); + options.settings['allowedRedirect'] = allowedRedirectval; options.saveSetting('allowedRedirect'); }); }; diff --git a/keepassxc-browser/popups/popup_remember.js b/keepassxc-browser/popups/popup_remember.js index d1bb15c..13c04ae 100644 --- a/keepassxc-browser/popups/popup_remember.js +++ b/keepassxc-browser/popups/popup_remember.js @@ -108,9 +108,10 @@ function _connected_database(db) { } function _verifyResult(code) { - if (code === 'success') { - _close(); + if (code === 'error') { + showNotification('Error: Credentials cannot be saved or updated.'); } + _close(); } function _close() {