cubiq / add-to-homescreen

Add to home screen call-out for mobile devices
http://cubiq.org/add-to-home-screen
2.29k stars 747 forks source link

Error when force show on desktop #260

Open gimox opened 7 years ago

gimox commented 7 years ago

forcing to show on desktop environment show error:

configuration

const addToHome = addToHomescreen({
      maxDisplayCount: 3,
      autostart: false,
      displayPace: 0
    });
addToHome.show()

error

TypeError: Cannot read property 'lastDisplayTime' of undefined
    at ath.Class.show (addtohomescreen.js:465)

Solution.

check this.session inside show method.

line 445:

show: function (force) {
      // don not start if session not exist
       if(!this.session) {
        return
    }
...
BumbleB2na commented 7 years ago

Not just for desktop but also in situations where plugin decides the popup has "already been shown on screen". I wanted to manually trigger the popup to show if you click a button, in case some people missed it the first time. To overcome this I had to set my [addToHomeVar].show = false; before triggering: [addToHomeVar].show(); - I would have rather just used [addToHomeVar].show(true); to force it.