Merge pull request #141 from Dexlux/pwa_support
feat: 集成PWA基础配置,支持用户以类App形式打开项目
This commit is contained in:
12
index.html
12
index.html
@@ -3,6 +3,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8"/>
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.png"/>
|
||||
<link rel="manifest" href="/manifest.json">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||
<title>Type Words - 词文记 | 单词跟打 · 文章跟打</title>
|
||||
<!-- 搜索引擎描述 -->
|
||||
@@ -77,5 +78,16 @@
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
<script>
|
||||
if ('serviceWorker' in navigator) {
|
||||
window.addEventListener('load', () => {
|
||||
navigator.serviceWorker.register('/service-worker.js').then(registration => {
|
||||
console.log('ServiceWorker registration successful with scope: ', registration.scope);
|
||||
}).catch(error => {
|
||||
console.log('ServiceWorker registration failed: ', error);
|
||||
});
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
16
manifest.json
Normal file
16
manifest.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "Type Words - 词文记 | 单词跟打 · 文章跟打",
|
||||
"short_name": "",
|
||||
"start_url": ".",
|
||||
"description": "在线英语打字练习平台,支持单词跟打与文章跟打,帮助提升打字速度与英语学习效率。",
|
||||
"display": "standalone",
|
||||
"background_color": "#ffffff",
|
||||
"theme_color": "#ffffff",
|
||||
"icons": [
|
||||
{
|
||||
"src": "/favicon.png",
|
||||
"sizes": "800x800",
|
||||
"type": "image/png"
|
||||
}
|
||||
]
|
||||
}
|
||||
12
service-worker.js
Normal file
12
service-worker.js
Normal file
@@ -0,0 +1,12 @@
|
||||
// 'install' 事件在 Service Worker 首次被安装时触发。
|
||||
self.addEventListener('install', event => {
|
||||
self.skipWaiting();
|
||||
});
|
||||
|
||||
// 'activate' 事件在 Service Worker 变为激活状态时触发。
|
||||
self.addEventListener('activate', event => {
|
||||
return self.clients.claim();
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', event => {
|
||||
});
|
||||
Reference in New Issue
Block a user