Container locking - simplified test code

This commit is contained in:
Francis McKenzie 2019-12-30 22:16:34 +01:00
parent 0bf47ad806
commit 6f55671f8f
2 changed files with 15 additions and 23 deletions

View file

@ -371,6 +371,16 @@ const Logic = {
}); });
}, },
lockOrUnlockContainer(userContextId, isLocked) {
return browser.runtime.sendMessage({
method: "lockOrUnlockContainer",
message: {
userContextId: userContextId,
isLocked: !!isLocked
}
});
},
generateIdentityName() { generateIdentityName() {
const defaultName = "Container #"; const defaultName = "Container #";
const ids = []; const ids = [];
@ -1041,16 +1051,10 @@ Logic.registerPanel(P_CONTAINER_EDIT, {
Logic.addEnterHandler(lockElement, async () => { Logic.addEnterHandler(lockElement, async () => {
try { try {
await browser.runtime.sendMessage({ await Logic.lockOrUnlockContainer(Logic.currentUserContextId(), !isLocked);
method: "lockOrUnlockContainer",
message: {
userContextId: Logic.currentUserContextId(),
isLocked: !isLocked
}
});
this.showAssignedContainers(assignments, !isLocked); this.showAssignedContainers(assignments, !isLocked);
} catch (e) { } catch (e) {
throw new Error("Failed to lock/unlock. ", e.message); throw new Error("Failed to lock/unlock container: " + e.message);
} }
}); });
/* Container locking end */ /* Container locking end */

View file

@ -53,21 +53,9 @@ module.exports = {
// https://github.com/mozilla/multi-account-containers/issues/847 // https://github.com/mozilla/multi-account-containers/issues/847
async setContainerIsLocked(cookieStoreId, isLocked) { async setContainerIsLocked(cookieStoreId, isLocked) {
const identityStateKey = this.getIdentityStateContainerStoreKey(cookieStoreId); const Logic = popup.dom.window.eval("Logic");
const identityState = await background.browser.storage.local.get([identityStateKey]) || {}; const userContextId = Logic.userContextId(cookieStoreId);
if (isLocked) { await Logic.lockOrUnlockContainer(userContextId, isLocked);
identityState.isLocked = "locked";
} else {
delete identityState.isLocked;
}
// Must have valid 'hiddenTabs', otherwise backgroundLogic.showTabs() throws error
if (!identityState.hiddenTabs) { identityState.hiddenTabs = []; }
await background.browser.storage.local.set({[identityStateKey]: identityState});
},
getIdentityStateContainerStoreKey(cookieStoreId) {
const storagePrefix = "identitiesState@@_";
return `${storagePrefix}${cookieStoreId}`;
} }
} }
}; };