Skip to content

Commit

Permalink
Excluding containers from sync with RegExp
Browse files Browse the repository at this point in the history
  • Loading branch information
stoically committed Dec 5, 2021
1 parent e3772b2 commit 1da25b2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/_locales
Submodule _locales updated 1 files
+6 −0 en/messages.json
13 changes: 13 additions & 0 deletions src/js/background/backgroundLogic.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const backgroundLogic = {
}
}
});

backgroundLogic.setDefaultOptions();
},

async getExtensionInfo() {
Expand Down Expand Up @@ -362,6 +364,17 @@ const backgroundLogic = {
cookieStoreId(userContextId) {
if(userContextId === 0) return "firefox-default";
return `firefox-container-${userContextId}`;
},

async setDefaultOptions() {
// Default container sync exclude regexp to "^tmp\d+$" to prevent
// https://github.com/mozilla/multi-account-containers/issues/1675
// https://github.com/stoically/temporary-containers/issues/371
// for future users of the MAC + TC combination.
const { syncExcludeRegExp } = await browser.storage.local.get("syncExcludeRegExp");
if (syncExcludeRegExp === undefined) {
browser.storage.local.set({syncExcludeRegExp: "^tmp\\d+$"});
}
}
};

Expand Down
7 changes: 7 additions & 0 deletions src/js/background/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,16 @@ const sync = {
await sync.checkForListenersMaybeAdd();

async function updateSyncIdentities() {
const { syncExcludeRegExp } = await browser.storage.local.get("syncExcludeRegExp");
const excludeRegExp = new RegExp(syncExcludeRegExp, 'i');
const identities = await browser.contextualIdentities.query({});

for (const identity of identities) {
// skip excluded identities
if (identity.name.match(excludeRegExp)) {
continue;
}

delete identity.colorCode;
delete identity.iconUrl;
identity.macAddonUUID = await identityState.lookupMACaddonUUID(identity.cookieStoreId);
Expand Down
7 changes: 7 additions & 0 deletions src/js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ async function setupOptions() {
const hasPermission = await browser.permissions.contains({permissions: ["bookmarks"]});
const { syncEnabled } = await browser.storage.local.get("syncEnabled");
const { replaceTabEnabled } = await browser.storage.local.get("replaceTabEnabled");
const { syncExcludeRegExp } = await browser.storage.local.get("syncExcludeRegExp");
if (hasPermission) {
document.querySelector("#bookmarksPermissions").checked = true;
}
document.querySelector("#syncCheck").checked = !!syncEnabled;
document.querySelector("#replaceTabCheck").checked = !!replaceTabEnabled;
document.querySelector("#syncExcludeRegExp").value = syncExcludeRegExp || "";
setupContainerShortcutSelects();
}

Expand Down Expand Up @@ -78,11 +80,16 @@ function resetOnboarding() {
browser.storage.local.set({"onboarding-stage": 0});
}

function updateSyncExcludeRegExp(event) {
browser.storage.local.set({syncExcludeRegExp: event.target.value});
}

document.addEventListener("DOMContentLoaded", setupOptions);
document.querySelector("#bookmarksPermissions").addEventListener( "change", requestPermissions);
document.querySelector("#syncCheck").addEventListener( "change", enableDisableSync);
document.querySelector("#replaceTabCheck").addEventListener( "change", enableDisableReplaceTab);
document.querySelector("button").addEventListener("click", resetOnboarding);
document.querySelector("#syncExcludeRegExp").addEventListener( "change", updateSyncExcludeRegExp);

for (let i=0; i < NUMBER_OF_KEYBOARD_SHORTCUTS; i++) {
document.querySelector("#open_container_"+i)
Expand Down
3 changes: 3 additions & 0 deletions src/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ <h3 data-i18n-message-id="keyboardShortCuts"></h3>
<h3 data-i18n-message-id="onboarding"></h3>
<button data-i18n-message-id="resetOnboardingPanels"></button>
<p><em data-i18n-message-id="onboardingToggle"></em></p>
<h3 data-i18n-message-id="syncExclude"></h3>
<input id="syncExcludeRegExp">
<p><em data-i18n-message-id="syncExcludeDescription"></em></p>
</form>
<script src="js/options.js"></script>
</body>
Expand Down

0 comments on commit 1da25b2

Please sign in to comment.