Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

use-before-install-prompt

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-before-install-prompt - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

39

dist/use-before-install-prompt.cjs.development.js

@@ -420,7 +420,9 @@ 'use strict';

var _useState = react.useState(false),
isInstalled = _useState[0],
setIsInstalled = _useState[1];
var _useState = react.useState(),
beforeInstallPromptEvent = _useState[0],
setBeforeInstallPromptEvent = _useState[1];
var beforeInstallPromptEvent = react.useRef();
var _useState2 = react.useState(false),
isInstalled = _useState2[0],
setIsInstalled = _useState2[1];

@@ -435,3 +437,3 @@ var addToHomeScreen = /*#__PURE__*/function () {

case 0:
if (beforeInstallPromptEvent.current) {
if (beforeInstallPromptEvent) {
_context.next = 2;

@@ -444,5 +446,5 @@ break;

case 2:
beforeInstallPromptEvent.current.prompt();
beforeInstallPromptEvent.prompt();
_context.next = 5;
return beforeInstallPromptEvent.current.userChoice;
return beforeInstallPromptEvent.userChoice;

@@ -454,5 +456,6 @@ case 5:

if (outcome === 'accepted') {
acceptedFn == null ? void 0 : acceptedFn();
setIsInstalled(true);
acceptedFn();
} else {
dismissedFn == null ? void 0 : dismissedFn();
dismissedFn();
}

@@ -476,3 +479,3 @@

e.preventDefault();
beforeInstallPromptEvent.current = e;
setBeforeInstallPromptEvent(e);
};

@@ -482,5 +485,5 @@

if (!beforeInstallPromptEvent.current) {
if (!beforeInstallPromptEvent) {
setIsInstalled(true);
installedFn == null ? void 0 : installedFn();
installedFn();
} else {

@@ -494,2 +497,14 @@ setIsInstalled(false);

}, [installedFn]);
react.useEffect(function () {
var handler = function handler() {
setIsInstalled(true); // For apply setIsInstalled(true) when install and popup new pwa
window.location.reload();
};
window.addEventListener('appinstalled', handler);
return function () {
window.removeEventListener('appinstalled', handler);
};
}, []);
return {

@@ -496,0 +511,0 @@ isInstalled: isInstalled,

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react");function r(){r=function(){return t};var t={},e=Object.prototype,n=e.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function u(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{u({},"")}catch(t){u=function(t,r,e){return t[r]=e}}function s(t,r,e,n){var o=Object.create((r&&r.prototype instanceof h?r:h).prototype),i=new O(n||[]);return o._invoke=function(t,r,e){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(e.method=o,e.arg=i;;){var a=e.delegate;if(a){var c=b(a,e);if(c){if(c===f)continue;return c}}if("next"===e.method)e.sent=e._sent=e.arg;else if("throw"===e.method){if("suspendedStart"===n)throw n="completed",e.arg;e.dispatchException(e.arg)}else"return"===e.method&&e.abrupt("return",e.arg);n="executing";var u=l(t,r,e);if("normal"===u.type){if(n=e.done?"completed":"suspendedYield",u.arg===f)continue;return{value:u.arg,done:e.done}}"throw"===u.type&&(n="completed",e.method="throw",e.arg=u.arg)}}}(t,e,i),o}function l(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var f={};function h(){}function p(){}function d(){}var v={};u(v,i,(function(){return this}));var y=Object.getPrototypeOf,g=y&&y(y(_([])));g&&g!==e&&n.call(g,i)&&(v=g);var m=d.prototype=h.prototype=Object.create(v);function w(t){["next","throw","return"].forEach((function(r){u(t,r,(function(t){return this._invoke(r,t)}))}))}function x(t,r){var e;this._invoke=function(o,i){function a(){return new r((function(e,a){!function e(o,i,a,c){var u=l(t[o],t,i);if("throw"!==u.type){var s=u.arg,f=s.value;return f&&"object"==typeof f&&n.call(f,"__await")?r.resolve(f.__await).then((function(t){e("next",t,a,c)}),(function(t){e("throw",t,a,c)})):r.resolve(f).then((function(t){s.value=t,a(s)}),(function(t){return e("throw",t,a,c)}))}c(u.arg)}(o,i,e,a)}))}return e=e?e.then(a,a):a()}}function b(t,r){var e=t.iterator[r.method];if(void 0===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=void 0,b(t,r),"throw"===r.method))return f;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return f}var n=l(e,t.iterator,r.arg);if("throw"===n.type)return r.method="throw",r.arg=n.arg,r.delegate=null,f;var o=n.arg;return o?o.done?(r[t.resultName]=o.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=void 0),r.delegate=null,f):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,f)}function L(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function E(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(L,this),this.reset(!0)}function _(t){if(t){var r=t[i];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var e=-1,o=function r(){for(;++e<t.length;)if(n.call(t,e))return r.value=t[e],r.done=!1,r;return r.value=void 0,r.done=!0,r};return o.next=o}}return{next:j}}function j(){return{value:void 0,done:!0}}return p.prototype=d,u(m,"constructor",d),u(d,"constructor",p),p.displayName=u(d,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===p||"GeneratorFunction"===(r.displayName||r.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,u(t,c,"GeneratorFunction")),t.prototype=Object.create(m),t},t.awrap=function(t){return{__await:t}},w(x.prototype),u(x.prototype,a,(function(){return this})),t.AsyncIterator=x,t.async=function(r,e,n,o,i){void 0===i&&(i=Promise);var a=new x(s(r,e,n,o),i);return t.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},w(m),u(m,c,"Generator"),u(m,i,(function(){return this})),u(m,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var r=[];for(var e in t)r.push(e);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=_,O.prototype={constructor:O,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(E),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function e(e,n){return a.type="throw",a.arg=t,r.next=e,n&&(r.method="next",r.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return e("end");if(i.tryLoc<=this.prev){var c=n.call(i,"catchLoc"),u=n.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return e(i.catchLoc,!0);if(this.prev<i.finallyLoc)return e(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return e(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return e(i.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var o=this.tryEntries[e];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,f):this.complete(a)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),f},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),E(e),f}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;E(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,e){return this.delegate={iterator:_(t),resultName:r,nextLoc:e},"next"===this.method&&(this.arg=void 0),f}},t}function e(t,r,e,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void e(t)}c.done?r(u):Promise.resolve(u).then(n,o)}function n(){return(n=Object.assign?Object.assign.bind():function(t){for(var r=1;r<arguments.length;r++){var e=arguments[r];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])}return t}).apply(this,arguments)}exports.default=function(o){var i=n({},o),a=i.acceptedFn,c=void 0===a?function(){return console.log("User accepted the A2HS prompt")}:a,u=i.dismissedFn,s=void 0===u?function(){return console.log("User dismissed the A2HS prompt")}:u,l=i.installedFn,f=void 0===l?function(){return console.log("Already installed")}:l,h=t.useState(!1),p=h[0],d=h[1],v=t.useRef(),y=function(){var t,n=(t=r().mark((function t(){return r().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(v.current){t.next=2;break}return t.abrupt("return",!1);case 2:return v.current.prompt(),t.next=5,v.current.userChoice;case 5:"accepted"===t.sent.outcome?null==c||c():null==s||s();case 8:case"end":return t.stop()}}),t)})),function(){var r=this,n=arguments;return new Promise((function(o,i){var a=t.apply(r,n);function c(t){e(a,o,i,c,u,"next",t)}function u(t){e(a,o,i,c,u,"throw",t)}c(void 0)}))});return function(){return n.apply(this,arguments)}}();return t.useEffect((function(){var t=function(t){t.preventDefault(),v.current=t};return window.addEventListener("beforeinstallprompt",t),v.current?d(!1):(d(!0),null==f||f()),function(){window.removeEventListener("beforeinstallprompt",t)}}),[f]),{isInstalled:p,addToHomeScreen:y}};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react");function e(){e=function(){return t};var t={},r=Object.prototype,n=r.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,r){return t[e]=r}}function s(t,e,r,n){var o=Object.create((e&&e.prototype instanceof h?e:h).prototype),i=new O(n||[]);return o._invoke=function(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=L(a,r);if(c){if(c===l)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=f(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===l)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(t,r,i),o}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var l={};function h(){}function p(){}function d(){}var v={};u(v,i,(function(){return this}));var y=Object.getPrototypeOf,g=y&&y(y(_([])));g&&g!==r&&n.call(g,i)&&(v=g);var m=d.prototype=h.prototype=Object.create(v);function w(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function x(t,e){var r;this._invoke=function(o,i){function a(){return new e((function(r,a){!function r(o,i,a,c){var u=f(t[o],t,i);if("throw"!==u.type){var s=u.arg,l=s.value;return l&&"object"==typeof l&&n.call(l,"__await")?e.resolve(l.__await).then((function(t){r("next",t,a,c)}),(function(t){r("throw",t,a,c)})):e.resolve(l).then((function(t){s.value=t,a(s)}),(function(t){return r("throw",t,a,c)}))}c(u.arg)}(o,i,r,a)}))}return r=r?r.then(a,a):a()}}function L(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,L(t,e),"throw"===e.method))return l;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var n=f(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,l;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,l):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,l)}function b(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function E(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(b,this),this.reset(!0)}function _(t){if(t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,o=function e(){for(;++r<t.length;)if(n.call(t,r))return e.value=t[r],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:j}}function j(){return{value:void 0,done:!0}}return p.prototype=d,u(m,"constructor",d),u(d,"constructor",p),p.displayName=u(d,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===p||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,u(t,c,"GeneratorFunction")),t.prototype=Object.create(m),t},t.awrap=function(t){return{__await:t}},w(x.prototype),u(x.prototype,a,(function(){return this})),t.AsyncIterator=x,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new x(s(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},w(m),u(m,c,"Generator"),u(m,i,(function(){return this})),u(m,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=_,O.prototype={constructor:O,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(E),!t)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function r(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var c=n.call(i,"catchLoc"),u=n.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return r(i.catchLoc,!0);if(this.prev<i.finallyLoc)return r(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return r(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return r(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,l):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),l},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),E(r),l}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;E(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:_(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),l}},t}function r(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function n(){return(n=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}exports.default=function(o){var i=n({},o),a=i.acceptedFn,c=void 0===a?function(){return console.log("User accepted the A2HS prompt")}:a,u=i.dismissedFn,s=void 0===u?function(){return console.log("User dismissed the A2HS prompt")}:u,f=i.installedFn,l=void 0===f?function(){return console.log("Already installed")}:f,h=t.useState(),p=h[0],d=h[1],v=t.useState(!1),y=v[0],g=v[1],m=function(){var t,n=(t=e().mark((function t(){return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(p){t.next=2;break}return t.abrupt("return",!1);case 2:return p.prompt(),t.next=5,p.userChoice;case 5:"accepted"===t.sent.outcome?(g(!0),c()):s();case 8:case"end":return t.stop()}}),t)})),function(){var e=this,n=arguments;return new Promise((function(o,i){var a=t.apply(e,n);function c(t){r(a,o,i,c,u,"next",t)}function u(t){r(a,o,i,c,u,"throw",t)}c(void 0)}))});return function(){return n.apply(this,arguments)}}();return t.useEffect((function(){var t=function(t){t.preventDefault(),d(t)};return window.addEventListener("beforeinstallprompt",t),p?g(!1):(g(!0),l()),function(){window.removeEventListener("beforeinstallprompt",t)}}),[l]),t.useEffect((function(){var t=function(){g(!0),window.location.reload()};return window.addEventListener("appinstalled",t),function(){window.removeEventListener("appinstalled",t)}}),[]),{isInstalled:y,addToHomeScreen:m}};
//# sourceMappingURL=use-before-install-prompt.cjs.production.min.js.map

