Skip to content

Commit

Permalink
move getSetting from background.js -> helpers.js
Browse files Browse the repository at this point in the history
it will have use in `detailsInterface.js`, not just `background.js`
(next patch).
  • Loading branch information
uninsane committed Nov 6, 2022
1 parent 0fd15fd commit e342264
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
23 changes: 2 additions & 21 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ async function fillFields(settings, login, fields) {
// build focus or submit request
let focusOrSubmitRequest = {
origin: new BrowserpassURL(settings.tab.url).origin,
autoSubmit: getSetting("autoSubmit", login, settings),
autoSubmit: helpers.getSetting("autoSubmit", login, settings),
filledFields: filledFields,
};

Expand Down Expand Up @@ -561,25 +561,6 @@ async function getFullSettings() {
return settings;
}

/**
* Get most relevant setting value
*
* @param string key Setting key
* @param object login Login object
* @param object settings Settings object
* @return object Setting value
*/
function getSetting(key, login, settings) {
if (typeof login.settings[key] !== "undefined") {
return login.settings[key];
}
if (typeof settings.stores[login.store.id].settings[key] !== "undefined") {
return settings.stores[login.store.id].settings[key];
}

return settings[key];
}

/**
* Deep copy an object
*
Expand Down Expand Up @@ -968,7 +949,7 @@ async function parseFields(settings, login) {
if (key === "secret" && lines.length) {
login.fields.secret = lines[0];
} else if (key === "login") {
const defaultUsername = getSetting("username", login, settings);
const defaultUsername = helpers.getSetting("username", login, settings);
login.fields[key] = defaultUsername || login.login.match(/([^\/]+)$/)[1];
} else {
delete login.fields[key];
Expand Down
20 changes: 20 additions & 0 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,32 @@ const BrowserpassURL = require("@browserpass/url");
module.exports = {
prepareLogins,
filterSortLogins,
getSetting,
ignoreFiles,
makeTOTP,
};

//----------------------------------- Function definitions ----------------------------------//

/**
* Get most relevant setting value
*
* @param string key Setting key
* @param object login Login object
* @param object settings Settings object
* @return object Setting value
*/
function getSetting(key, login, settings) {
if (typeof login.settings[key] !== "undefined") {
return login.settings[key];
}
if (typeof settings.stores[login.store.id].settings[key] !== "undefined") {
return settings.stores[login.store.id].settings[key];
}

return settings[key];
}

/**
* Get the deepest available domain component of a path
*
Expand Down

0 comments on commit e342264

Please sign in to comment.