Skip to content

Commit

Permalink
added basic files and codes
Browse files Browse the repository at this point in the history
created files and directories with basic codes and added funtional manifest and service worker
  • Loading branch information
if-true001 committed Dec 27, 2022
1 parent 9083cb8 commit 09ed808
Show file tree
Hide file tree
Showing 13 changed files with 203 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}

.page{
width: 100%;
height: 100vh;
}
19 changes: 19 additions & 0 deletions app/app.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#317EFB"/>
<link rel="apple-touch-icon" href="app/icons/calc-maskable950.png">
<link rel="stylesheet" href="app.css">
<title>calculator</title>
</head>
<body>

<div class="page"></div>

<script src="app.js"></script>

</body>
</html>
Empty file added app/app.js
Empty file.
Binary file added app/icons/calc-maskable950.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 app/icons/calc144.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 app/icons/calc512.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 app/icons/calc64.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 favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<link rel="shortcut icon" href="favicon.png" type="image/png">
<link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin><link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
<meta name="theme-color" content="#317EFB"/>
<link rel="apple-touch-icon" href="app/icons/calc-maskable950.png">
<link rel="stylesheet" href="style.css">
<link rel="manifest" href="manifest.json">
<title>calulator PWA</title>
</head>
<body>

<div class="main">
<div class="part1">
<h1>Simple responsive calculator PWA</h1>
</div>
<div class="part2">
<p>Use a chromium based browser for best experience !</p>
<button id="install">Install</button>
</div>
</div>

<script>
//install PWA on button click
//not complete yet
const install = document.getElementById('install')
install.addEventListener('click',async=>{
console.log("clicked");
});
</script>
<script src="script.js"></script>

</body>
</html>
31 changes: 31 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "calculator",
"short_name": "calc",
"start_url": "./app/app.html",
"background_color": "#252525",
"theme_color": "#000000",
"display": "standalone",
"icons":[
{
"src": "./app/icons/calc64.png",
"sizes": "64x64",
"type": "image/png"
},
{
"src": "./app/icons/calc144.png",
"sizes": "144x144",
"type": "image/png"
},
{
"src": "./app/icons/calc512.png",
"sizes": "512x512",
"type": "image/png"
},
{
"src": "./app/icons/calc-maskable950.png",
"sizes": "950x950",
"type": "image/png",
"purpose": "maskable"
}
]
}
12 changes: 12 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
if("serviceWorker" in navigator){
navigator.serviceWorker.register("service-worker.js").then(registration=>{
console.log("Service worker registered")
console.log(registration);
}).catch(error=>{
console.log("Service worker error")
console.log(error);
})
}
else{
alert("Service worker not working")
}
45 changes: 45 additions & 0 deletions service-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const staticCache = "static v:00001";
const assets = [
"./app/app.html",
"./app/app.css",
"./app/app.js",
"./app/icons/calc64.png",
"./app/icons/calc144.png",
"./app/icons/calc512.png",
"./app/icons/calc-maskable950.png"
];

//installing service worker
self.addEventListener("install",event=>{
//caching assets
event.waitUntil(
caches.open("staticCache").then(cache=>{
return cache.addAll(assets);
})
)
})

self.addEventListener('activate',event=>{
event.waitUntil(
//updating cache
caches.keys().then(keys=>{
return Promise.all(
keys.filter(staticCache=>{
})
.map(staticCache=>{
return caches.delete(keys);
})
);
}),
);
})

//fetch assets
self.addEventListener("fetch",event=>{
//response to requests from cache if available else fetch from server
event.respondWith(
caches.match(event.request).then(response=>{
return response || fetch(event.request);
})
);
})
48 changes: 48 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
*{
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Roboto', sans-serif;
scroll-behavior: smooth;
}

.main{
width: 100%;
height: 100vh;
background: linear-gradient(to bottom right, #5a99a8, #062486);
}

.part1{
font-size: larger;
font-weight: 700;
text-align: center;
padding-top: 4rem;
}

h1{
color: #f0f8ff;
}

.part2{
padding-top: 6rem;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}

p{
color: #e2bcbc;
}

button{
width: 80px;
height: 30px;
margin: 4rem;
color: #f0f8ff;
font-weight: bold;
border-radius: 50px;
border-color: #000000;
cursor: pointer;
background: linear-gradient(to bottom right, #0d8bdf, #0ec799);
}

0 comments on commit 09ed808

Please sign in to comment.