@@ -1,2 +0,2 @@

import { useState, useRef, useEffect } from 'react';
import { useState, useEffect } from 'react';

@@ -416,7 +416,9 @@ function _regeneratorRuntime() {

var _useState = useState(false),
isInstalled = _useState[0],
setIsInstalled = _useState[1];
var _useState = useState(),
beforeInstallPromptEvent = _useState[0],
setBeforeInstallPromptEvent = _useState[1];
var beforeInstallPromptEvent = useRef();
var _useState2 = useState(false),
isInstalled = _useState2[0],
setIsInstalled = _useState2[1];

@@ -431,3 +433,3 @@ var addToHomeScreen = /*#__PURE__*/function () {

case 0:
if (beforeInstallPromptEvent.current) {
if (beforeInstallPromptEvent) {
_context.next = 2;

@@ -440,5 +442,5 @@ break;

case 2:
beforeInstallPromptEvent.current.prompt();
beforeInstallPromptEvent.prompt();
_context.next = 5;
return beforeInstallPromptEvent.current.userChoice;
return beforeInstallPromptEvent.userChoice;

@@ -450,5 +452,6 @@ case 5:

if (outcome === 'accepted') {
acceptedFn == null ? void 0 : acceptedFn();
setIsInstalled(true);
acceptedFn();
} else {
dismissedFn == null ? void 0 : dismissedFn();
dismissedFn();
}

@@ -472,3 +475,3 @@

e.preventDefault();
beforeInstallPromptEvent.current = e;
setBeforeInstallPromptEvent(e);
};

@@ -478,5 +481,5 @@

if (!beforeInstallPromptEvent.current) {
if (!beforeInstallPromptEvent) {
setIsInstalled(true);
installedFn == null ? void 0 : installedFn();
installedFn();
} else {

@@ -490,2 +493,14 @@ setIsInstalled(false);

}, [installedFn]);
useEffect(function () {
var handler = function handler() {
setIsInstalled(true); // For apply setIsInstalled(true) when install and popup new pwa
window.location.reload();
};
window.addEventListener('appinstalled', handler);
return function () {
window.removeEventListener('appinstalled', handler);
};
}, []);
return {

@@ -492,0 +507,0 @@ isInstalled: isInstalled,

@@ -5,3 +5,3 @@ {

"author": "Taesu Hyeon <email@qvil.dev>",
"version": "1.0.3",
"version": "1.0.4",
"license": "MIT",

@@ -8,0 +8,0 @@ "main": "dist/index.js",

@@ -1,2 +0,2 @@

import { useEffect, useRef, useState } from 'react';
import { useEffect, useState } from 'react';

@@ -11,16 +11,19 @@ import { BeforeInstallPromptEvent, Options, ReturnType } from './types';

} = { ...options };
const [beforeInstallPromptEvent, setBeforeInstallPromptEvent] = useState<
BeforeInstallPromptEvent
>();
const [isInstalled, setIsInstalled] = useState(false);
let beforeInstallPromptEvent = useRef<BeforeInstallPromptEvent>();
const addToHomeScreen = async () => {
if (!beforeInstallPromptEvent.current) return false;
if (!beforeInstallPromptEvent) return false;
beforeInstallPromptEvent.current.prompt();
beforeInstallPromptEvent.prompt();
const { outcome } = await beforeInstallPromptEvent.current.userChoice;
const { outcome } = await beforeInstallPromptEvent.userChoice;
if (outcome === 'accepted') {
acceptedFn?.();
setIsInstalled(true);
acceptedFn();
} else {
dismissedFn?.();
dismissedFn();
}

@@ -32,3 +35,3 @@ };

e.preventDefault();
beforeInstallPromptEvent.current = e;
setBeforeInstallPromptEvent(e);
};

@@ -38,5 +41,5 @@

if (!beforeInstallPromptEvent.current) {
if (!beforeInstallPromptEvent) {
setIsInstalled(true);
installedFn?.();
installedFn();
} else {

@@ -51,2 +54,16 @@ setIsInstalled(false);

useEffect(() => {
const handler = () => {
setIsInstalled(true);
// For apply setIsInstalled(true) when install and popup new pwa
window.location.reload();
};
window.addEventListener('appinstalled', handler);
return () => {
window.removeEventListener('appinstalled', handler);
};
}, []);
return { isInstalled, addToHomeScreen };

@@ -53,0 +70,0 @@ };

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc