Skip to content

Commit

Permalink
Merge pull request #2405 from keepassxreboot/fix/show_notification_fo…
Browse files Browse the repository at this point in the history
…r_non_connected_db

Show error notification when database is not connected
  • Loading branch information
varjolintu authored Dec 11, 2024
2 parents c697bca + 2d06cc6 commit aba4ffc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
6 changes: 5 additions & 1 deletion keepassxc-browser/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,11 @@
},
"errorNotConnected": {
"message": "Not connected to KeePassXC.",
"description": "Error notification shown when not connected to KeePassXC"
"description": "Error notification shown when not connected to KeePassXC."
},
"errorCurrentDatabaseNotConnected": {
"message": "Current database is not connected.",
"description": "Error notification shown when current database is not connected during action."
},
"passwordGeneratorErrorTooLong": {
"message": "Error: The generated password is longer than the allowed length!",
Expand Down
16 changes: 13 additions & 3 deletions keepassxc-browser/content/fill.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ kpxcFill.fillInFromActiveElement = async function(passOnly = false) {
await kpxc.receiveCredentialsIfNecessary();
if (kpxc.credentials.length === 0) {
logDebug(`Error: Credential list is empty for: ${document.location.origin}`);
kpxcUI.createNotification('error', `${tr('credentialsNoLoginsFound')} ${document.location.origin}`);
showErrorNotification(`${tr('credentialsNoLoginsFound')} ${document.location.origin}`);
return;
}

Expand Down Expand Up @@ -119,7 +119,7 @@ kpxcFill.fillFromTOTP = async function(target) {
const credentialList = await kpxc.updateTOTPList();

if (!credentialList || credentialList?.length === 0) {
kpxcUI.createNotification('warning', tr('credentialsNoTOTPFound'));
showErrorNotification(tr('credentialsNoTOTPFound'), 'warning');
return;
}

Expand Down Expand Up @@ -197,7 +197,7 @@ kpxcFill.fillFromUsernameIcon = async function(combination) {
await kpxc.receiveCredentialsIfNecessary();
if (kpxc.credentials.length === 0) {
logDebug(`Error: Credential list is empty for: ${document.location.origin}`);
kpxcUI.createNotification('error', `${tr('credentialsNoLoginsFound')} ${document.location.origin}`);
showErrorNotification(`${tr('credentialsNoLoginsFound')} ${document.location.origin}`);
return;
} else if (kpxc.credentials.length > 1 && kpxc.settings.autoCompleteUsernames) {
kpxcUserAutocomplete.showList(combination.username || combination.password);
Expand Down Expand Up @@ -352,3 +352,13 @@ const passwordFillIsAllowed = function(elem) {

return elem?.getLowerCaseAttribute('type') === 'password';
};

// Show a specific error notification if current database is not connected
const showErrorNotification = async function(errorMessage, notificationType = 'error') {
const connectedDatabase = await sendMessage('get_connected_database');
if (!connectedDatabase?.identifier) {
kpxcUI.createNotification('error', tr('errorCurrentDatabaseNotConnected'));
} else {
kpxcUI.createNotification(notificationType, errorMessage);
}
};

0 comments on commit aba4ffc

Please sign in to comment.