Clean functions returning Promise

This commit is contained in:
varjolintu 2019-10-18 20:57:54 +03:00
parent 6c8742b21d
commit b20e59f2bf
3 changed files with 22 additions and 28 deletions

View file

@ -113,9 +113,9 @@ kpxcEvent.onPopStack = function(tab) {
return Promise.resolve();
};
kpxcEvent.onGetTabInformation = function(tab) {
kpxcEvent.onGetTabInformation = async function(tab) {
const id = tab.id || page.currentTabId;
return Promise.resolve(page.tabs[id]);
return page.tabs[id];
};
kpxcEvent.onGetConnectedDatabase = function() {
@ -131,7 +131,7 @@ kpxcEvent.onGetKeePassXCVersions = async function(tab) {
return { 'current': keepass.currentKeePassXC, 'latest': keepass.latestKeePassXC.version };
}
return Promise.resolve({ 'current': keepass.currentKeePassXC, 'latest': keepass.latestKeePassXC.version });
return { 'current': keepass.currentKeePassXC, 'latest': keepass.latestKeePassXC.version };
};
kpxcEvent.onCheckUpdateKeePassXC = async function() {
@ -158,11 +158,7 @@ kpxcEvent.onLoginPopup = function(tab, logins) {
};
browserAction.stackUnshift(stackData, tab.id);
if (logins.length > 0) {
page.tabs[tab.id].loginList = logins[0];
}
page.tabs[tab.id].loginList = logins;
browserAction.show(tab);
return Promise.resolve();
};
@ -204,8 +200,8 @@ kpxcEvent.pageClearLogins = function(tab, alreadyCalled) {
return Promise.resolve();
};
kpxcEvent.pageGetLoginId = function() {
return Promise.resolve(page.loginId);
kpxcEvent.pageGetLoginId = async function() {
return page.loginId;
};
kpxcEvent.pageSetLoginId = function(tab, loginId) {
@ -218,8 +214,8 @@ kpxcEvent.pageClearSubmitted = function() {
return Promise.resolve();
}
kpxcEvent.pageGetSubmitted = function() {
return Promise.resolve(page.submittedCredentials);
kpxcEvent.pageGetSubmitted = async function() {
return page.submittedCredentials;
};
kpxcEvent.pageSetSubmitted = function(tab, args = []) {
@ -228,8 +224,8 @@ kpxcEvent.pageSetSubmitted = function(tab, args = []) {
return Promise.resolve();
};
kpxcEvent.onUsernameFieldDetected = function(tab, args = []) {
page.usernameFieldDetected = args[0];
kpxcEvent.onUsernameFieldDetected = function(tab, detected) {
page.usernameFieldDetected = detected;
};
// All methods named in this object have to be declared BEFORE this!

View file

@ -53,7 +53,7 @@ kpxcAutocomplete.showList = function(inputField) {
// Save index for combination.loginId
const index = Array.prototype.indexOf.call(e.currentTarget.parentElement.childNodes, e.currentTarget);
browser.runtime.sendMessage({
action: 'page_set_login_id', args: [ index ]
action: 'page_set_login_id', args: index
});
inputField.value = this.getElementsByTagName('input')[0].value;

View file

@ -306,7 +306,7 @@ kpxcFields.getAllFields = function() {
fields.length === 1 && fields[0].getLowerCaseAttribute('type') !== 'password') {
browser.runtime.sendMessage({
action: 'username_field_detected',
args: [ true ]
args: true
});
}
@ -886,7 +886,7 @@ kpxc.initCredentialFields = async function(forceCall) {
await browser.runtime.sendMessage({
action: 'page_clear_logins',
args: [ _called.clearLogins ]
args: _called.clearLogins
});
_called.clearLogins = true;
@ -1028,7 +1028,7 @@ kpxc.prepareFieldsForCredentials = function(autoFillInForSingle) {
// Generate popup-list of usernames + descriptions
browser.runtime.sendMessage({
action: 'popup_login',
args: [ [ `${kpxc.credentials[0].login} (${kpxc.credentials[0].name})` ] ]
args: [ `${kpxc.credentials[0].login} (${kpxc.credentials[0].name})` ]
});
} else if (kpxc.credentials.length > 1 || (kpxc.credentials.length > 0 && (!kpxc.settings.autoFillSingleEntry || !autoFillInForSingle))) {
kpxc.preparePageForMultipleCredentials(kpxc.credentials);
@ -1066,7 +1066,7 @@ kpxc.preparePageForMultipleCredentials = function(credentials) {
// Generate popup-list of usernames + descriptions
browser.runtime.sendMessage({
action: 'popup_login',
args: [ usernames ]
args: usernames
});
// Initialize autocomplete for username fields
@ -1314,16 +1314,14 @@ kpxc.fillWithSpecificLogin = function(id) {
kpxc.setValueWithChange(kpxc.u, kpxc.credentials[id].login);
combination = kpxcFields.getCombination('username', kpxc.u);
browser.runtime.sendMessage({
action: 'page_set_login_id',
args: [ id ]
action: 'page_set_login_id', args: id
});
kpxc.u.focus();
}
if (kpxc.p) {
kpxc.setValueWithChange(kpxc.p, kpxc.credentials[id].password);
browser.runtime.sendMessage({
action: 'page_set_login_id',
args: [ id ]
action: 'page_set_login_id', args: id
});
combination = kpxcFields.getCombination('password', kpxc.p);
}
@ -1359,7 +1357,7 @@ kpxc.fillIn = function(combination, onlyPassword, suppressWarnings) {
if (uField && (!onlyPassword || _singleInputEnabledForPage)) {
kpxc.setValueWithChange(uField, kpxc.credentials[0].login);
browser.runtime.sendMessage({
action: 'page_set_login_id', args: [ 0 ]
action: 'page_set_login_id', args: 0
});
filledIn = true;
}
@ -1368,7 +1366,7 @@ kpxc.fillIn = function(combination, onlyPassword, suppressWarnings) {
kpxc.setValueWithChange(pField, kpxc.credentials[0].password);
pField.setAttribute('unchanged', true);
browser.runtime.sendMessage({
action: 'page_set_login_id', args: [ 0 ]
action: 'page_set_login_id', args: 0
});
filledIn = true;
}
@ -1396,7 +1394,7 @@ kpxc.fillIn = function(combination, onlyPassword, suppressWarnings) {
if (uField && (!onlyPassword || _singleInputEnabledForPage)) {
kpxc.setValueWithChange(uField, kpxc.credentials[combination.loginId].login);
browser.runtime.sendMessage({
action: 'page_set_login_id', args: [ combination.loginId ]
action: 'page_set_login_id', args: combination.loginId
});
filledIn = true;
}
@ -1405,7 +1403,7 @@ kpxc.fillIn = function(combination, onlyPassword, suppressWarnings) {
kpxc.setValueWithChange(pField, kpxc.credentials[combination.loginId].password);
pField.setAttribute('unchanged', true);
browser.runtime.sendMessage({
action: 'page_set_login_id', args: [ combination.loginId ]
action: 'page_set_login_id', args: combination.loginId
});
filledIn = true;
}
@ -1727,7 +1725,7 @@ kpxc.addToSitePreferences = async function(sites) {
browser.runtime.sendMessage({
action: 'username_field_detected',
args: [ false ]
args: false
});
};