-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(service-worker): Add new service worker configuration
- Loading branch information
1 parent
f0dda34
commit 1fa68c8
Showing
20 changed files
with
2,784 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,22 @@ | ||
<!DOCTYPE html> | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<meta | ||
http-equiv="Content-Security-Policy" | ||
content="default-src 'self'; img-src 'self' data:; style-src 'self' 'unsafe-inline'; style-src-attr 'self'; child-src 'none'; worker-src 'self' blob:; script-src-elem 'self' https://api.mapbox.com; connect-src 'self' ws://* wss://* https://*;" | ||
/> | ||
<meta name="description" content="SitRep" /> | ||
<link rel="icon" href="/favicon-48x48.ico" sizes="48x48" /> | ||
<link rel="icon" href="/favicon.ico" sizes="64x64" /> | ||
<link rel="icon" href="/logo.svg" sizes="any" type="image/svg+xml" /> | ||
<link rel="apple-touch-icon" href="/apple-touch-icon-180x180.png" /> | ||
<title>Sitrep</title> | ||
</head> | ||
|
||
<head> | ||
<meta charset="utf-8" /> | ||
<link rel="icon" href="/favicon.ico" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<meta http-equiv="Content-Security-Policy" | ||
content="default-src 'self'; img-src 'self' data:; style-src 'self' 'unsafe-inline'; style-src-attr 'self'; child-src 'none'; worker-src 'self' blob:; script-src-elem 'self' https://api.mapbox.com; connect-src 'self' ws://* wss://* https://*;" /> | ||
<meta name="description" content="SitRep" /> | ||
<link rel="apple-touch-icon" href="/logo192.png" /> | ||
<link rel="manifest" href="/manifest.json" /> | ||
<title>Sitrep</title> | ||
</head> | ||
|
||
<body class="has-navbar-fixed-top"> | ||
<div id="root"></div> | ||
<script type="module" src="/src/index.tsx"></script> | ||
</body> | ||
|
||
</html> | ||
<body class="has-navbar-fixed-top"> | ||
<div id="root"></div> | ||
<script type="module" src="/src/index.tsx"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,8 @@ | |
"start": "VERSION=dev GIT_SHA=HEAD vite", | ||
"build": "tsc && vite build", | ||
"test": "vitest", | ||
"preview": "vite preview" | ||
"preview": "vite preview", | ||
"generate-pwa-assets": "pwa-assets-generator" | ||
}, | ||
"eslintConfig": { | ||
"extends": [ | ||
|
@@ -78,8 +79,10 @@ | |
"@types/react-color": "^3.0.11", | ||
"@types/react-dom": "^18.2.18", | ||
"@types/react-router-dom": "^5.3.3", | ||
"@types/semver": "^7", | ||
"@typescript-eslint/eslint-plugin": "^6.21.0", | ||
"@typescript-eslint/parser": "^6.21.0", | ||
"@vite-pwa/assets-generator": "^0.2.3", | ||
"@vitejs/plugin-react-swc": "^3.6.0", | ||
"@vitest/coverage-v8": "^1.2.2", | ||
"eslint": "^8.56.0", | ||
|
@@ -90,21 +93,23 @@ | |
"lint-staged": "^15.2.0", | ||
"prettier": "^3.2.4", | ||
"sass": "^1.70.0", | ||
"semver": "^7.6.0", | ||
"source-map-explorer": "^2.5.3", | ||
"ts-jest": "^29.1.2", | ||
"typescript": "^4.9.5", | ||
"vite": "^5.0.12", | ||
"vite-plugin-checker": "^0.6.4", | ||
"vite-plugin-eslint": "^1.8.1", | ||
"vite-plugin-pwa": "^0.17.5", | ||
"vite-plugin-svgr": "^4.2.0", | ||
"vite-tsconfig-paths": "^4.3.1", | ||
"vitest": "^1.2.2" | ||
}, | ||
"resolutions": { | ||
"json5": "^2.2.3", | ||
"semver": "^5.7.2", | ||
"@types/react": "^18.2.0", | ||
"@types/react-dom": "^18.2.18" | ||
"@types/react-dom": "^18.2.18", | ||
"sharp": "^0.33.2" | ||
}, | ||
"packageManager": "[email protected]" | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { defineConfig } from "@vite-pwa/assets-generator/config"; | ||
|
||
export default defineConfig({ | ||
/* remember to include the preset for favicons and apple touch icon */ | ||
headLinkOptions: { | ||
preset: "2023", | ||
}, | ||
preset: { | ||
transparent: { | ||
sizes: [64, 192, 512], | ||
favicons: [ | ||
[48, "favicon-48x48.ico"], | ||
[64, "favicon.ico"], | ||
], | ||
}, | ||
maskable: { | ||
sizes: [512], | ||
}, | ||
apple: { | ||
sizes: [180], | ||
}, | ||
}, | ||
images: ["public/logo.svg"], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { useRegisterSW } from "virtual:pwa-register/react"; | ||
|
||
function ReloadPrompt() { | ||
const { | ||
offlineReady: [offlineReady, setOfflineReady], | ||
needRefresh: [needRefresh, setNeedRefresh], | ||
updateServiceWorker, | ||
} = useRegisterSW({ | ||
onRegistered(r) { | ||
// eslint-disable-next-line prefer-template | ||
console.log("SW Registered: " + r); | ||
}, | ||
onRegisterError(error) { | ||
console.log("SW registration error", error); | ||
}, | ||
}); | ||
|
||
const close = () => { | ||
setOfflineReady(false); | ||
setNeedRefresh(false); | ||
}; | ||
|
||
return ( | ||
<> | ||
{needRefresh && offlineReady && ( | ||
<div className="notification is-info"> | ||
<button className="delete" onClick={close}></button> | ||
<span>New content available, click on reload button to update.</span> | ||
<button className="button is-primary is-light" onClick={() => updateServiceWorker(true)}> | ||
Reload | ||
</button> | ||
</div> | ||
)} | ||
</> | ||
); | ||
} | ||
|
||
export default ReloadPrompt; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
/// <reference types="vite/client" /> | ||
/// <reference types="vite-plugin-svgr/client" /> | ||
/// <reference types="vite-plugin-pwa/client" /> | ||
/// <reference types="vite-plugin-pwa/react" /> | ||
|
||
import { FC, SVGProps } from 'react'; | ||
import { FC, SVGProps } from "react"; | ||
|
||
declare module '*.png'; | ||
declare module '*.jpeg'; | ||
declare module '*.jpg'; | ||
declare module '*.svg' { | ||
const content: FC<SVGProps<SVGElement>>; | ||
export default content; | ||
} | ||
declare module "*.png"; | ||
declare module "*.jpeg"; | ||
declare module "*.jpg"; | ||
declare module "*.svg" { | ||
const content: FC<SVGProps<SVGElement>>; | ||
export default content; | ||
} |
Oops, something went wrong.