@dxos/plugin-pwa 0.6.8-main.046e6cf
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +8 -0
- package/README.md +15 -0
- package/dist/lib/browser/chunk-WUGDEZKD.mjs +11 -0
- package/dist/lib/browser/chunk-WUGDEZKD.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +82 -0
- package/dist/lib/browser/index.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -0
- package/dist/lib/browser/meta.mjs +9 -0
- package/dist/lib/browser/meta.mjs.map +7 -0
- package/dist/types/src/PwaPlugin.d.ts +3 -0
- package/dist/types/src/PwaPlugin.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +4 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/meta.d.ts +6 -0
- package/dist/types/src/meta.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +14 -0
- package/dist/types/src/translations.d.ts.map +1 -0
- package/package.json +56 -0
- package/src/PwaPlugin.tsx +54 -0
- package/src/index.ts +9 -0
- package/src/meta.ts +9 -0
- package/src/pwa.d.ts +5 -0
- package/src/translations.ts +22 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
Copyright (c) 2022 DXOS
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
5
|
+
|
|
6
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @dxos/plugin-url-sync
|
|
2
|
+
|
|
3
|
+
DXOS Surface plugin for PWA registration and update handling.
|
|
4
|
+
|
|
5
|
+
## DXOS Resources
|
|
6
|
+
|
|
7
|
+
- [Website](https://dxos.org)
|
|
8
|
+
- [Developer Documentation](https://docs.dxos.org)
|
|
9
|
+
- Talk to us on [Discord](https://dxos.org/discord)
|
|
10
|
+
|
|
11
|
+
## Contributions
|
|
12
|
+
|
|
13
|
+
Your ideas, issues, and code are most welcome. Please take a look at our [community code of conduct](https://github.com/dxos/dxos/blob/main/CODE_OF_CONDUCT.md), the [issue guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-issues), and the [PR contribution guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-prs).
|
|
14
|
+
|
|
15
|
+
License: [MIT](./LICENSE) Copyright 2023 © DXOS
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/meta.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nexport const PWA_PLUGIN = 'dxos.org/plugin/pwa';\n\nexport default {\n id: PWA_PLUGIN,\n};\n"],
|
|
5
|
+
"mappings": ";AAIO,IAAMA,aAAa;AAE1B,IAAA,eAAe;EACbC,IAAID;AACN;",
|
|
6
|
+
"names": ["PWA_PLUGIN", "id"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PWA_PLUGIN,
|
|
3
|
+
meta_default
|
|
4
|
+
} from "./chunk-WUGDEZKD.mjs";
|
|
5
|
+
|
|
6
|
+
// packages/plugins/plugin-pwa/src/PwaPlugin.tsx
|
|
7
|
+
import { registerSW } from "virtual:pwa-register";
|
|
8
|
+
import { parseIntentPlugin, resolvePlugin, LayoutAction } from "@dxos/app-framework";
|
|
9
|
+
import { log } from "@dxos/log";
|
|
10
|
+
import { captureException } from "@dxos/observability/sentry";
|
|
11
|
+
|
|
12
|
+
// packages/plugins/plugin-pwa/src/translations.ts
|
|
13
|
+
var translations_default = [
|
|
14
|
+
{
|
|
15
|
+
"en-US": {
|
|
16
|
+
[PWA_PLUGIN]: {
|
|
17
|
+
"need refresh label": "Refresh now to get app updates",
|
|
18
|
+
"need refresh description": "You\u2019ll need these updates to continue without interruption.",
|
|
19
|
+
"refresh label": "Refresh",
|
|
20
|
+
"refresh alt": "Click your browser\u2019s refresh button or use the refresh keyboard shortcut.",
|
|
21
|
+
// TODO(wittjosiah): Non-react translation utils.
|
|
22
|
+
// 'offline ready label': '{{appName}} is ready to use offline.',
|
|
23
|
+
"offline ready label": "Ready to use offline.",
|
|
24
|
+
"confirm label": "Okay"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
// packages/plugins/plugin-pwa/src/PwaPlugin.tsx
|
|
31
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/plugin-pwa/src/PwaPlugin.tsx";
|
|
32
|
+
var PwaPlugin = () => ({
|
|
33
|
+
meta: meta_default,
|
|
34
|
+
ready: async (plugins) => {
|
|
35
|
+
const dispatch = resolvePlugin(plugins, parseIntentPlugin)?.provides.intent.dispatch;
|
|
36
|
+
const updateSW = registerSW({
|
|
37
|
+
onNeedRefresh: () => dispatch?.({
|
|
38
|
+
action: LayoutAction.SET_LAYOUT,
|
|
39
|
+
data: {
|
|
40
|
+
element: "toast",
|
|
41
|
+
subject: {
|
|
42
|
+
id: `${PWA_PLUGIN}/need-refresh`,
|
|
43
|
+
title: translations_default[0]["en-US"][PWA_PLUGIN]["need refresh label"],
|
|
44
|
+
description: translations_default[0]["en-US"][PWA_PLUGIN]["need refresh description"],
|
|
45
|
+
duration: 4 * 60 * 1e3,
|
|
46
|
+
actionLabel: translations_default[0]["en-US"][PWA_PLUGIN]["refresh label"],
|
|
47
|
+
actionAlt: translations_default[0]["en-US"][PWA_PLUGIN]["refresh alt"],
|
|
48
|
+
onAction: () => updateSW(true)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}),
|
|
52
|
+
onOfflineReady: () => dispatch?.({
|
|
53
|
+
action: LayoutAction.SET_LAYOUT,
|
|
54
|
+
data: {
|
|
55
|
+
element: "toast",
|
|
56
|
+
subject: {
|
|
57
|
+
id: `${PWA_PLUGIN}/offline-ready`,
|
|
58
|
+
title: translations_default[0]["en-US"][PWA_PLUGIN]["offline ready label"],
|
|
59
|
+
closeLabel: translations_default[0]["en-US"][PWA_PLUGIN]["confirm label"]
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}),
|
|
63
|
+
onRegisterError: (err) => {
|
|
64
|
+
captureException(err);
|
|
65
|
+
log.error(err, void 0, {
|
|
66
|
+
F: __dxlog_file,
|
|
67
|
+
L: 50,
|
|
68
|
+
S: void 0,
|
|
69
|
+
C: (f, a) => f(...a)
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// packages/plugins/plugin-pwa/src/index.ts
|
|
77
|
+
var src_default = PwaPlugin;
|
|
78
|
+
export {
|
|
79
|
+
PwaPlugin,
|
|
80
|
+
src_default as default
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/PwaPlugin.tsx", "../../../src/translations.ts", "../../../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { registerSW } from 'virtual:pwa-register';\n\nimport { parseIntentPlugin, resolvePlugin, type PluginDefinition, LayoutAction } from '@dxos/app-framework';\nimport { log } from '@dxos/log';\nimport { captureException } from '@dxos/observability/sentry';\n\nimport meta, { PWA_PLUGIN } from './meta';\nimport translations from './translations';\n\nexport const PwaPlugin = (): PluginDefinition => ({\n meta,\n ready: async (plugins) => {\n const dispatch = resolvePlugin(plugins, parseIntentPlugin)?.provides.intent.dispatch;\n\n const updateSW = registerSW({\n onNeedRefresh: () =>\n dispatch?.({\n action: LayoutAction.SET_LAYOUT,\n data: {\n element: 'toast',\n subject: {\n id: `${PWA_PLUGIN}/need-refresh`,\n title: translations[0]['en-US'][PWA_PLUGIN]['need refresh label'],\n description: translations[0]['en-US'][PWA_PLUGIN]['need refresh description'],\n duration: 4 * 60 * 1000, // 4m\n actionLabel: translations[0]['en-US'][PWA_PLUGIN]['refresh label'],\n actionAlt: translations[0]['en-US'][PWA_PLUGIN]['refresh alt'],\n onAction: () => updateSW(true),\n },\n },\n }),\n onOfflineReady: () =>\n dispatch?.({\n action: LayoutAction.SET_LAYOUT,\n data: {\n element: 'toast',\n subject: {\n id: `${PWA_PLUGIN}/offline-ready`,\n title: translations[0]['en-US'][PWA_PLUGIN]['offline ready label'],\n closeLabel: translations[0]['en-US'][PWA_PLUGIN]['confirm label'],\n },\n },\n }),\n onRegisterError: (err) => {\n captureException(err);\n log.error(err);\n },\n });\n },\n});\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { PWA_PLUGIN } from './meta';\n\nexport default [\n {\n 'en-US': {\n [PWA_PLUGIN]: {\n 'need refresh label': 'Refresh now to get app updates',\n 'need refresh description': 'You’ll need these updates to continue without interruption.',\n 'refresh label': 'Refresh',\n 'refresh alt': 'Click your browser’s refresh button or use the refresh keyboard shortcut.',\n // TODO(wittjosiah): Non-react translation utils.\n // 'offline ready label': '{{appName}} is ready to use offline.',\n 'offline ready label': 'Ready to use offline.',\n 'confirm label': 'Okay',\n },\n },\n },\n];\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { PwaPlugin } from './PwaPlugin';\n\nexport default PwaPlugin;\n\nexport * from './PwaPlugin';\n"],
|
|
5
|
+
"mappings": ";;;;;;AAIA,SAASA,kBAAkB;AAE3B,SAASC,mBAAmBC,eAAsCC,oBAAoB;AACtF,SAASC,WAAW;AACpB,SAASC,wBAAwB;;;ACFjC,IAAA,uBAAe;EACb;IACE,SAAS;MACP,CAACC,UAAAA,GAAa;QACZ,sBAAsB;QACtB,4BAA4B;QAC5B,iBAAiB;QACjB,eAAe;;;QAGf,uBAAuB;QACvB,iBAAiB;MACnB;IACF;EACF;;;;;ADPK,IAAMC,YAAY,OAAyB;EAChDC;EACAC,OAAO,OAAOC,YAAAA;AACZ,UAAMC,WAAWC,cAAcF,SAASG,iBAAAA,GAAoBC,SAASC,OAAOJ;AAE5E,UAAMK,WAAWC,WAAW;MAC1BC,eAAe,MACbP,WAAW;QACTQ,QAAQC,aAAaC;QACrBC,MAAM;UACJC,SAAS;UACTC,SAAS;YACPC,IAAI,GAAGC,UAAAA;YACPC,OAAOC,qBAAa,CAAA,EAAG,OAAA,EAASF,UAAAA,EAAY,oBAAA;YAC5CG,aAAaD,qBAAa,CAAA,EAAG,OAAA,EAASF,UAAAA,EAAY,0BAAA;YAClDI,UAAU,IAAI,KAAK;YACnBC,aAAaH,qBAAa,CAAA,EAAG,OAAA,EAASF,UAAAA,EAAY,eAAA;YAClDM,WAAWJ,qBAAa,CAAA,EAAG,OAAA,EAASF,UAAAA,EAAY,aAAA;YAChDO,UAAU,MAAMjB,SAAS,IAAA;UAC3B;QACF;MACF,CAAA;MACFkB,gBAAgB,MACdvB,WAAW;QACTQ,QAAQC,aAAaC;QACrBC,MAAM;UACJC,SAAS;UACTC,SAAS;YACPC,IAAI,GAAGC,UAAAA;YACPC,OAAOC,qBAAa,CAAA,EAAG,OAAA,EAASF,UAAAA,EAAY,qBAAA;YAC5CS,YAAYP,qBAAa,CAAA,EAAG,OAAA,EAASF,UAAAA,EAAY,eAAA;UACnD;QACF;MACF,CAAA;MACFU,iBAAiB,CAACC,QAAAA;AAChBC,yBAAiBD,GAAAA;AACjBE,YAAIC,MAAMH,KAAAA,QAAAA;;;;;;MACZ;IACF,CAAA;EACF;AACF;;;AE/CA,IAAA,cAAeI;",
|
|
6
|
+
"names": ["registerSW", "parseIntentPlugin", "resolvePlugin", "LayoutAction", "log", "captureException", "PWA_PLUGIN", "PwaPlugin", "meta", "ready", "plugins", "dispatch", "resolvePlugin", "parseIntentPlugin", "provides", "intent", "updateSW", "registerSW", "onNeedRefresh", "action", "LayoutAction", "SET_LAYOUT", "data", "element", "subject", "id", "PWA_PLUGIN", "title", "translations", "description", "duration", "actionLabel", "actionAlt", "onAction", "onOfflineReady", "closeLabel", "onRegisterError", "err", "captureException", "log", "error", "PwaPlugin"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"inputs":{"packages/plugins/plugin-pwa/src/meta.ts":{"bytes":730,"imports":[],"format":"esm"},"packages/plugins/plugin-pwa/src/translations.ts":{"bytes":2353,"imports":[{"path":"packages/plugins/plugin-pwa/src/meta.ts","kind":"import-statement","original":"./meta"}],"format":"esm"},"packages/plugins/plugin-pwa/src/PwaPlugin.tsx":{"bytes":7317,"imports":[{"path":"virtual:pwa-register","kind":"import-statement","external":true},{"path":"@dxos/app-framework","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/observability/sentry","kind":"import-statement","external":true},{"path":"packages/plugins/plugin-pwa/src/meta.ts","kind":"import-statement","original":"./meta"},{"path":"packages/plugins/plugin-pwa/src/translations.ts","kind":"import-statement","original":"./translations"}],"format":"esm"},"packages/plugins/plugin-pwa/src/index.ts":{"bytes":743,"imports":[{"path":"packages/plugins/plugin-pwa/src/PwaPlugin.tsx","kind":"import-statement","original":"./PwaPlugin"},{"path":"packages/plugins/plugin-pwa/src/PwaPlugin.tsx","kind":"import-statement","original":"./PwaPlugin"}],"format":"esm"}},"outputs":{"packages/plugins/plugin-pwa/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":4565},"packages/plugins/plugin-pwa/dist/lib/browser/index.mjs":{"imports":[{"path":"packages/plugins/plugin-pwa/dist/lib/browser/chunk-WUGDEZKD.mjs","kind":"import-statement"},{"path":"virtual:pwa-register","kind":"import-statement","external":true},{"path":"@dxos/app-framework","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/observability/sentry","kind":"import-statement","external":true}],"exports":["PwaPlugin","default"],"entryPoint":"packages/plugins/plugin-pwa/src/index.ts","inputs":{"packages/plugins/plugin-pwa/src/PwaPlugin.tsx":{"bytesInOutput":1821},"packages/plugins/plugin-pwa/src/translations.ts":{"bytesInOutput":620},"packages/plugins/plugin-pwa/src/index.ts":{"bytesInOutput":29}},"bytes":2821},"packages/plugins/plugin-pwa/dist/lib/browser/meta.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"packages/plugins/plugin-pwa/dist/lib/browser/meta.mjs":{"imports":[{"path":"packages/plugins/plugin-pwa/dist/lib/browser/chunk-WUGDEZKD.mjs","kind":"import-statement"}],"exports":["PWA_PLUGIN","default"],"entryPoint":"packages/plugins/plugin-pwa/src/meta.ts","inputs":{},"bytes":155},"packages/plugins/plugin-pwa/dist/lib/browser/chunk-WUGDEZKD.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":316},"packages/plugins/plugin-pwa/dist/lib/browser/chunk-WUGDEZKD.mjs":{"imports":[],"exports":["PWA_PLUGIN","meta_default"],"inputs":{"packages/plugins/plugin-pwa/src/meta.ts":{"bytesInOutput":81}},"bytes":210}}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PwaPlugin.d.ts","sourceRoot":"","sources":["../../../src/PwaPlugin.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAoC,KAAK,gBAAgB,EAAgB,MAAM,qBAAqB,CAAC;AAO5G,eAAO,MAAM,SAAS,QAAO,gBAwC3B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,eAAe,SAAS,CAAC;AAEzB,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meta.d.ts","sourceRoot":"","sources":["../../../src/meta.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,UAAU,wBAAwB,CAAC;;;;AAEhD,wBAEE"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
'en-US': {
|
|
3
|
+
"dxos.org/plugin/pwa": {
|
|
4
|
+
'need refresh label': string;
|
|
5
|
+
'need refresh description': string;
|
|
6
|
+
'refresh label': string;
|
|
7
|
+
'refresh alt': string;
|
|
8
|
+
'offline ready label': string;
|
|
9
|
+
'confirm label': string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
}[];
|
|
13
|
+
export default _default;
|
|
14
|
+
//# sourceMappingURL=translations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translations.d.ts","sourceRoot":"","sources":["../../../src/translations.ts"],"names":[],"mappings":";;;;;;;;;;;;AAMA,wBAeE"}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dxos/plugin-pwa",
|
|
3
|
+
"version": "0.6.8-main.046e6cf",
|
|
4
|
+
"description": "DXOS Surface plugin for PWA registration and update handling.",
|
|
5
|
+
"homepage": "https://dxos.org",
|
|
6
|
+
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"author": "DXOS.org",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"browser": "./dist/lib/browser/index.mjs",
|
|
12
|
+
"types": "./dist/types/src/index.d.ts"
|
|
13
|
+
},
|
|
14
|
+
"./meta": {
|
|
15
|
+
"browser": "./dist/lib/browser/meta.mjs",
|
|
16
|
+
"types": "./dist/types/src/meta.d.ts"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"types": "dist/types/src/index.d.ts",
|
|
20
|
+
"typesVersions": {
|
|
21
|
+
"*": {
|
|
22
|
+
"meta": [
|
|
23
|
+
"dist/types/src/meta.d.ts"
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"src"
|
|
30
|
+
],
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@dxos/app-framework": "0.6.8-main.046e6cf",
|
|
33
|
+
"@dxos/log": "0.6.8-main.046e6cf",
|
|
34
|
+
"@dxos/observability": "0.6.8-main.046e6cf",
|
|
35
|
+
"@dxos/react-ui": "0.6.8-main.046e6cf",
|
|
36
|
+
"@dxos/react-ui-theme": "0.6.8-main.046e6cf"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@phosphor-icons/react": "^2.1.5",
|
|
40
|
+
"@types/react": "~18.2.0",
|
|
41
|
+
"@types/react-dom": "~18.2.0",
|
|
42
|
+
"react": "~18.2.0",
|
|
43
|
+
"react-dom": "~18.2.0",
|
|
44
|
+
"vite": "^5.3.4",
|
|
45
|
+
"vite-plugin-pwa": "^0.18.2",
|
|
46
|
+
"workbox-window": "^7.0.0",
|
|
47
|
+
"@dxos/storybook-utils": "0.6.8-main.046e6cf"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"@phosphor-icons/react": "^2.1.5",
|
|
51
|
+
"react": "^18.0.0"
|
|
52
|
+
},
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"access": "public"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { registerSW } from 'virtual:pwa-register';
|
|
6
|
+
|
|
7
|
+
import { parseIntentPlugin, resolvePlugin, type PluginDefinition, LayoutAction } from '@dxos/app-framework';
|
|
8
|
+
import { log } from '@dxos/log';
|
|
9
|
+
import { captureException } from '@dxos/observability/sentry';
|
|
10
|
+
|
|
11
|
+
import meta, { PWA_PLUGIN } from './meta';
|
|
12
|
+
import translations from './translations';
|
|
13
|
+
|
|
14
|
+
export const PwaPlugin = (): PluginDefinition => ({
|
|
15
|
+
meta,
|
|
16
|
+
ready: async (plugins) => {
|
|
17
|
+
const dispatch = resolvePlugin(plugins, parseIntentPlugin)?.provides.intent.dispatch;
|
|
18
|
+
|
|
19
|
+
const updateSW = registerSW({
|
|
20
|
+
onNeedRefresh: () =>
|
|
21
|
+
dispatch?.({
|
|
22
|
+
action: LayoutAction.SET_LAYOUT,
|
|
23
|
+
data: {
|
|
24
|
+
element: 'toast',
|
|
25
|
+
subject: {
|
|
26
|
+
id: `${PWA_PLUGIN}/need-refresh`,
|
|
27
|
+
title: translations[0]['en-US'][PWA_PLUGIN]['need refresh label'],
|
|
28
|
+
description: translations[0]['en-US'][PWA_PLUGIN]['need refresh description'],
|
|
29
|
+
duration: 4 * 60 * 1000, // 4m
|
|
30
|
+
actionLabel: translations[0]['en-US'][PWA_PLUGIN]['refresh label'],
|
|
31
|
+
actionAlt: translations[0]['en-US'][PWA_PLUGIN]['refresh alt'],
|
|
32
|
+
onAction: () => updateSW(true),
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
}),
|
|
36
|
+
onOfflineReady: () =>
|
|
37
|
+
dispatch?.({
|
|
38
|
+
action: LayoutAction.SET_LAYOUT,
|
|
39
|
+
data: {
|
|
40
|
+
element: 'toast',
|
|
41
|
+
subject: {
|
|
42
|
+
id: `${PWA_PLUGIN}/offline-ready`,
|
|
43
|
+
title: translations[0]['en-US'][PWA_PLUGIN]['offline ready label'],
|
|
44
|
+
closeLabel: translations[0]['en-US'][PWA_PLUGIN]['confirm label'],
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
}),
|
|
48
|
+
onRegisterError: (err) => {
|
|
49
|
+
captureException(err);
|
|
50
|
+
log.error(err);
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
});
|
package/src/index.ts
ADDED
package/src/meta.ts
ADDED
package/src/pwa.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2022 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { PWA_PLUGIN } from './meta';
|
|
6
|
+
|
|
7
|
+
export default [
|
|
8
|
+
{
|
|
9
|
+
'en-US': {
|
|
10
|
+
[PWA_PLUGIN]: {
|
|
11
|
+
'need refresh label': 'Refresh now to get app updates',
|
|
12
|
+
'need refresh description': 'You’ll need these updates to continue without interruption.',
|
|
13
|
+
'refresh label': 'Refresh',
|
|
14
|
+
'refresh alt': 'Click your browser’s refresh button or use the refresh keyboard shortcut.',
|
|
15
|
+
// TODO(wittjosiah): Non-react translation utils.
|
|
16
|
+
// 'offline ready label': '{{appName}} is ready to use offline.',
|
|
17
|
+
'offline ready label': 'Ready to use offline.',
|
|
18
|
+
'confirm label': 'Okay',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
];
|