mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-07-24 14:47:35 +08:00
feat(pwa): 补齐 web 端 PWA 可安装条件
- 新增 192/512 图标与 maskable 变体(源自 icon.png,安全区 80%) - manifest.json 图标声明修正(原先仅声明一个实际不存在的 256 尺寸) - 注册最小 Service Worker(空 fetch 处理器,不做缓存拦截),仅 Web 生产环境生效 Closes #640 Ref #382
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 62 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 76 KiB |
+13
-2
@@ -8,9 +8,20 @@
|
|||||||
"theme_color": "#000000",
|
"theme_color": "#000000",
|
||||||
"icons": [
|
"icons": [
|
||||||
{
|
{
|
||||||
"src": "./icon.png",
|
"src": "/icon-192.png",
|
||||||
"type": "image/png",
|
"type": "image/png",
|
||||||
"sizes": "256x256"
|
"sizes": "192x192"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "/icon-512.png",
|
||||||
|
"type": "image/png",
|
||||||
|
"sizes": "512x512"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "/icon-512-maskable.png",
|
||||||
|
"type": "image/png",
|
||||||
|
"sizes": "512x512",
|
||||||
|
"purpose": "maskable"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
// 最小 Service Worker:仅满足 PWA 可安装性要求(需存在 fetch 处理器)。
|
||||||
|
// 不做任何缓存拦截,所有请求保持浏览器默认网络行为。
|
||||||
|
self.addEventListener('install', () => {
|
||||||
|
self.skipWaiting();
|
||||||
|
});
|
||||||
|
|
||||||
|
self.addEventListener('activate', (event) => {
|
||||||
|
event.waitUntil(self.clients.claim());
|
||||||
|
});
|
||||||
|
|
||||||
|
self.addEventListener('fetch', () => {
|
||||||
|
// 特意留空:不拦截,默认走网络
|
||||||
|
});
|
||||||
@@ -8,10 +8,20 @@ import { createApp } from 'vue';
|
|||||||
import i18n from '@/../i18n/renderer';
|
import i18n from '@/../i18n/renderer';
|
||||||
import router from '@/router';
|
import router from '@/router';
|
||||||
import pinia from '@/store';
|
import pinia from '@/store';
|
||||||
|
import { isElectron } from '@/utils';
|
||||||
|
|
||||||
import App from './App.vue';
|
import App from './App.vue';
|
||||||
import directives from './directive';
|
import directives from './directive';
|
||||||
|
|
||||||
|
// Web 端注册最小 Service Worker,使站点满足 PWA 可安装条件(#640/#382)
|
||||||
|
if (!isElectron && import.meta.env.PROD && 'serviceWorker' in navigator) {
|
||||||
|
window.addEventListener('load', () => {
|
||||||
|
navigator.serviceWorker.register('/sw.js').catch((error) => {
|
||||||
|
console.warn('[PWA] Service Worker 注册失败:', error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const app = createApp(App);
|
const app = createApp(App);
|
||||||
|
|
||||||
Object.keys(directives).forEach((key: string) => {
|
Object.keys(directives).forEach((key: string) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user