From bf31fa9196d5051aa00f3f6104574f403fa78378 Mon Sep 17 00:00:00 2001 From: stoically Date: Thu, 23 Jun 2022 00:28:54 +0200 Subject: [PATCH] Excluding containers from sync with RegExp --- src/css/options.css | 10 ++++++++++ src/js/background/backgroundLogic.js | 12 ++++++++++++ src/js/background/sync.js | 7 +++++++ src/js/options.js | 7 +++++++ src/options.html | 9 +++++++++ 5 files changed, 45 insertions(+) diff --git a/src/css/options.css b/src/css/options.css index 5a6baf0f..99036f65 100644 --- a/src/css/options.css +++ b/src/css/options.css @@ -37,6 +37,16 @@ form { margin-block: 4px 8px; } +.settings-group-column { + display: flex; + flex-direction: column; +} + +.settings-group-column label, +.settings-group-column p { + margin-block: 4px 8px; +} + input[type="checkbox"] { margin-inline: 0 8px; margin-block: 1px auto; diff --git a/src/js/background/backgroundLogic.js b/src/js/background/backgroundLogic.js index 1050d400..a4d42d89 100644 --- a/src/js/background/backgroundLogic.js +++ b/src/js/background/backgroundLogic.js @@ -27,6 +27,7 @@ const backgroundLogic = { browser.permissions.onAdded.addListener(permissions => this.resetPermissions(permissions)); browser.permissions.onRemoved.addListener(permissions => this.resetPermissions(permissions)); + backgroundLogic.setSyncExclusion(); }, resetPermissions(permissions) { @@ -399,6 +400,17 @@ const backgroundLogic = { cookieStoreId(userContextId) { if(userContextId === 0) return "firefox-default"; return `firefox-container-${userContextId}`; + }, + + async setSyncExclusion() { + // 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+$"}); + } } }; diff --git a/src/js/background/sync.js b/src/js/background/sync.js index 6dfb6294..fc6d8756 100644 --- a/src/js/background/sync.js +++ b/src/js/background/sync.js @@ -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); diff --git a/src/js/options.js b/src/js/options.js index 7679e2b3..d3daf541 100644 --- a/src/js/options.js +++ b/src/js/options.js @@ -63,10 +63,12 @@ async function setupOptions() { const { syncEnabled } = await browser.storage.local.get("syncEnabled"); const { replaceTabEnabled } = await browser.storage.local.get("replaceTabEnabled"); const { currentThemeId } = await browser.storage.local.get("currentThemeId"); + const { syncExcludeRegExp } = await browser.storage.local.get("syncExcludeRegExp"); document.querySelector("#syncCheck").checked = !!syncEnabled; document.querySelector("#replaceTabCheck").checked = !!replaceTabEnabled; document.querySelector("#changeTheme").selectedIndex = currentThemeId; + document.querySelector("#syncExcludeRegExp").value = syncExcludeRegExp || ""; setupContainerShortcutSelects(); } @@ -120,10 +122,15 @@ async function resetPermissionsUi() { browser.permissions.onAdded.addListener(resetPermissionsUi); browser.permissions.onRemoved.addListener(resetPermissionsUi); +function updateSyncExcludeRegExp(event) { + browser.storage.local.set({syncExcludeRegExp: event.target.value}); +} + document.addEventListener("DOMContentLoaded", setupOptions); document.querySelector("#syncCheck").addEventListener( "change", enableDisableSync); document.querySelector("#replaceTabCheck").addEventListener( "change", enableDisableReplaceTab); document.querySelector("#changeTheme").addEventListener( "change", changeTheme); +document.querySelector("#syncExcludeRegExp").addEventListener( "change", updateSyncExcludeRegExp); maybeShowPermissionsWarningIcon(); for (let i=0; i < NUMBER_OF_KEYBOARD_SHORTCUTS; i++) { diff --git a/src/options.html b/src/options.html index c8b8ff9a..efd15f52 100644 --- a/src/options.html +++ b/src/options.html @@ -48,6 +48,15 @@

+
+ + +

+