Skip to content

Commit

Permalink
Merge pull request #2231 from stoically/stoically/feat/sync-exclude-r…
Browse files Browse the repository at this point in the history
…egexp

Excluding containers from sync with RegExp
  • Loading branch information
dannycolin authored Jun 23, 2022
2 parents 66b9000 + bf31fa9 commit a399f84
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/css/options.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions src/js/background/backgroundLogic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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+$"});
}
}
};

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 @@ -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();
}

Expand Down Expand Up @@ -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++) {
Expand Down
9 changes: 9 additions & 0 deletions src/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ <h3 data-i18n-message-id="firefoxAccountsSync"></h3>
</label>
<p><em data-i18n-message-id="enableSyncDescription"></em></p>
</div>
<div class="settings-group-column">
<label for="syncExcludeRegExp">
<span class="bold" data-i18n-message-id="syncExclude"></span>
</label>
<input id="syncExcludeRegExp"
data-i18n-attribute="placeholder"
data-i18n-attribute-message-id="syncExcludePlaceholder">
<p><em data-i18n-message-id="syncExcludeDescription"></em></p>
</div>

<h3 data-i18n-message-id="tabBehavior"></h3>

Expand Down

0 comments on commit a399f84

Please sign in to comment.