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

Create Progressive Web App #4730

Merged
merged 14 commits into from
Nov 27, 2018
Next Next commit
Create manifest and serviceworker
  • Loading branch information
SohnyBohny committed Aug 16, 2018
commit a8df308a2273114a0d83721018a3b682d67f79b0
20 changes: 20 additions & 0 deletions public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"short_name": "Gitea",
"name": "Gitea - Git with a cup of tea",
"icons": [
{
"src": "/img/gitea-lg.png",
"type": "image/png",
"sizes": "880x880"
},
{
"src": "/img/gitea-sm.png",
"type": "image/png",
"sizes": "120x120"
}
],
"start_url": "/",
"background_color": "#FAFAFA",
"display": "standalone",
"theme_color": "#609926"
}
68 changes: 68 additions & 0 deletions public/serviceworker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
var STATIC_CACHE = 'static-cache-v1';
var urlsToCache = [
// js
'/vendor/plugins/jquery.areyousure/jquery.are-you-sure.js',
'/vendor/plugins/jquery/jquery.min.js',
'/vendor/plugins/semantic/semantic.min.js',
'/js/index.js', // TODO: {{MD5 AppVer}}
'/js/draw.js',
'/vendor/plugins/clipboard/clipboard.min.js',
'/vendor/plugins/gitgraph/gitgraph.js',
'/vendor/plugins/vue/vue.min.js',
'/vendor/plugins/emojify/emojify.min.js',
'/vendor/plugins/cssrelpreload/loadCSS.min.js',
'/vendor/plugins/cssrelpreload/cssrelpreload.min.js',
'/vendor/plugins/dropzone/dropzone.js',
'/vendor/plugins/highlight/highlight.pack.js',
'/vendor/plugins/jquery.datetimepicker/jquery.datetimepicker.js',
'/vendor/plugins/jquery.minicolors/jquery.minicolors.min.js',
'/vendor/plugins/codemirror/addon/mode/loadmode.js',
'/vendor/plugins/codemirror/mode/meta.js',
'/vendor/plugins/simplemde/simplemde.min.js',

// css
'/vendor/assets/font-awesome/css/font-awesome.min.css',
'/vendor/assets/octicons/octicons.min.css',
'/vendor/plugins/simplemde/simplemde.min.css',
'/vendor/plugins/gitgraph/gitgraph.css',
'/vendor/plugins/tribute/tribute.css',
'/vendor/plugins/semantic/semantic.min.css',
'/css/index.css', // TODO: {{MD5 AppVer}}
'/vendor/plugins/highlight/github.css',
'/vendor/plugins/jquery.minicolors/jquery.minicolors.css',
'/vendor/plugins/jquery.datetimepicker/jquery.datetimepicker.css',
'/vendor/plugins/dropzone/dropzone.css',
// TODO: /css/theme-{{DefaultTheme}}.css

// img
'/img/gitea-sm.png',
'/img/gitea-lg.png',

// fonts
'/vendor/plugins/semantic/themes/default/assets/fonts/icons.woff2',
'/vendor/assets/octicons/octicons.woff2' // TODO: ?MD5
];

self.addEventListener('install', function (event) {
// Perform install steps
event.waitUntil(
caches.open(STATIC_CACHE)
.then(function (cache) {
return cache.addAll(urlsToCache);
})
);
});

self.addEventListener('fetch', function (event) {
event.respondWith(
caches.match(event.request)
.then(function (response) {
// Cache hit - return response
if (response) {
return response;
}
return fetch(event.request);
}
)
);
});
17 changes: 17 additions & 0 deletions templates/base/head.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>{{if .Title}}{{.Title}} - {{end}}{{AppName}}</title>
<link rel="manifest" href="/manifest.json">

<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('/serviceworker.js').then(function(registration) {
SohnyBohny marked this conversation as resolved.
Show resolved Hide resolved
// Registration was successful
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}, function(err) {
// registration failed :(
console.log('ServiceWorker registration failed: ', err);
});
});
}

</script>

<meta name="theme-color" content="{{ThemeColorMetaTag}}">
<meta name="author" content="{{if .Repository}}{{.Owner.Name}}{{else}}{{MetaAuthor}}{{end}}" />
<meta name="description" content="{{if .Repository}}{{.Repository.Name}}{{if .Repository.Description}} - {{.Repository.Description}}{{end}}{{else}}{{MetaDescription}}{{end}}" />
Expand Down