* created pwa
* fixed jdbc warning * new gradle run task * new gradle jar-build task
This commit is contained in:
		@@ -26,6 +26,8 @@
 | 
			
		||||
  <script type="text/javascript" src="js/index.js"></script>
 | 
			
		||||
 | 
			
		||||
	  <script src="lib/AdminLTE/plugins/sweetalert2/sweetalert2.all.js"></script>
 | 
			
		||||
 | 
			
		||||
	  <link rel="manifest" href="/manifest.json">
 | 
			
		||||
</head>
 | 
			
		||||
<body>
 | 
			
		||||
<div class="container">
 | 
			
		||||
 
 | 
			
		||||
@@ -25,4 +25,20 @@ $(document).ready(function () {
 | 
			
		||||
            }
 | 
			
		||||
        }, 'json');
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    //register pwa
 | 
			
		||||
    async function registerSW() {
 | 
			
		||||
        console.log("registering service worker!");
 | 
			
		||||
        if ('serviceWorker' in navigator) {
 | 
			
		||||
            try {
 | 
			
		||||
                await navigator.serviceWorker.register('/sw.js');
 | 
			
		||||
            } catch (e) {
 | 
			
		||||
                console.log(`SW registration failed`);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    registerSW();
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										15
									
								
								src/resources/wwwroot/manifest.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								src/resources/wwwroot/manifest.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
			
		||||
{
 | 
			
		||||
  "name": "Waste Information Server",
 | 
			
		||||
  "short_name": "WasteInformationServer",
 | 
			
		||||
  "start_url": "/",
 | 
			
		||||
  "display": "standalone",
 | 
			
		||||
  "background_color": "#fff",
 | 
			
		||||
  "description": "A web app to manage waste pickups",
 | 
			
		||||
  "icons": [
 | 
			
		||||
    {
 | 
			
		||||
      "src": "wasteicon.png",
 | 
			
		||||
      "sizes": "512x512",
 | 
			
		||||
      "type": "image/png"
 | 
			
		||||
    }
 | 
			
		||||
  ]
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										59
									
								
								src/resources/wwwroot/sw.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								src/resources/wwwroot/sw.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,59 @@
 | 
			
		||||
const cacheName = 'static-v2';
 | 
			
		||||
const staticAssets = [
 | 
			
		||||
    '/',
 | 
			
		||||
    '/index.html',
 | 
			
		||||
    '/css/index.css',
 | 
			
		||||
    '/js/index.js',
 | 
			
		||||
    '/manifest.json',
 | 
			
		||||
    '/lib/bootstrap.min.css',
 | 
			
		||||
    '/lib/bootstrap.min.js',
 | 
			
		||||
    '/lib/jquery.min.js',
 | 
			
		||||
    '/lib/popper.min.js',
 | 
			
		||||
    '/rsc/login2.jpg',
 | 
			
		||||
    '/wasteicon.png'
 | 
			
		||||
];
 | 
			
		||||
 | 
			
		||||
self.addEventListener('install', async e => {
 | 
			
		||||
    console.log('V1 installing…');
 | 
			
		||||
 | 
			
		||||
    e.waitUntil(
 | 
			
		||||
        caches.open('static-v2').then(cache => cache.addAll(staticAssets))
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    // const cache = await caches.open(cacheName);
 | 
			
		||||
    // await cache.addAll(staticAssets);
 | 
			
		||||
    // return self.skipWaiting();
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
self.addEventListener('activate', e => {
 | 
			
		||||
    self.clients.claim();
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
self.addEventListener('fetch', async e => {
 | 
			
		||||
    const req = e.request;
 | 
			
		||||
    const url = new URL(req.url);
 | 
			
		||||
 | 
			
		||||
    if (url.origin === location.origin) {
 | 
			
		||||
        e.respondWith(cacheFirst(req));
 | 
			
		||||
    } else {
 | 
			
		||||
        e.respondWith(networkAndCache(req));
 | 
			
		||||
    }
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
async function cacheFirst(req) {
 | 
			
		||||
    const cache = await caches.open(cacheName);
 | 
			
		||||
    const cached = await cache.match(req);
 | 
			
		||||
    return cached || fetch(req);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function networkAndCache(req) {
 | 
			
		||||
    const cache = await caches.open(cacheName);
 | 
			
		||||
    try {
 | 
			
		||||
        const fresh = await fetch(req);
 | 
			
		||||
        await cache.put(req, fresh.clone());
 | 
			
		||||
        return fresh;
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
        const cached = await cache.match(req);
 | 
			
		||||
        return cached;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user