Skip to content
This repository has been archived by the owner on Jul 25, 2023. It is now read-only.

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
tgerulaitis committed Jun 7, 2017
2 parents b2481c4 + 096b46b commit c691c61
Show file tree
Hide file tree
Showing 14 changed files with 155 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# Build files
/node_modules

# Dev environment
/magento
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ A Docker development environment is included with the project:
docker-compose run --rm cli bash /src/setup.sh
docker-compose up -d

### npm dependencies

The extension uses npm to manage some of its web dependencies. Dependencies are installed and updated using npm, then
copied into the `src/` directory using an npm script. To update the web dependencies, run:

docker-compose run --rm node npm update
docker-compose run --rm node npm run build

### Testing Service Workers on Chrome

Chrome is very strict about security and only allows Service Workers on localhost, or on an HTTPS site with a valid certificate. To bypass these restrictions for testing, use the `--ignore-certificate-errors` and `--unsafely-treat-insecure-origin-as-secure` flags to run a less secure copy of Chrome:
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "meanbee/magento2-serviceworker",
"description": "A Magento 2 extension that adds Service Worker support.",
"type": "magento2-module",
"version": "1.0.0",
"version": "1.1.0",
"license": [
"MIT"
],
Expand All @@ -20,9 +20,9 @@
},
"require": {
"magento/framework": "^100.1.2",
"magento/module-backend": "^100.1.2",
"magento/module-config": "^100.1.2",
"magento/module-cms": "^101.0.3"
"magento/module-backend": "^100.1.1",
"magento/module-config": "^100.1.1",
"magento/module-cms": "^101.0.2"
},
"autoload": {
"files": [
Expand Down
11 changes: 10 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ services:
links:
- db

node:
image: node:8
working_dir: /src
command: /bin/true
volumes:
- ~/.npm:/.npm
volumes_from:
- appdata

db:
image: mariadb:10
ports:
Expand All @@ -107,7 +116,7 @@ services:
- SYNC_VERBOSE=1
- SYNC_MAX_INOTIFY_WATCHES=64000
privileged: true
restart: always
restart: on-failure:5

dbdata:
image: tianon/true
Expand Down
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "@meanbee/magento2-serviceworker",
"version": "1.1.0",
"description": "A Magento 2 extension that adds Service Worker support.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build:clean": "rm -rf src/view/frontend/web/js/lib/*",
"build:copy": "find node_modules/workbox-google-analytics -name 'workbox-google-analytics.prod.*' -exec install -t src/view/frontend/web/js/lib {} +",
"build": "npm run build:clean && npm run build:copy"
},
"repository": {
"type": "git",
"url": "git+https://github.com/meanbee/magento2-serviceworker.git"
},
"author": "Tomas Gerulaitis <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/meanbee/magento2-serviceworker/issues"
},
"homepage": "https://github.com/meanbee/magento2-serviceworker#readme",
"dependencies": {
"workbox-google-analytics": "^1.0.0"
}
}
20 changes: 20 additions & 0 deletions src/Block/Js.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,24 @@ public function getUrlBlacklist()
{
return $this->config->getUrlBlacklist();
}

/**
* Check if Offline Google Analytics features are enabled.
*
* @return bool
*/
public function isGaOfflineEnabled()
{
return $this->config->isGaOfflineEnabled();
}

/**
* Get the URL to the Offline Google Analytics helper script.
*
* @return string
*/
public function getGaJsUrl()
{
return $this->getViewFileUrl("Meanbee_ServiceWorker::js/lib/workbox-google-analytics.prod.v1.0.0.js");
}
}
13 changes: 13 additions & 0 deletions src/Helper/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Config extends \Magento\Framework\App\Helper\AbstractHelper
const XML_PATH_ENABLE = "web/serviceworker/enable";
const XML_PATH_OFFLINE_PAGE = "web/serviceworker/offline_page";
const XML_PATH_URL_BLACKLIST = "web/serviceworker/url_blacklist";
const XML_PATH_GA_OFFLINE_ENABLE = "web/serviceworker/ga_offline_enable";

const PATH_WILDCARD_SYMBOL = "*";

Expand Down Expand Up @@ -81,4 +82,16 @@ public function getUrlBlacklist()

return $data;
}

/**
* Check if Offline Google Analytics features are enabled.
*
* @param string $store
*
* @return bool
*/
public function isGaOfflineEnabled($store = null)
{
return $this->scopeConfig->isSetFlag(static::XML_PATH_GA_OFFLINE_ENABLE, ScopeInterface::SCOPE_STORE, $store);
}
}
5 changes: 5 additions & 0 deletions src/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
<label>Offline URL blacklist</label>
<comment><![CDATA[A list of URL paths, one per line. Any pages entered here will not be cached and will be unavailable offline. If an entry ends with "*", any pages that start with the entered path will also be excluded.]]></comment>
</field>
<field id="ga_offline_enable" translate="label comment" type="select" sortOrder="500" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enable Offline Google Analytics</label>
<comment><![CDATA[If enabled, caches any Google Analytics tracking events while the visitor is browsing offline and submits them when internet connection is restored.]]></comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
</section>
</system>
Expand Down
1 change: 1 addition & 0 deletions src/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
customer/account/create*
customer/account/login*
]]></url_blacklist>
<ga_offline_enable>1</ga_offline_enable>
</serviceworker>
</web>
</default>
Expand Down
2 changes: 1 addition & 1 deletion src/etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Meanbee_ServiceWorker" setup_version="1.0.0">
<module name="Meanbee_ServiceWorker" setup_version="1.1.0">
<sequence/>
</module>
</config>
6 changes: 6 additions & 0 deletions src/view/frontend/templates/serviceworker.js.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ const version = '<?php echo $block->getVersion() ?>';
const offlinePage = '<?php echo $block->getOfflinePageUrl() ?>';
const urlBlacklist = <?php echo json_encode($block->getUrlBlacklist()) ?>;

<?php if ($block->isGaOfflineEnabled()): ?>
importScripts('<?php echo $block->getGaJsUrl() ?>');

workbox.googleAnalytics.initialize();
<?php endif; ?>

// Functions
// #####################################

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

0 comments on commit c691c61

Please sign in to comment.