diff --git a/backgroundscript.js b/backgroundscript.js index 04f76091c..a02cc2d30 100644 --- a/backgroundscript.js +++ b/backgroundscript.js @@ -32,7 +32,7 @@ if (typeof browser !== 'undefined') { // Chromium/Chrome genericBrowser = chrome; } - +// DEV: For a Mozilla MV3 extension, we have to change the event below to 'action' genericBrowser.browserAction.onClicked.addListener(function () { var newURL = chrome.runtime.getURL('www/index.html'); chrome.tabs.create({ url: newURL }); diff --git a/manifest.fx.v3.json b/manifest.fx.v3.json new file mode 100644 index 000000000..06cd4f7dd --- /dev/null +++ b/manifest.fx.v3.json @@ -0,0 +1,47 @@ +{ + "manifest_version": 3, + "name": "Kiwix", + "version": "3.10.2", + + "description": "Kiwix Offline Browser", + + "icons": { + "16": "www/img/icons/kiwix-16.png", + "19": "www/img/icons/kiwix-19.png", + "32": "www/img/icons/kiwix-32.png", + "38": "www/img/icons/kiwix-38.png", + "48": "www/img/icons/kiwix-48.png", + "64": "www/img/icons/kiwix-64.png", + "90": "www/img/icons/kiwix-90.png", + "128": "www/img/icons/kiwix-128.png" + }, + + "action": { + "default_icon": { + "16": "www/img/icons/kiwix-16.png", + "19": "www/img/icons/kiwix-19.png", + "32": "www/img/icons/kiwix-32.png", + "38": "www/img/icons/kiwix-38.png", + "64": "www/img/icons/kiwix-64.png" + }, + "default_title": "Kiwix" + }, + + "background": { + "scripts": ["backgroundscript.js"] + }, + + "content_security_policy": { + "extension_pages": "script-src 'self' 'wasm-unsafe-eval'; object-src 'self';", + "sandbox": "sandbox allow-scripts allow-downloads allow-forms allow-popups allow-modals; script-src 'self' 'unsafe-inline' 'unsafe-eval'; child-src 'self';" + }, + + "web_accessible_resources": [{ + "resources": ["www/index.html", "www/article.html"], + "matches": ["https://*.kiwix.org/*"] + }], + + "author": "Kiwix", + "homepage_url": "https://www.kiwix.org", + "offline_enabled": true +} diff --git a/rollup.config.js b/rollup.config.js index f9d9b83ee..04dcd3a5d 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -46,7 +46,7 @@ const config = { }, { src: ['node_modules/bootstrap/dist/css/bootstrap.min.*'], dest: 'dist/www/css' }, { src: ['i18n/*'], dest: 'dist/i18n' }, - { src: ['archives', 'backgroundscript.js', 'index.html', 'manifest.json', 'manifest.v2.json', 'manifest.webapp', 'package.json', 'LICENSE-GPLv3.txt', 'CHANGELOG.md', 'README.md', '*.pfx', '*.cjs'], dest: 'dist' } + { src: ['archives', 'backgroundscript.js', 'index.html', 'manifest.json', 'manifest.fx.v3.json', 'manifest.v2.json', 'manifest.webapp', 'package.json', 'LICENSE-GPLv3.txt', 'CHANGELOG.md', 'README.md', '*.pfx', '*.cjs'], dest: 'dist' } ], flatten: true }) diff --git a/scripts/create_all_packages.sh b/scripts/create_all_packages.sh index 7ecc008a6..ed35c3943 100755 --- a/scripts/create_all_packages.sh +++ b/scripts/create_all_packages.sh @@ -59,20 +59,14 @@ fi # Copy only the necessary files in a temporary directory mkdir -p tmp rm -rf tmp/* -cp -r www i18n manifest.json manifest.v2.json manifest.webapp LICENSE-GPLv3.txt service-worker.js README.md tmp/ +cp -r www i18n manifest.json manifest.webapp LICENSE-GPLv3.txt service-worker.js README.md tmp/ # Remove unwanted files (this line should not be necessary if building from dist/) rm -f tmp/www/js/lib/libzim-*dev.* # Replace the version number everywhere # But Chrome would only accept a numeric version number : if it's not, we only use the prefix in manifest.json regexpNumericVersion='^[0-9\.]+$' -if [[ $VERSION =~ $regexpNumericVersion ]] ; then - sed -i -E "s/$VERSION_TO_REPLACE/$VERSION/" tmp/manifest.json - sed -i -E "s/$VERSION_TO_REPLACE/$VERSION/" tmp/manifest.v2.json -else - sed -i -E "s/$VERSION_TO_REPLACE/$MAJOR_NUMERIC_VERSION/" tmp/manifest.json - sed -i -E "s/$VERSION_TO_REPLACE/$MAJOR_NUMERIC_VERSION/" tmp/manifest.v2.json -fi +sed -i -E "s/$VERSION_TO_REPLACE/$MAJOR_NUMERIC_VERSION/" tmp/manifest.json sed -i -E "s/$VERSION_TO_REPLACE/$VERSION/" tmp/manifest.webapp sed -i -E "s/$VERSION_TO_REPLACE/$VERSION/" tmp/service-worker.js sed -i -E "s/$VERSION_TO_REPLACE/$VERSION/" tmp/www/js/init.js @@ -85,23 +79,36 @@ rm -rf build/* scripts/package_chrome_extension.sh -m 3 $DRYRUN $TAG -v $VERSION # Package for Chromium/Chrome with Manifest V2 cp backgroundscript.js tmp/ -rm tmp/manifest.json -mv tmp/manifest.v2.json tmp/manifest.json +cp manifest.v2.json tmp/manifest.json +sed -i -E "s/$VERSION_TO_REPLACE/$MAJOR_NUMERIC_VERSION/" tmp/manifest.json scripts/package_chrome_extension.sh -m 2 $DRYRUN $TAG -v $VERSION echo "The following extensions have been built so far:" pwd & ls -l build -# Package for Firefox and Firefox OS +# Package for Firefox MV2 # We have to put a unique version string inside the manifest.json (which Chrome might not have accepted) # So we take the original manifest v2 again, and replace the version inside it again cp manifest.v2.json tmp/manifest.json sed -i -E "s/$VERSION_TO_REPLACE/$VERSION_FOR_MOZILLA_MANIFEST/" tmp/manifest.json -echo "Manifest version for Firefox extension:" +echo "Manifest version for Firefox MV2 extension:" cat tmp/manifest.json -echo -e "\nPacking for Firefox..." -scripts/package_firefox_extension.sh $DRYRUN $TAG -v $VERSION +echo -e "\nPacking for Firefox MV2..." +scripts/package_firefox_extension.sh -m 2 $DRYRUN $TAG -v $VERSION + +# Package for Firefox MV3 +cp manifest.fx.v3.json tmp/manifest.json +# Replace the browserAction key which is no longer supported in MV3 +sed -i -E "s/browserAction/action/" tmp/backgroundscript.js +# Note that MV3 requires a numeric version number +sed -i -E "s/$VERSION_TO_REPLACE/$MAJOR_NUMERIC_VERSION/" tmp/manifest.json +echo "Manifest version for Firefox MV3 extension:" +cat tmp/manifest.json +echo -e "\nPacking for Firefox MV3..." +scripts/package_firefox_extension.sh -m 3 $DRYRUN $TAG -v $VERSION echo "The following extensions have been built so far:" pwd & ls -l build + +# Package for Firefox OS echo -e "\nPacking for Firefox OS..." scripts/package_firefoxos_app.sh $DRYRUN $TAG -v $VERSION cp -f ubuntu_touch/* tmp/ diff --git a/scripts/package_firefox_extension.sh b/scripts/package_firefox_extension.sh index b46ac0453..08e89a097 100755 --- a/scripts/package_firefox_extension.sh +++ b/scripts/package_firefox_extension.sh @@ -4,13 +4,18 @@ cd "$BASEDIR" pwd # Reading arguments -while getopts tdv: option; do +while getopts m:tdv: option; do case "${option}" in + m) MV=$OPTARG;; # Optionally indicates the manifest version we're using (2 or 3); if present, the version will be added to filename t) TAG="-t";; # Indicates that we're releasing a public version from a tag d) DRYRUN="-d";; # Indicates a dryrun test, that does not modify anything on the network v) VERSION=${OPTARG};; esac done +if [ -n $MV ]; then + echo -e "\nManifest version requested: $MV" + VERSION="mv$MV-$VERSION" +fi # Install web-ext if it's not already installed (and if we're not doing a dryrun test) if [ ! -f node_modules/web-ext/bin/web-ext ] && [ "${DRYRUN}zz" == "zz" ]; then