Skip to content

Commit

Permalink
Allow hiding badge counter
Browse files Browse the repository at this point in the history
  • Loading branch information
maximbaz committed Sep 9, 2020
1 parent 29a7043 commit c92725c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ The list of available options:
| --------------------------------------------------------------- | ------------------------------------------------------------- |
| Automatically submit forms after filling (aka `autoSubmit`) | Make Browserpass automatically submit the login form for you |
| Enable support for OTP tokens (aka `enableOTP`) | Generate TOTP codes if a TOTP seed is found in the pass entry |
| Hide badge counter on the toolbar icon (aka `hideBadge`) | Do not show badge with number of matching password entries |
| Default username (aka `username`) | Username to use when it's not defined in the password file |
| Custom gpg binary (aka `gpgPath`) | Path to a custom `gpg` binary to use |
| Custom store locations | List of password stores to use |
Expand All @@ -234,6 +235,7 @@ Browserpass allows configuring certain settings in different places places using
- `autoSubmit`
1. Options defined in `.browserpass.json` file located in the root of a password store:
- `autoSubmit`
- `hideBadge`
- `enableOTP`
- `gpgPath`
- `username`
Expand All @@ -243,6 +245,7 @@ Browserpass allows configuring certain settings in different places places using
1. Options defined in browser extension options:
- Automatically submit forms after filling (aka `autoSubmit`)
- Enable support for OTP tokens (aka `enableOTP`)
- Hide badge counter on the toolbar icon (aka `hideBadge`)
- Default username (aka `username`)
- Custom gpg binary (aka `gpgPath`)
- Custom store locations
Expand Down
19 changes: 14 additions & 5 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var defaultSettings = {
username: null,
theme: "dark",
enableOTP: false,
hideBadge: false,
};

var authListeners = {};
Expand Down Expand Up @@ -115,15 +116,19 @@ async function updateMatchingPasswordsCount(tabId, forceRefresh = false) {
if (forceRefresh || Date.now() > badgeCache.expires) {
badgeCache.isRefreshing = true;

let files = [];
let settings = await getFullSettings();
let response = await hostAction(settings, "list");
if (response.status != "ok") {
throw new Error(JSON.stringify(response));
if (!settings.hideBadge) {
let response = await hostAction(settings, "list");
if (response.status != "ok") {
throw new Error(JSON.stringify(response));
}
files = response.data.files;
}

const CACHE_TTL_MS = 60 * 1000;
badgeCache = {
files: response.data.files,
files: files,
settings: settings,
expires: Date.now() + CACHE_TTL_MS,
isRefreshing: false,
Expand All @@ -137,7 +142,7 @@ async function updateMatchingPasswordsCount(tabId, forceRefresh = false) {
throw new Error(`Unable to determine domain of the tab with id ${tabId}`);
}

// Compule badge counter
// Compute badge counter
const files = helpers.ignoreFiles(badgeCache.files, badgeCache.settings);
const logins = helpers.prepareLogins(files, badgeCache.settings);
const matchedPasswordsCount = logins.reduce(
Expand All @@ -151,6 +156,7 @@ async function updateMatchingPasswordsCount(tabId, forceRefresh = false) {
tabId: tabId,
});
} catch (e) {
badgeCache.isRefreshing = false;
console.log(e);
}
}
Expand Down Expand Up @@ -1092,6 +1098,9 @@ async function saveSettings(settings) {
localStorage.setItem(key, JSON.stringify(settingsToSave[key]));
}
}

// refresh in case user has just toggled showing badge counter
updateMatchingPasswordsCount(settings.tab.id, true);
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/options/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function view(ctl, params) {
nodes.push(
createCheckbox.call(this, "enableOTP", "Enable support for OTP tokens (not recommended)")
);
nodes.push(createCheckbox.call(this, "hideBadge", "Hide badge counter on the toolbar icon"));
nodes.push(createInput.call(this, "username", "Default username", "john.smith"));
nodes.push(createInput.call(this, "gpgPath", "Custom gpg binary", "/path/to/gpg"));

Expand Down

0 comments on commit c92725c

Please sign in to comment.