Skip to content

Commit

Permalink
Web PWA setup and update icons
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Mar 24, 2024
1 parent f12681e commit 64f6f37
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 1 deletion.
1 change: 1 addition & 0 deletions website/src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<link rel="manifest" href="/manifest.json" />
<meta name="viewport" content="width=device-width" />
%sveltekit.head%
</head>
Expand Down
2 changes: 1 addition & 1 deletion website/src/routes/header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<header class="sticky top-0 z-50 bg-gray-900 text-gray-50 small:static my-5 mx-10 rounded-xl">
<div class="container mx-auto flex flex-col flex-wrap items-center p-5 md:flex-row">
<a href="/" class="space-x-2 flex items-center hover:text-gray-300 duration-200">
<img width="16" height="16" class="inline-block" src="icon.png" alt="authme-logo" />
<img class="inline-block" src="icon.png" alt="authme-logo" />
<h1 class="inline-block text-lg font-bold">Authme</h1>
</a>

Expand Down
82 changes: 82 additions & 0 deletions website/src/service-worker/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/// <reference types="@sveltejs/kit" />
// @ts-nocheck

Check failure on line 2 in website/src/service-worker/index.ts

View workflow job for this annotation

GitHub Actions / build

Do not use "@ts-nocheck" because it alters compilation errors
import { build, files, version } from "$service-worker"

// Create a unique cache name for this deployment
const CACHE = `cache-${version}`

const ASSETS = [
...build, // the app itself
...files, // everything in `static`
]

self.addEventListener("install", (event) => {
// Create a new cache and add all files to it
async function addFilesToCache() {
const cache = await caches.open(CACHE)
await cache.addAll(ASSETS)
}

event.waitUntil(addFilesToCache())
})

self.addEventListener("activate", (event) => {
// Remove previous cached data from disk
async function deleteOldCaches() {
for (const key of await caches.keys()) {
if (key !== CACHE) await caches.delete(key)
}
}

event.waitUntil(deleteOldCaches())
})

self.addEventListener("fetch", (event) => {
// ignore POST requests etc
if (event.request.method !== "GET") return

async function respond() {
const url = new URL(event.request.url)
const cache = await caches.open(CACHE)

// `build`/`files` can always be served from the cache
if (ASSETS.includes(url.pathname)) {
const response = await cache.match(url.pathname)

if (response) {
return response
}
}

// for everything else, try the network first, but
// fall back to the cache if we're offline
try {
const response = await fetch(event.request)

// if we're offline, fetch can return a value that is not a Response
// instead of throwing - and we can't pass this non-Response to respondWith
if (!(response instanceof Response)) {
throw new Error("invalid response from fetch")
}

console.log(response)
if (response.status === 200 && response.url.startsWith("http")) {
cache.put(event.request, response.clone())
}

return response
} catch (err) {
const response = await cache.match(event.request)

if (response) {
return response
}

// if there's no cache, then just error out
// as there is nothing we can do to respond to this request
throw err
}
}

event.respondWith(respond())
})
Binary file modified website/static/favicon.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 modified website/static/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions website/static/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"$schema": "https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/web-manifest.json",
"name": "Authme",
"short_name": "Authme",
"description": "Simple cross-platform two-factor (2FA) authenticator app for desktop.",
"start_url": "/",
"display": "standalone",
"background_color": "#000000",
"theme_color": "#000000",
"orientation": "portrait-primary",
"lang": "en-US",
"categories": ["utilities"],
"dir": "ltr",
"icons": [
{
"src": "maskable_icon_x512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "maskable"
},
{
"src": "maskable_icon_x512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "any"
},
{
"src": "maskable_icon_x192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "maskable"
},
{
"src": "maskable_icon_x192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "any"
}
]
}
Binary file added website/static/maskable_icon_x192.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 website/static/maskable_icon_x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 64f6f37

Please sign in to comment.