Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inter-extension communication with Cliqz #101

Merged
merged 6 commits into from Jul 19, 2018
Fix usage of conf
  • Loading branch information
sammacbeth committed Jun 28, 2018
commit d0558281ff435a853ccadcb714c4ceb932d74c2a
@@ -135,6 +135,7 @@ class ConfData {
_initProperty('setup_step', 0);
_initProperty('setup_path', 0);
_initProperty('setup_block', 1);
_initProperty('cliqz_import_state', 0);

// Complex props
_initProperty('bugs', {});
@@ -10,7 +10,7 @@ function promiseTimeout(timeout) {
function runCliqzSettingsImport(cliqz, conf) {
log('run cliqz settings importer');
const inject = new KordInjector();
inject.init();
inject.init();
// inject modules in remote cliqz extension with which we want to communicate
const privacyMigration = inject.module('privacy-migration');

@@ -43,28 +43,27 @@ function runCliqzSettingsImport(cliqz, conf) {
.map(s => s.replace(/^(http[s]?:\/\/)?(www\.)?/, ''))
.filter(s => !existingSites.has(s)));
log('add whitelisted sites', [...newSites]);

This comment has been minimized.

@zarembsky

zarembsky Jun 15, 2018
Contributor

Should be:

const site_whitelist;
newSites.forEach((s) => {
       site_whitelist.push(s);
}
conf.site_whitelist = site_whitelist;

Setter is proxied on conf, but it reacts only changes to immediate children properties.

const whitelist = conf.site_whitelist;
newSites.forEach((s) => {
conf.site_whitelist.push(s);
whitelist.push(s);
});
return privacyMigration.cleanModuleData();
conf.site_whitelist = whitelist;
privacyMigration.cleanModuleData();
return Promise.resolve();
}).then(() => {
inject.unload();
});
}

// import settings from cliqz
export function importCliqzSettings(cliqz, conf) {
const IMPORT_RUN_FLAG = 'cliqzImportState';
chrome.storage.local.get([IMPORT_RUN_FLAG], (result) => {
log(IMPORT_RUN_FLAG, result);
if (!result[IMPORT_RUN_FLAG]) {
runCliqzSettingsImport(cliqz, conf).then(() => {
log('cliqz settings import successful');
chrome.storage.local.set({ [IMPORT_RUN_FLAG]: 1 });
}, (e) => {
log('cliqz import not available at present');
console.error(e);
});
}
});
log('checking cliqz import', conf.cliqz_import_state);
if (!conf.cliqz_import_state) {
runCliqzSettingsImport(cliqz, conf).then(() => {
log('cliqz settings import successful');
conf.cliqz_import_state = 1;
}, (e) => {
log('cliqz import not available at present', e);
});
}
}
ProTip! Use n and p to navigate between commits in a pull request.