Skip to content

Commit f3c560c

Browse files
feat: enable offline mode
close #118
1 parent fa61a94 commit f3c560c

12 files changed

Lines changed: 3396 additions & 367 deletions

index.html

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11
<!DOCTYPE html>
22
<html lang="en">
3-
<head>
4-
<meta charset="utf-8" />
5-
<!-- <link rel="shortcut icon" href="/favicon.ico" /> -->
6-
<meta name="viewport" content="width=device-width, initial-scale=1" />
7-
<meta name="theme-color" content="#000000" />
8-
<title>NMRium Wrapper</title>
93

10-
<style>
11-
html,
12-
body,
13-
#root {
14-
height: 100%;
15-
margin: 0;
16-
padding: 0;
17-
}
18-
</style>
19-
</head>
20-
<body>
21-
<noscript>You need to enable JavaScript to run this app.</noscript>
22-
<div id="root"></div>
23-
<script type="module" src="/src/index.tsx"></script>
24-
</body>
25-
</html>
4+
<head>
5+
<meta charset="utf-8" />
6+
<!-- <link rel="shortcut icon" href="/favicon.ico" /> -->
7+
<meta name="viewport" content="width=device-width, initial-scale=1" />
8+
<meta name="theme-color" content="#ea580c" />
9+
<title>NMRium Wrapper</title>
10+
<meta name="description"
11+
content="Wrapper for NMRium which is a powerful tool for displaying and processing nuclear magnetic resonance (NMR) spectra">
12+
13+
<style>
14+
html,
15+
body,
16+
#root {
17+
height: 100%;
18+
margin: 0;
19+
padding: 0;
20+
}
21+
</style>
22+
</head>
23+
24+
<body>
25+
<noscript>You need to enable JavaScript to run this app.</noscript>
26+
<div id="root"></div>
27+
<script type="module" src="/src/index.tsx"></script>
28+
</body>
29+
30+
</html>

package-lock.json

Lines changed: 2015 additions & 309 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"@emotion/react": "^11.11.1",
1717
"filelist-utils": "^1.10.0",
1818
"nmr-load-save": "^0.15.1",
19-
"nmrium": "0.42.0"
19+
"nmrium": "0.42.0",
20+
"vite-plugin-pwa": "^0.16.4"
2021
},
2122
"scripts": {
2223
"start": "vite --host localhost --port 3000 --open",

public/icon-192x192.png

3.57 KB
Loading

public/icon-256x256.png

4.68 KB
Loading

public/icon-384x384.png

8.46 KB
Loading

public/icon-512x512.png

10.5 KB
Loading

public/manifest.webmanifest

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"theme_color": "#ea580c",
3+
"background_color": "#ea580c",
4+
"display": "standalone",
5+
"scope": "/",
6+
"start_url": "/",
7+
"name": "NMRium",
8+
"short_name": "NMRium wrapper",
9+
"icons": [
10+
{
11+
"src": "/icon-192x192.png",
12+
"sizes": "192x192",
13+
"type": "image/png"
14+
},
15+
{
16+
"src": "/icon-256x256.png",
17+
"sizes": "256x256",
18+
"type": "image/png"
19+
},
20+
{
21+
"src": "/icon-384x384.png",
22+
"sizes": "384x384",
23+
"type": "image/png"
24+
},
25+
{
26+
"src": "/icon-512x512.png",
27+
"sizes": "512x512",
28+
"type": "image/png"
29+
}
30+
],
31+
"description": "Wrapper for NMRium which is a powerful tool for displaying and processing nuclear magnetic resonance (NMR) spectra"
32+
}

src/index.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createRoot } from 'react-dom/client';
22
import { HashRouter as Router, Route, Routes } from 'react-router-dom';
3+
import { registerSW } from 'virtual:pwa-register';
34
import NMRiumWrapper from './NMRiumWrapper';
45
import NMRiumWrapperDemo from './demo/NMRiumWrapperDemo';
56

@@ -9,6 +10,18 @@ if (!rootContainer) {
910
throw new Error('#root element is not exists in the dom');
1011
}
1112

13+
// add this to prompt for a refresh
14+
const updateSW = registerSW({
15+
onNeedRefresh() {
16+
if (window.confirm('New NMRium wrappe update available. Reload?')) {
17+
updateSW(true);
18+
}
19+
},
20+
onOfflineReady() {
21+
window.alert('NMRium wrapper runs in offline mode');
22+
},
23+
});
24+
1225
const root = createRoot(rootContainer);
1326

1427
function RootWrapper() {

tsconfig.json

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
{
22
"compilerOptions": {
33
"target": "ES2020",
4-
"lib": ["dom", "dom.iterable", "esnext"],
5-
"types": ["vite/client", "@types/jest"],
4+
"lib": [
5+
"dom",
6+
"dom.iterable",
7+
"esnext"
8+
],
9+
"types": [
10+
"vite/client",
11+
"@types/jest",
12+
"vite-plugin-pwa/client"
13+
],
614
"allowJs": false,
715
"skipLibCheck": true,
816
"esModuleInterop": true,
@@ -18,8 +26,13 @@
1826
"noEmit": true,
1927
"jsx": "react-jsx",
2028
},
21-
22-
"include": ["src","vite.config.ts","test-e2e", "playwright.config.ts"],
23-
"exclude": ["node_modules"]
24-
25-
}
29+
"include": [
30+
"src",
31+
"vite.config.ts",
32+
"test-e2e",
33+
"playwright.config.ts"
34+
],
35+
"exclude": [
36+
"node_modules"
37+
]
38+
}

0 commit comments

Comments
 (0)