Microsoft has acquired GitHub. Decentraleyes has left GitHub. Welcome to its new home!

To participate, please register, or sign in with an existing GitLab.com, Bitbucket, or GitHub account.

Past contributions on GitHub? Be sure to reclaim your Comments, Issues, and Pull Requests.

Refactor existing codebase

parent 717d20f1
......@@ -41,8 +41,7 @@ main._initializeOptions = function () {
options = optionDefaults; // Restore option defaults.
}
if (options.enforceStaging === true ||
options.blockMissing === true) {
if (options.blockMissing === true) {
// Improve coverage at the cost of website stability.
stateManager.setExtensionEnvironment('staging');
......
......@@ -30,14 +30,6 @@ messenger._handleMessageReceived = function (message, sender, sendResponse) {
topic = message.topic;
value = message.value;
if (topic === 'extension:set-environment') {
stateManager.setExtensionEnvironment(value);
sendResponse({value});
return MessageResponse.SYNCHRONOUS;
}
if (topic === 'tab:fetch-injections') {
sendResponse({'value': stateManager.tabs[value].injections});
......
......@@ -70,13 +70,19 @@ stateManager.registerInjection = function (tabIdentifier, injection) {
stateManager.setExtensionEnvironment = function (environment) {
switch (environment) {
case 'staging':
files.active = Object.assign({}, files.stable, files.staging);
break;
default:
files.active = files.stable;
}
return new Promise((resolve) => {
chrome.storage.local.get(Setting.ENFORCE_STAGING, function (items) {
if (environment === 'staging' || items.enforceStaging === true) {
files.active = Object.assign({}, files.stable, files.staging);
} else {
files.active = files.stable;
}
resolve();
});
});
};
stateManager.addDomainToWhitelist = function (domain) {
......@@ -172,6 +178,32 @@ stateManager._updateTab = function (details) {
stateManager._handleStorageChanged = function (changes) {
if (Setting.BLOCK_MISSING in changes) {
if (changes.blockMissing.newValue === true) {
stateManager.setExtensionEnvironment('staging');
} else {
stateManager.setExtensionEnvironment('stable');
}
}
if (Setting.ENFORCE_STAGING in changes) {
chrome.storage.local.get(Setting.BLOCK_MISSING, function (items) {
if (changes.enforceStaging.newValue === true) {
stateManager.setExtensionEnvironment('staging');
} else {
if (items.blockMissing === true) {
stateManager.setExtensionEnvironment('staging');
} else {
stateManager.setExtensionEnvironment('stable');
}
}
});
}
if (Setting.SHOW_ICON_BADGE in changes) {
stateManager.showIconBadge = changes.showIconBadge.newValue;
......
......@@ -205,23 +205,11 @@ options._onOptionChanged = function ({target}) {
if (optionKey === Setting.BLOCK_MISSING) {
let preferredEnvironment = 'stable';
if (optionValue === true) {
options._renderBlockMissingNotice();
preferredEnvironment = 'staging';
} else {
options._hideBlockMissingNotice();
}
let message = {
'topic': 'extension:set-environment',
'value': preferredEnvironment
};
chrome.runtime.sendMessage(message);
}
if (optionKey === Setting.DISABLE_PREFETCH) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment