diff --git a/.eslintignore b/.eslintignore index 945f1892..13fd70f6 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,2 @@ -src/assets/* \ No newline at end of file +src/assets/* +public/sw.js \ No newline at end of file diff --git a/package.json b/package.json index 2758cd3d..2bd42abc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "stapxs-qq-lite", - "version": "2.8.6", + "version": "2.9.0", "private": false, "author": "Stapx Steve [林槐]", "description": "一个兼容 OneBot 的非官方网页版 QQ 客户端,使用 Vue 重制的全新版本。", @@ -27,6 +27,7 @@ "detect-browser": "^5.3.0", "electron-store": "^8.1.0", "electron-window-state": "^5.0.3", + "gettext-parser": "^8.0.0", "js-file-downloader": "^1.1.24", "js-yaml-loader": "^1.2.2", "jsonpath": "^1.1.1", @@ -38,6 +39,7 @@ "semver-compare": "^1.0.0", "spacingjs": "^1.0.7", "ts-loader": "~8.2.0", + "util": "^0.12.5", "uuidv4": "^6.2.13", "v-viewer": "^3.0.11", "viewerjs": "^1.11.6", @@ -54,6 +56,7 @@ "@types/animejs": "^3.1.12", "@types/css": "^0.0.33", "@types/electron-devtools-installer": "^2.2.0", + "@types/gettext-parser": "^4.0.4", "@types/jsonpath": "^0.2.3", "@types/semver-compare": "^1.0.3", "@typescript-eslint/eslint-plugin": "^5.4.0", diff --git a/public/css/append-dark.css b/public/css/append-dark.css index c88c7292..b77237e6 100644 --- a/public/css/append-dark.css +++ b/public/css/append-dark.css @@ -8,4 +8,6 @@ --color-bg-green: #3f544a; --color-bg-red: #523a3c; --color-bg-yellow: #504b3d; + + --color-issue-close: #a47ff1; } \ No newline at end of file diff --git a/public/css/append-light.css b/public/css/append-light.css index 9cb77a7e..d62d88c1 100644 --- a/public/css/append-light.css +++ b/public/css/append-light.css @@ -8,4 +8,6 @@ --color-bg-green: #d5e6de; --color-bg-red: #f3d8da; --color-bg-yellow: #fdf3d1; + + --color-issue-close: #8059d9; } \ No newline at end of file diff --git a/public/sw.js b/public/sw.js new file mode 100644 index 00000000..0c755e46 --- /dev/null +++ b/public/sw.js @@ -0,0 +1,58 @@ +/** + * 本文件由 Copilot 生成,sw 配置实在是太难写了 😭 + */ + +const CACHE_NAME = 'qlogo-cache-v1'; +// const CACHE_DURATION = 1000; +const CACHE_DURATION = 3 * 24 * 60 * 60 * 1000; + +self.addEventListener('install', (event) => { + // 跳过等待,立即激活 + self.skipWaiting(); +}); + +self.addEventListener('activate', (event) => { + // 清理旧缓存 + event.waitUntil( + caches.keys().then((cacheNames) => { + return Promise.all( + cacheNames.map((cacheName) => { + if (cacheName !== CACHE_NAME) { + return caches.delete(cacheName); + } + }) + ); + }) + ); +}); + +self.addEventListener('fetch', (event) => { + const url = new URL(event.request.url); + + // sw.js 本身的请求不缓存 + if (url.pathname === '/sw.js') { + return; + } + + if (url.hostname === 'q1.qlogo.cn') { + // 对于 QQ 头像的请求,缓存三天 + event.respondWith( + caches.open(CACHE_NAME).then((cache) => { + return cache.match(event.request).then((response) => { + if (response) { + return response; + } + + return fetch(event.request).then((response) => { + const responseClone = response.clone(); + cache.put(event.request, responseClone); + return response; + }); + }); + }) + ); + } else { + // 对于其他请求,采用默认的网络优先策略 + event.respondWith(fetch(event.request)); + } +}); \ No newline at end of file diff --git a/src/App.vue b/src/App.vue index ce097800..4b9305f6 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,4 +1,8 @@