From 0b80a6bd18cd55dd153752b2b31982d0ec585e4c Mon Sep 17 00:00:00 2001 From: "Ilya Ig. Petrov" Date: Tue, 28 Nov 2017 22:19:13 +0500 Subject: [PATCH] Release firefox edition separately --- .../runet-censorship-bypass/gulpfile.js | 58 ++++++++----------- .../src/extension-common/manifest.tmpl.json | 1 + .../01-chrome-proxy-settings.js | 42 ++++++++++++++ .../src/templates-data.js | 14 +++++ 4 files changed, 81 insertions(+), 34 deletions(-) create mode 100644 extensions/chromium/runet-censorship-bypass/src/extension-firefox/01-chrome-proxy-settings.js diff --git a/extensions/chromium/runet-censorship-bypass/gulpfile.js b/extensions/chromium/runet-censorship-bypass/gulpfile.js index 89f6afa..1d751a6 100644 --- a/extensions/chromium/runet-censorship-bypass/gulpfile.js +++ b/extensions/chromium/runet-censorship-bypass/gulpfile.js @@ -56,52 +56,31 @@ const contexts = require('./src/templates-data').contexts; const excFolder = (name) => [`!./src/**/${name}`, `!./src/**/${name}/**/*`]; const excluded = [ ...excFolder('test') , ...excFolder('node_modules'), ...excFolder('src') ]; -const commonWoTests = ['./src/extension-common/**/*', ...excluded]; const miniDst = './build/extension-mini'; const fullDst = './build/extension-full'; const betaDst = './build/extension-beta'; +const firefoxDst = './build/extension-firefox'; -gulp.task('_cp-common', ['clean'], function(cb) { +const commonSrc = './src/extension-common/**/*';; +const miniSrc = './src/extension-mini/**/*'; +const fullSrc = './src/extension-full/**/*'; +const firefoxSrc = './src/extension-firefox/**/*'; - let fins = 0; - const intheend = () => { - if (++fins === 2) { - cb(); - } - }; +const joinSrc = (...args) => [...args, ...excluded]; - gulp.src(commonWoTests) - //.pipe(changed(miniDst)) - .pipe(templatePlugin(contexts.mini)) - .pipe(gulp.dest(miniDst)) - .on('end', intheend); +gulp.task('_cp-mini', function(cb) { - gulp.src(commonWoTests) - //.pipe(changed(fullDst)) - .pipe(templatePlugin(contexts.full)) - .pipe(gulp.dest(fullDst)) - .on('end', intheend); - - gulp.src(commonWoTests) - //.pipe(changed(fullDst)) - .pipe(templatePlugin(contexts.beta)) - .pipe(gulp.dest(betaDst)) - .on('end', intheend); -}); - -gulp.task('_cp-mini', ['_cp-common'], function(cb) { - - gulp.src(['./src/extension-mini/**/*', ...excluded]) + gulp.src(joinSrc(commonSrc, miniSrc)) //.pipe(changed(miniDst)) .pipe(templatePlugin(contexts.mini)) .pipe(gulp.dest(miniDst)) .on('end', cb); }); -gulp.task('_cp-full', ['_cp-common'], function(cb) { +gulp.task('_cp-full', function(cb) { - gulp.src(['./src/extension-full/**/*', ...excluded]) + gulp.src(joinSrc(commonSrc, fullSrc)) //.pipe(changed(fullDst)) .pipe(templatePlugin(contexts.full)) .pipe(gulp.dest(fullDst)) @@ -109,9 +88,19 @@ gulp.task('_cp-full', ['_cp-common'], function(cb) { }); -gulp.task('_cp-beta', ['_cp-common'], function(cb) { +gulp.task('_cp-firefox', function(cb) { - gulp.src(['./src/extension-full/**/*', ...excluded]) + gulp.src(joinSrc(commonSrc, fullSrc, firefoxSrc)) + //.pipe(changed(fullDst)) + .pipe(templatePlugin(contexts.firefox)) + .pipe(gulp.dest(firefoxDst)) + .on('end', cb); + +}); + +gulp.task('_cp-beta', function(cb) { + + gulp.src(joinSrc(commonSrc, fullSrc)) //.pipe(changed(fullDst)) .pipe(templatePlugin(contexts.beta)) .pipe(gulp.dest(betaDst)) @@ -119,5 +108,6 @@ gulp.task('_cp-beta', ['_cp-common'], function(cb) { }); -gulp.task('build:all', ['_cp-mini', '_cp-full', '_cp-beta']); +gulp.task('build:all', ['_cp-mini', '_cp-full', '_cp-beta', '_cp-firefox']); gulp.task('build:beta', ['_cp-beta']); +gulp.task('build:firefox', ['_cp-firefox']); diff --git a/extensions/chromium/runet-censorship-bypass/src/extension-common/manifest.tmpl.json b/extensions/chromium/runet-censorship-bypass/src/extension-common/manifest.tmpl.json index b9d38df..6e1cb73 100644 --- a/extensions/chromium/runet-censorship-bypass/src/extension-common/manifest.tmpl.json +++ b/extensions/chromium/runet-censorship-bypass/src/extension-common/manifest.tmpl.json @@ -27,6 +27,7 @@ ${persistent} "scripts": [ "00-init-apis.js" + ${scripts_0x} , "11-error-handlers-api.js" , "12-errors-lib.js" , "13-http-lib.js" diff --git a/extensions/chromium/runet-censorship-bypass/src/extension-firefox/01-chrome-proxy-settings.js b/extensions/chromium/runet-censorship-bypass/src/extension-firefox/01-chrome-proxy-settings.js new file mode 100644 index 0000000..d892eb4 --- /dev/null +++ b/extensions/chromium/runet-censorship-bypass/src/extension-firefox/01-chrome-proxy-settings.js @@ -0,0 +1,42 @@ +'use strict'; + +{ + + if (!chrome.proxy.settings) { + + const ffxStore = window.utils.createStorage('firefox-only'); + + + chrome.proxy.settings = { + get: (_, cb) => { + + let currentSettings = ffxStore('proxySettings') || {}; + currentSettings.levelOfControl = 'controlled_by_this_extension'; // May be lie, but this field is required. + cb && cb(currentSettings); + + }, + onChange: { + addListener: () => {}, + }, + set: (details, cb) => { + + browser.proxy.unregister(); + browser.proxy.register('./default.pac.js'); + + + // browser.proxy.onProxyError.addListener((...err) => { console.log('ERROR IN PAC:', ...err) }); + + browser.runtime.sendMessage(details, {toProxyScript: true}); + ffxStore('proxySettings', details); + cb && cb(); + + }, + }; + const proxySettings = ffxStore('proxySettings'); + if (proxySettings) { + chrome.proxy.settings.set(proxySettings); + } + + } + +} diff --git a/extensions/chromium/runet-censorship-bypass/src/templates-data.js b/extensions/chromium/runet-censorship-bypass/src/templates-data.js index 59860c5..1470d19 100644 --- a/extensions/chromium/runet-censorship-bypass/src/templates-data.js +++ b/extensions/chromium/runet-censorship-bypass/src/templates-data.js @@ -28,6 +28,7 @@ exports.contexts.full = Object.assign({}, commonContext, { nameSuffixRu: '', extra_permissions, persistent: '', + scripts_0x: '', scripts_2x: ', "20-ip-to-host-api.js"', scripts_8x: ', "80-error-menu.js", "83-last-errors.js", "85-block-informer.js"', }); @@ -38,10 +39,22 @@ exports.contexts.mini = Object.assign({}, commonContext, { nameSuffixRu: ' МИНИ', extra_permissions: '', persistent: '"persistent": false,', + scripts_0x: '', scripts_2x: ', "20-for-mini-only.js"', scripts_8x: '', }); +exports.contexts.firefox = Object.assign({}, commonContext, { + versionSuffix: '', + nameSuffixEn: '', + nameSuffixRu: '', + extra_permissions, + persistent: '', + scripts_0x: ', "01-chrome-proxy-settings.js"', + scripts_2x: ', "20-ip-to-host-api.js"', + scripts_8x: ', "80-error-menu.js", "83-last-errors.js", "85-block-informer.js"', +}); + exports.contexts.beta = Object.assign({}, commonContext, { anticensorityPacUrls: [ // 'https://rebrand.ly/ac-beta-pac', @@ -53,6 +66,7 @@ exports.contexts.beta = Object.assign({}, commonContext, { nameSuffixRu: ' ДЛЯ ТЕСТОВ', extra_permissions, persistent: '', + scripts_0x: '', scripts_2x: ', "20-ip-to-host-api.js"', scripts_8x: ', "80-error-menu.js", "83-last-errors.js", "85-block-informer.js"', });