@@ -48,33 +48,42 @@ function saveBeforeInstallPromptEvent(evt) {
4848// Event handler for butInstall - Does the PWA installation.
4949function installPWA ( evt ) {
5050
51- // if able to install codeit
52- if ( deferredInstallPrompt ) {
53-
54- deferredInstallPrompt . prompt ( ) ;
55-
56- // Log user response to prompt.
57- deferredInstallPrompt . userChoice
58- . then ( ( choice ) => {
59- if ( choice . outcome === 'accepted' ) {
60-
61- console . log ( 'Accepted the install prompt' ) ;
62-
63- document . querySelectorAll ( '.btn.install' ) . forEach ( button => {
64-
65- button . classList . add ( 'loading' ) ;
66-
67- } ) ;
68-
69- } else {
70-
71- console . log ( 'Dismissed the install prompt' ) ;
72-
73- }
74-
75- deferredInstallPrompt = null ;
76-
77- } ) ;
51+ // if codeit isn't already installed
52+ if ( ! localStorage . getItem ( 'installed' ) ) {
53+
54+ // if able to install codeit
55+ if ( deferredInstallPrompt ) {
56+
57+ deferredInstallPrompt . prompt ( ) ;
58+
59+ // Log user response to prompt.
60+ deferredInstallPrompt . userChoice
61+ . then ( ( choice ) => {
62+ if ( choice . outcome === 'accepted' ) {
63+
64+ console . log ( 'Accepted the install prompt' ) ;
65+
66+ document . querySelectorAll ( '.btn.install' ) . forEach ( button => {
67+
68+ button . classList . add ( 'loading' ) ;
69+
70+ } ) ;
71+
72+ } else {
73+
74+ console . log ( 'Dismissed the install prompt' ) ;
75+
76+ }
77+
78+ deferredInstallPrompt = null ;
79+
80+ } ) ;
81+
82+ } else { // open in the browser
83+
84+ window . location . replace ( window . location . origin + '/full' ) ;
85+
86+ }
7887
7988 } else { // open in the browser
8089
@@ -118,8 +127,6 @@ document.querySelectorAll('.btn.install').forEach(button => {
118127
119128 button . classList . add ( 'installed' ) ;
120129
121- window . location . replace ( window . location . origin + '/full' ) ;
122-
123130 }
124131
125132 }
0 commit comments