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

pwa support #92

Open
wants to merge 9 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
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default [
languageOptions: { globals: globals.browser },
},
{
ignores: ['.github', '.husky', '.vscode', 'node_modules', 'dist'],
ignores: ['.github', '.husky', '.vscode', 'node_modules', 'dist', 'public/sw.js'],
},
js.configs.recommended,
...ts.configs.recommendedTypeChecked,
Expand Down
74 changes: 46 additions & 28 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,38 +1,56 @@
<!doctype html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no" />
<meta name="theme-color" content="#1B1B1F" />
<meta name="description" content="manage your openpilot experience" />
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
<meta name="theme-color" content="#1B1B1F">
<meta name="description" content="manage your openpilot experience">
<title>connect</title>

<link rel="manifest" href="/manifest.json" />
<link
href="/images/favicon-16x16.png"
rel="icon"
type="image/png"
sizes="16x16"
/>
<link
href="/images/favicon-32x32.png"
rel="icon"
type="image/png"
sizes="32x32"
/>
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,[email protected],400,0..1,0&display=block"
/>
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Inter:[email protected]&family=JetBrains+Mono:wght@400;500&display=swap"
/>
<link rel="manifest" href="/manifest.json">
<link href="/images/favicon-16x16.png" rel="icon" type="image/png" sizes="16x16">
<link href="/images/favicon-32x32.png" rel="icon" type="image/png" sizes="32x32">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,[email protected],400,0..1,0&amp;display=block">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:[email protected]&amp;family=JetBrains+Mono:wght@400;500&amp;display=swap">
<link rel="apple-touch-icon" href="images/apple-icon-180.png">
<meta name="apple-mobile-web-app-capable" content="yes">
<link rel="apple-touch-startup-image" href="images/apple-splash-2048-2732.jpg" media="(device-width: 1024px) and (device-height: 1366px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="images/apple-splash-2732-2048.jpg" media="(device-width: 1024px) and (device-height: 1366px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="images/apple-splash-1668-2388.jpg" media="(device-width: 834px) and (device-height: 1194px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="images/apple-splash-2388-1668.jpg" media="(device-width: 834px) and (device-height: 1194px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="images/apple-splash-1536-2048.jpg" media="(device-width: 768px) and (device-height: 1024px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="images/apple-splash-2048-1536.jpg" media="(device-width: 768px) and (device-height: 1024px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="images/apple-splash-1488-2266.jpg" media="(device-width: 744px) and (device-height: 1133px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="images/apple-splash-2266-1488.jpg" media="(device-width: 744px) and (device-height: 1133px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="images/apple-splash-1640-2360.jpg" media="(device-width: 820px) and (device-height: 1180px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="images/apple-splash-2360-1640.jpg" media="(device-width: 820px) and (device-height: 1180px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="images/apple-splash-1668-2224.jpg" media="(device-width: 834px) and (device-height: 1112px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="images/apple-splash-2224-1668.jpg" media="(device-width: 834px) and (device-height: 1112px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="images/apple-splash-1620-2160.jpg" media="(device-width: 810px) and (device-height: 1080px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="images/apple-splash-2160-1620.jpg" media="(device-width: 810px) and (device-height: 1080px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="images/apple-splash-1290-2796.jpg" media="(device-width: 430px) and (device-height: 932px) and (-webkit-device-pixel-ratio: 3) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="images/apple-splash-2796-1290.jpg" media="(device-width: 430px) and (device-height: 932px) and (-webkit-device-pixel-ratio: 3) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="images/apple-splash-1179-2556.jpg" media="(device-width: 393px) and (device-height: 852px) and (-webkit-device-pixel-ratio: 3) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="images/apple-splash-2556-1179.jpg" media="(device-width: 393px) and (device-height: 852px) and (-webkit-device-pixel-ratio: 3) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="images/apple-splash-1284-2778.jpg" media="(device-width: 428px) and (device-height: 926px) and (-webkit-device-pixel-ratio: 3) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="images/apple-splash-2778-1284.jpg" media="(device-width: 428px) and (device-height: 926px) and (-webkit-device-pixel-ratio: 3) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="images/apple-splash-1170-2532.jpg" media="(device-width: 390px) and (device-height: 844px) and (-webkit-device-pixel-ratio: 3) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="images/apple-splash-2532-1170.jpg" media="(device-width: 390px) and (device-height: 844px) and (-webkit-device-pixel-ratio: 3) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="images/apple-splash-1125-2436.jpg" media="(device-width: 375px) and (device-height: 812px) and (-webkit-device-pixel-ratio: 3) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="images/apple-splash-2436-1125.jpg" media="(device-width: 375px) and (device-height: 812px) and (-webkit-device-pixel-ratio: 3) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="images/apple-splash-1242-2688.jpg" media="(device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 3) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="images/apple-splash-2688-1242.jpg" media="(device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 3) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="images/apple-splash-828-1792.jpg" media="(device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="images/apple-splash-1792-828.jpg" media="(device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="images/apple-splash-1242-2208.jpg" media="(device-width: 414px) and (device-height: 736px) and (-webkit-device-pixel-ratio: 3) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="images/apple-splash-2208-1242.jpg" media="(device-width: 414px) and (device-height: 736px) and (-webkit-device-pixel-ratio: 3) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="images/apple-splash-750-1334.jpg" media="(device-width: 375px) and (device-height: 667px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="images/apple-splash-1334-750.jpg" media="(device-width: 375px) and (device-height: 667px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="images/apple-splash-640-1136.jpg" media="(device-width: 320px) and (device-height: 568px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="images/apple-splash-1136-640.jpg" media="(device-width: 320px) and (device-height: 568px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">
</head>
<body data-theme="dark" class="overflow-x-hidden bg-background text-on-background">
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>

<script src="/src/index.tsx" type="module"></script>
</body>
</html>
91 changes: 91 additions & 0 deletions offline.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Offline - Comma Connect</title>
<style>
body {
font-family: 'Inter', sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
margin: 0;
background-color: #1B1B1F;
color: #FFFFFF;
text-align: center;
padding: 1rem;
}
.container {
display: flex;
flex-direction: column;
align-items: center;
gap: 2rem;
max-width: 20rem;
}
h1 {
font-size: 1.5rem;
font-weight: 800;
margin: 0;
margin-bottom: 8px;
}
p {
font-size: 1rem;
margin: 0.5rem 0 0;
}
.button {
background-color: #3B3B3F;
color: #FFFFFF;
border: none;
padding: 0.75rem 1.5rem;
border-radius: 0.5rem;
font-size: 1rem;
cursor: pointer;
transition: background-color 0.3s;
}
.button:hover {
background-color: #4B4B4F;
}
.int_check {
margin: 0;
}
.status-container {
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
}
.status-circle {
width: 0.5rem;
height: 0.5rem;
background-color: #FF0000;
border-radius: 50%;
}
.status-container p {
margin: 0;
display: flex;
align-items: center;
}
</style>
</head>
<body>
<div class="container">
<img src="/images/logo-connect-light.svg" alt="comma connect" width="96" height="96" />
<div>
<h1>comma connect</h1>
<div class="status-container">
<div class="status-circle"></div>
<p>offline</p>
</div>
</div>
<p class="int_check">Please check your internet connection and try again.</p>
<button class="button" onclick="window.location.reload()">Try Again</button>
</div>
<script>
// This script will attempt to reload the page when online
window.addEventListener('online', () => window.location.reload());
</script>
</body>
</html>
Binary file added public/images/apple-icon-180.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 public/images/apple-splash-1125-2436.jpg
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 public/images/apple-splash-1136-640.jpg
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 public/images/apple-splash-1170-2532.jpg
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 public/images/apple-splash-1179-2556.jpg
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 public/images/apple-splash-1242-2208.jpg
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 public/images/apple-splash-1242-2688.jpg
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 public/images/apple-splash-1284-2778.jpg
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 public/images/apple-splash-1290-2796.jpg
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 public/images/apple-splash-1334-750.jpg
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 public/images/apple-splash-1488-2266.jpg
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 public/images/apple-splash-1536-2048.jpg
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 public/images/apple-splash-1620-2160.jpg
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 public/images/apple-splash-1640-2360.jpg
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 public/images/apple-splash-1668-2224.jpg
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 public/images/apple-splash-1668-2388.jpg
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 public/images/apple-splash-1792-828.jpg
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 public/images/apple-splash-2048-1536.jpg
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 public/images/apple-splash-2048-2732.jpg
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 public/images/apple-splash-2160-1620.jpg
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 public/images/apple-splash-2208-1242.jpg
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 public/images/apple-splash-2224-1668.jpg
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 public/images/apple-splash-2266-1488.jpg
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 public/images/apple-splash-2360-1640.jpg
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 public/images/apple-splash-2388-1668.jpg
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 public/images/apple-splash-2436-1125.jpg
Binary file added public/images/apple-splash-2532-1170.jpg
Binary file added public/images/apple-splash-2556-1179.jpg
Binary file added public/images/apple-splash-2688-1242.jpg
Binary file added public/images/apple-splash-2732-2048.jpg
Binary file added public/images/apple-splash-2778-1284.jpg
Binary file added public/images/apple-splash-2796-1290.jpg
Binary file added public/images/apple-splash-640-1136.jpg
Binary file added public/images/apple-splash-750-1334.jpg
Binary file added public/images/apple-splash-828-1792.jpg
Binary file added public/images/manifest-icon-192.maskable.png
Binary file added public/images/manifest-icon-512.maskable.png
31 changes: 17 additions & 14 deletions public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,38 @@
"name": "comma connect",
"icons": [
{
"src": "/images/icon-vector.svg",
"type": "image/svg+xml",
"sizes": "512x512"
"src": "images/manifest-icon-192.maskable.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "any"
},
{
"src": "/images/icon-192.png",
"src": "images/manifest-icon-192.maskable.png",
"sizes": "192x192",
"type": "image/png",
"sizes": "192x192"
"purpose": "maskable"
},
{
"src": "/images/icon-256.png",
"src": "images/manifest-icon-512.maskable.png",
"sizes": "512x512",
"type": "image/png",
"sizes": "256x256"
"purpose": "any"
},
{
"src": "/images/icon-384.png",
"src": "images/manifest-icon-512.maskable.png",
"sizes": "512x512",
"type": "image/png",
"sizes": "384x384"
"purpose": "maskable"
},
{
"src": "/images/icon-512.png",
"src": "/images/icon-256.png",
"type": "image/png",
"sizes": "512x512"
"sizes": "256x256"
},
{
"src": "/images/icon-maskable.png",
"sizes": "512x512",
"src": "/images/icon-384.png",
"type": "image/png",
"purpose": "maskable"
"sizes": "384x384"
}
],
"id": "/",
Expand Down
58 changes: 58 additions & 0 deletions public/sw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const CACHE_NAME = 'connect-cache'
const URLS_TO_CACHE = [
'/index.html',
'/manifest.json',
'/offline.html',
]

const CACHE_PATTERNS = [
/\/images\/.*\.(png|jpg|svg)$/,
/\/fonts\.googleapis\.com\//,
/\/fonts\.gstatic\.com\//,
]

self.addEventListener('install', (event) => {
event.waitUntil(
caches.open(CACHE_NAME).then((cache) => cache.addAll(URLS_TO_CACHE))
)
})

self.addEventListener('fetch', (event) => {
if (event.request.method !== 'GET') {
return
}

if (shouldCache(event.request.url)) {
event.respondWith(
caches.match(event.request).then((response) => {
if (response) {
return response
}
return fetch(event.request).then((fetchResponse) => {
if (fetchResponse.status === 200) {
const responseToCache = fetchResponse.clone()
caches.open(CACHE_NAME).then((cache) => {
cache.put(event.request, responseToCache)
})
}
return fetchResponse
})
}).catch(handleError))
} else {
event.respondWith(
fetch(event.request).catch(handleError)
)
}
})

function handleError(err) {
if (!navigator.onLine) {
return caches.match('/offline.html')
}
throw err
}

function shouldCache(url) {
const path = new URL(url).pathname
return CACHE_PATTERNS.some((pattern) => pattern.test(path))
}
1 change: 0 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const App: VoidComponent = () => {
<Route path="/login" component={Login} />
<Route path="/logout" component={Logout} />
<Route path="/auth" component={Auth} />

<Route path="/*dongleId" component={Dashboard} />
</Router>
)
Expand Down
2 changes: 2 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import './index.css'

import { render } from 'solid-js/web'
import App from './App'
import { registerServiceWorker } from './registerSW'

const root = document.getElementById('root')

Expand All @@ -13,3 +14,4 @@ if (import.meta.env.DEV && !(root instanceof HTMLElement)) {
}

render(() => <App />, root!)
registerServiceWorker()
62 changes: 19 additions & 43 deletions src/pages/auth/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,23 @@ import { setAccessToken } from '~/api/auth/client'

import Button from '~/components/material/Button'

interface AuthButtonProps {
href: string
logo: string
text: string
}

const AuthButton = (props: AuthButtonProps) => {
return <Button
class="h-16 gap-4"
href={props.href}
leading={<img src={`/images/logo-${props.logo}.svg`} alt="" width={32} height={32} />}>
{props.text}
</Button >
}

export default function Login() {
const loginAsDemoUser = function () {
const loginAsDemoUser = function() {
setAccessToken('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NDg1ODI0NjUsIm5iZiI6MTcxNzA0NjQ2NSwiaWF0IjoxNzE3MDQ2NDY1LCJpZGVudGl0eSI6IjBkZWNkZGNmZGYyNDFhNjAifQ.g3khyJgOkNvZny6Vh579cuQj1HLLGSDeauZbfZri9jw')
window.location.href = window.location.origin
}
Expand All @@ -25,48 +40,9 @@ export default function Login() {
</div>

<div class="flex flex-col items-stretch gap-4 self-stretch">
<Button
class="h-16 gap-4"
href={getGoogleAuthUrl()}
leading={
<img
src="/images/logo-google.svg"
alt=""
width={32}
height={32}
/>
}
>
Sign in with Google
</Button>
<Button
class="h-16 gap-4"
href={getAppleAuthUrl()}
leading={
<img
src="/images/logo-apple.svg"
alt=""
width={32}
height={32}
/>
}
>
Sign in with Apple&nbsp&nbsp
</Button>
<Button
class="h-16 gap-4"
href={getGitHubAuthUrl()}
leading={
<img
src="/images/logo-github.svg"
alt=""
width={32}
height={32}
/>
}
>
Sign in with GitHub
</Button>
<AuthButton href={getGoogleAuthUrl()} logo="google" text="Sign in with Google" />
<AuthButton href={getAppleAuthUrl()} logo="apple" text="Sign in with Apple" />
<AuthButton href={getGitHubAuthUrl()} logo="github" text="Sign in with GitHub" />
</div>

<div class="flex justify-between gap-4">
Expand Down
Loading
Loading