mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-05-22 08:49:47 +08:00
Refactor service worker types and extract type definitions
Co-authored-by: jxxghp <jxxghp@163.com>
This commit is contained in:
@@ -1,28 +1,8 @@
|
||||
import { cleanupOutdatedCaches, precacheAndRoute } from 'workbox-precaching'
|
||||
|
||||
// Service Worker 类型声明
|
||||
declare let self: ServiceWorkerGlobalScope
|
||||
|
||||
// 扩展ServiceWorkerRegistration类型以支持sync
|
||||
interface SyncManager {
|
||||
register(tag: string): Promise<void>
|
||||
}
|
||||
|
||||
interface ServiceWorkerRegistration {
|
||||
readonly sync: SyncManager
|
||||
}
|
||||
|
||||
// 扩展ExtendableEvent以支持sync事件
|
||||
interface SyncEvent extends ExtendableEvent {
|
||||
readonly tag: string
|
||||
readonly lastChance: boolean
|
||||
}
|
||||
|
||||
// 扩展ServiceWorkerGlobalScope事件映射
|
||||
declare global {
|
||||
interface ServiceWorkerGlobalScopeEventMap {
|
||||
'sync': SyncEvent
|
||||
}
|
||||
declare let self: ServiceWorkerGlobalScope & {
|
||||
__WB_MANIFEST: Array<{ url: string; revision?: string }>
|
||||
}
|
||||
|
||||
// 缓存版本控制
|
||||
|
||||
38
src/types/service-worker-sync.d.ts
vendored
Normal file
38
src/types/service-worker-sync.d.ts
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
export {}
|
||||
|
||||
declare global {
|
||||
/**
|
||||
* Background SyncManager interface as per the Web Background Sync API.
|
||||
*/
|
||||
interface SyncManager {
|
||||
/**
|
||||
* Registers a one-off sync event with the provided tag.
|
||||
*/
|
||||
register(tag: string): Promise<void>
|
||||
}
|
||||
|
||||
/**
|
||||
* Extension of ServiceWorkerRegistration to include the SyncManager.
|
||||
*/
|
||||
interface ServiceWorkerRegistration {
|
||||
/**
|
||||
* The SyncManager for background sync operations.
|
||||
*/
|
||||
readonly sync: SyncManager
|
||||
}
|
||||
|
||||
/**
|
||||
* The event fired when a background sync is triggered.
|
||||
*/
|
||||
interface SyncEvent extends ExtendableEvent {
|
||||
readonly tag: string
|
||||
readonly lastChance: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Extend ServiceWorkerGlobalScope event map to include the sync event type.
|
||||
*/
|
||||
interface ServiceWorkerGlobalScopeEventMap {
|
||||
'sync': SyncEvent
|
||||
}
|
||||
}
|
||||
23
src/types/workbox-precaching.d.ts
vendored
Normal file
23
src/types/workbox-precaching.d.ts
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
// Type definitions for workbox-precaching runtime use in service worker
|
||||
// Simplified subset needed by this project
|
||||
|
||||
declare module 'workbox-precaching' {
|
||||
/**
|
||||
* A manifest entry generated by Workbox build tools.
|
||||
*/
|
||||
export interface ManifestEntry {
|
||||
url: string
|
||||
revision?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes outdated precaches created by older versions of Workbox.
|
||||
*/
|
||||
export function cleanupOutdatedCaches(): void
|
||||
|
||||
/**
|
||||
* Adds the supplied manifest entries to the precache list and sets up the
|
||||
* appropriate route so that they are served from the cache.
|
||||
*/
|
||||
export function precacheAndRoute(entries: ManifestEntry[]): void
|
||||
}
|
||||
Reference in New Issue
Block a user