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

feat: add basic offline pwa support #3718

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -69,6 +69,7 @@
"switchery-latest": "^0.8.2",
"three": "~0.97.0",
"universal-ga": "^1.2.0",
"vite-plugin-pwa": "^0.17.4",
"vue": "^2.7.10"
},
"devDependencies": {
Expand Down
Binary file added src/images/pwa/apple-touch-icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/pwa/favicon.ico
Binary file not shown.
Binary file added src/images/pwa/pwa-192-192.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/pwa/pwa-512-512.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions src/index.html
@@ -1,13 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="author" content="cTn"/>
<meta name="viewport" content="width=device-width,initial-scale=1">

<script type="module" src="/src/js/utils/common.js"></script>
<script type="module" src="/src/js/browserMain.js"></script>

<title></title>
<title>Betaflight</title>
<meta name="description" content="Configurator for betaflight firmware">
<link rel="icon" href="/images/pwa/favicon.ico">
<link rel="apple-touch-icon" href="/images/pwa/apple-touch-icon.png" sizes="128x128">
<meta name="theme-color" content="#eea600">
</head>
<body>
<div id="main-wrapper">
Expand Down
8 changes: 8 additions & 0 deletions src/js/browserMain.js
Expand Up @@ -50,3 +50,11 @@ import "../components/EscDshotDirection/Styles.css";
import "../css/dark-theme.less";

import "./main";

import { registerSW } from 'virtual:pwa-register';

registerSW({
onOfflineReady() {
alert('App is ready for offline use.');
},
});
28 changes: 28 additions & 0 deletions vite.config.js
Expand Up @@ -6,6 +6,7 @@ import { readFileSync } from "node:fs";
import copy from "rollup-plugin-copy";
import pkg from './package.json';
import * as child from 'child_process';
import { VitePWA } from "vite-plugin-pwa";

const commitHash = child.execSync('git rev-parse --short HEAD').toString();

Expand Down Expand Up @@ -73,6 +74,33 @@ export default defineConfig({
],
hook: "writeBundle",
}),
VitePWA({
registerType: 'autoUpdate',
workbox: {
globPatterns: ['**/*.{js,css,html,ico,png,svg,json,mcm}'],
// 5MB
maximumFileSizeToCacheInBytes: 5 * 1024 * 1024,
},
includeAssets: ['favicon.ico', 'apple-touch-icon.png'],
manifest: {
name: pkg.productName,
short_name: pkg.productName,
description: pkg.description,
theme_color: '#ffffff',
icons: [
{
src: '/images/pwa/pwa-192-192.png',
sizes: '192x192',
type: 'image/png',
},
{
src: '/images/pwa/pwa-512-512.png',
sizes: '512x512',
type: 'image/png',
},
],
},
}),
],
root: "./src",
resolve: {
Expand Down
1,255 changes: 1,242 additions & 13 deletions yarn.lock

Large diffs are not rendered by default.