Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
345 changes: 164 additions & 181 deletions docs/plugins/pwa/pwa/config.md

Large diffs are not rendered by default.

337 changes: 160 additions & 177 deletions docs/zh/plugins/pwa/pwa/config.md

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions plugins/pwa/plugin-pwa/src/client/composables/setupPwa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ import { pwaEventSymbol } from './usePwaEvent.js'
import { useRegisterSW } from './useRegisterSW.js'
import type { PwaEvent } from './index.js'

/**
* Setup PWA functionality
*
* 设置 PWA 功能
*
* @param serviceWorkerPath - Service Worker path / Service Worker 路径
* @param shouldForceUpdate - Whether to force update / 是否强制更新
*/
export const setupPwa = (
serviceWorkerPath: string,
shouldForceUpdate = false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { onMounted } from 'vue'

/**
* Setup viewport for PWA standalone mode
*
* 为 PWA 独立模式设置视口
*/
export const setupViewPoint = (): void => {
onMounted(() => {
const isStandAlone = window.matchMedia('(display-mode: standalone)').matches
Expand Down
7 changes: 7 additions & 0 deletions plugins/pwa/plugin-pwa/src/client/composables/usePwaEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ export const pwaEventSymbol: InjectionKey<PwaEvent> = Symbol(
__VUEPRESS_DEV__ ? 'PwaEvent' : '',
)

/**
* Use PWA event emitter
*
* 使用 PWA 事件发射器
*
* @returns PWA event emitter / PWA 事件发射器
*/
export const usePwaEvent = (): PwaEvent => {
const pwaEvent = inject(pwaEventSymbol)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ import { withBase } from 'vuepress/client'
import { registerSW } from '../utils/index.js'
import type { PwaEvent } from './usePwaEvent.js'

/**
* Register service worker with event emitter
*
* 使用事件发射器注册 Service Worker
*
* @param serviceWorkerPath - Service Worker path / Service Worker 路径
* @param event - PWA event emitter / PWA 事件发射器
* @returns Promise that resolves when registration is complete / 注册完成时解析的 Promise
*/
export const useRegisterSW = async (
serviceWorkerPath: string,
event: PwaEvent,
Expand Down
10 changes: 3 additions & 7 deletions plugins/pwa/plugin-pwa/src/client/utils/registerSW.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ import type { Hooks } from 'register-service-worker'
/**
* Register serviceWorker under `serviceWorkerPath`
*
* @param serviceWorkerPath Service Worker path
* @param hooks Service worker hooks
* @param showStatus Whether to show status in console
*
* 在 `serviceWorkerPath` 下注册 Service Worker
*
* @param serviceWorkerPath Service Worker 路径
* @param hooks Service Worker 钩子
* @param showStatus 是否在控制台显示状态
* @param serviceWorkerPath - Service Worker path / Service Worker 路径
* @param hooks - Service worker hooks / Service Worker 钩子
* @param showStatus - Whether to show status in console / 是否在控制台显示状态
*/
export const registerSW = async (
serviceWorkerPath: string,
Expand Down
2 changes: 2 additions & 0 deletions plugins/pwa/plugin-pwa/src/client/utils/skipWaiting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* Call `skipWaiting()` inside current waiting worker
*
* 在当前等待中的 Service Worker 中调用 `skipWaiting()`
*
* @param registration - The registration of the service worker you want activate / 想要激活的 Service Worker 的注册
*/
export const skipWaiting = (registration: ServiceWorkerRegistration): void => {
// Get the waiting worker
Expand Down
4 changes: 1 addition & 3 deletions plugins/pwa/plugin-pwa/src/client/utils/unregisterSW.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
/**
* Call `unregister()` inside current active worker
*
* @returns `true` if unregister success, `false` if unregister failed
*
* 在当前激活的 Service Worker 中调用 `unregister()`
*
* @returns `true` 表示注销成功,`false` 表示注销失败
* @returns `true` if unregister success, `false` if unregister failed / `true` 表示注销成功,`false` 表示注销失败
*/
export const unregisterSW = (): Promise<boolean> =>
navigator.serviceWorker
Expand Down
25 changes: 25 additions & 0 deletions plugins/pwa/plugin-pwa/src/node/pwaPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,31 @@ import { PLUGIN_NAME, logger } from './logger.js'
import type { PwaPluginOptions } from './options.js'
import { prepareClientConfigFile } from './prepareClientConfigFile.js'

/**
* PWA plugin
*
* PWA 插件
*
* @param options - Plugin options / 插件选项
* @returns VuePress plugin / VuePress 插件
*
* @example
* ```ts
* import { pwaPlugin } from '@vuepress/plugin-pwa'
*
* export default {
* plugins: [
* pwaPlugin({
* showInstall: true,
* manifest: {
* name: 'My PWA App'
* },
* update: 'hint'
* })
* ]
* }
* ```
*/
export const pwaPlugin =
(options: PwaPluginOptions = {}): PluginFunction =>
(app) => {
Expand Down
Loading