npm-pkg-hook 1.9.6 → 1.9.8

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/package.json CHANGED
@@ -47,5 +47,5 @@
47
47
  "rm": "rm -rf node_modules package-lock.json && npm i",
48
48
  "test": "echo \"Error: no test specified\" && exit 1"
49
49
  },
50
- "version": "1.9.6"
50
+ "version": "1.9.8"
51
51
  }
@@ -22,6 +22,7 @@ export * from './useUploadProducts'
22
22
  export * from './useAmountInput'
23
23
  export * from './useColorByLetters'
24
24
  export * from './newMessageSubscription'
25
+ export * from './usePWAInstall'
25
26
  export * from './useGetCookies'
26
27
  export * from './generateTemplate'
27
28
  export * from './isTokenExpired'
@@ -0,0 +1,38 @@
1
+ import { useState, useEffect } from 'react';
2
+
3
+ export const usePWAInstall = () => {
4
+ const [deferredPrompt, setDeferredPrompt] = useState(null);
5
+ const [isInstallable, setIsInstallable] = useState(false);
6
+
7
+ useEffect(() => {
8
+ const handleBeforeInstallPrompt = (e) => {
9
+ e.preventDefault(); // Evita que el navegador muestre el diálogo automáticamente
10
+ setDeferredPrompt(e); // Almacena el evento para que puedas llamarlo más tarde
11
+ setIsInstallable(true); // Marca que la PWA es instalable
12
+ };
13
+
14
+ window.addEventListener('beforeinstallprompt', handleBeforeInstallPrompt);
15
+
16
+ return () => {
17
+ window.removeEventListener('beforeinstallprompt', handleBeforeInstallPrompt);
18
+ };
19
+ }, []);
20
+
21
+ const installPWA = () => {
22
+ if (deferredPrompt) {
23
+ deferredPrompt.prompt();
24
+
25
+ deferredPrompt.userChoice.then((choiceResult) => {
26
+ if (choiceResult.outcome === 'accepted') {
27
+ console.log('User accepted the install prompt');
28
+ } else {
29
+ console.log('User dismissed the install prompt');
30
+ }
31
+ setDeferredPrompt(null); // Limpia el evento después de usarlo
32
+ setIsInstallable(false); // Oculta el botón de instalación
33
+ });
34
+ }
35
+ };
36
+
37
+ return { isInstallable, installPWA };
38
+ };
package/src/index.jsx CHANGED
@@ -2,3 +2,6 @@ export * from './hooks/index'
2
2
  export * from './utils'
3
3
  export * from './cookies'
4
4
  export * from './security/index'
5
+
6
+ // version
7
+ export { version } from '../package.json'