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

Make the web app progressive #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="theme-color" content="#212121">
<link rel="manifest" href="manifest.json">
<meta name="description" content="Point your camera at things to hear how to say them in a different language">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta name="author" content="Dan Motzenbecker">
<script src="service-worker-registration.js"></script>
<link href="https://fonts.googleapis.com/css?family=Montserrat:400,700" rel="stylesheet" type="text/css">
<link href="app.css" rel="stylesheet" type="text/css">
<title>Thing Translator</title>
Expand Down
Binary file added logo-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added logo-512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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": {
Expand All @@ -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"
Expand Down
57 changes: 57 additions & 0 deletions service-worker-registration.js
Original file line number Diff line number Diff line change
@@ -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);
});
}
12 changes: 12 additions & 0 deletions sw-precache-config.js
Original file line number Diff line number Diff line change
@@ -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'
]
};