diff --git a/index.html b/index.html index 542a09a9..41f95316 100644 --- a/index.html +++ b/index.html @@ -2,9 +2,12 @@ + + + Thing Translator diff --git a/logo-192x192.png b/logo-192x192.png new file mode 100644 index 00000000..1d45870c Binary files /dev/null and b/logo-192x192.png differ diff --git a/logo-512x512.png b/logo-512x512.png new file mode 100644 index 00000000..182a5b71 Binary files /dev/null and b/logo-512x512.png differ diff --git a/logo.svg b/logo.svg new file mode 100644 index 00000000..4e3a9099 --- /dev/null +++ b/logo.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/manifest.json b/manifest.json new file mode 100644 index 00000000..522ffda1 --- /dev/null +++ b/manifest.json @@ -0,0 +1,25 @@ +{ + "name": "Thing Translator", + "short_name": "Thing Translator", + "start_url": "./?utm_source=homescreen", + "scope": "/", + "display": "standalone", + "theme_color": "#212121", + "background_color": "#fff", + "icons": [ + { + "src": "logo-192x192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "logo-512x512.png", + "sizes": "512x512", + "type": "image/png" + }, + { + "src": "logo.svg", + "type": "image/svg+xml" + } + ] +} diff --git a/package.json b/package.json index 366512a3..daaf72ff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "thing-translator", - "version": "0.0.1", + "version": "0.0.2", "description": "Thing Translator is an AI Experiment that lets you point your camera at things to hear how to say them in a different language.", "private": true, "main": "src/app.js", @@ -11,9 +11,10 @@ }, "scripts": { "bundle": "NODE_ENV=production browserify -e src/app.js -g babelify -g envify -g unassertify -g uglifyify | uglifyjs > app.js", - "dev": "parallelshell 'npm run watch' 'npm run watch-style'", + "dev": "parallelshell 'npm run watch' 'npm run watch-style' 'npm run gen-sw-precache'", "watch": "budo src/app.js --live -- -t babelify", - "watch-style": "stylus -c -u nib -w style/main.styl -o app.css" + "watch-style": "stylus -c -u nib -w style/main.styl -o app.css", + "gen-sw-precache": "sw-precache --config=sw-precache-config.js" }, "license": "MIT", "dependencies": { @@ -29,6 +30,7 @@ "nib": "^1.1.2", "parallelshell": "^2.0.0", "stylus": "^0.54.5", + "sw-precache": "^4.2.2", "uglify-js": "^2.7.4", "uglifyify": "^3.0.4", "unassertify": "^2.0.3" diff --git a/service-worker-registration.js b/service-worker-registration.js new file mode 100644 index 00000000..6bb4599e --- /dev/null +++ b/service-worker-registration.js @@ -0,0 +1,57 @@ +/** + * Copyright 2015 Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* eslint-env browser */ +'use strict'; + +if ('serviceWorker' in navigator) { + // Your service-worker.js *must* be located at the top-level directory relative to your site. + // It won't be able to control pages unless it's located at the same level or higher than them. + // *Don't* register service worker file in, e.g., a scripts/ sub-directory! + // See https://github.com/slightlyoff/ServiceWorker/issues/468 + navigator.serviceWorker.register('service-worker.js').then(function(reg) { + // updatefound is fired if service-worker.js changes. + reg.onupdatefound = function() { + // The updatefound event implies that reg.installing is set; see + // https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#service-worker-container-updatefound-event + var installingWorker = reg.installing; + + installingWorker.onstatechange = function() { + switch (installingWorker.state) { + case 'installed': + if (navigator.serviceWorker.controller) { + // At this point, the old content will have been purged and the fresh content will + // have been added to the cache. + // It's the perfect time to display a "New content is available; please refresh." + // message in the page's interface. + console.log('New or updated content is available.'); + } else { + // At this point, everything has been precached. + // It's the perfect time to display a "Content is cached for offline use." message. + console.log('Content is now available offline!'); + } + break; + + case 'redundant': + console.error('The installing service worker became redundant.'); + break; + } + }; + }; + }).catch(function(e) { + console.error('Error during service worker registration:', e); + }); +} diff --git a/sw-precache-config.js b/sw-precache-config.js new file mode 100644 index 00000000..e0fe6a02 --- /dev/null +++ b/sw-precache-config.js @@ -0,0 +1,12 @@ +module.exports = { + staticFileGlobs: [ + 'index.html', + 'app.js', + 'app.css', + 'service-worker-registration.js', + 'manifest.json', + 'logo-192x192.png', + 'logo-512x512.png', + 'logo.svg' + ] +}; \ No newline at end of file