• Hello,
    I would like to improve your plugin with one more functionality.

    My idea is to add inside the widget popup a checkbox and some icons to let users to add my web app to his device, in this way with only one click they can accept notification and add web app to home screen in mobile or desktop (when supported).

    I have already developed a button in my web site, so I should only embed the code inside the widget and develope a logic for the checkbox (if checkbox is checked then when users accept notification also add web app).

    This is my code, it works with onclick event on a button with addweb class:

    if ('serviceWorker' in navigator) {
      navigator.serviceWorker
        .register('/sw.js')
        .then(() => { console.log('Service Worker Registered'); });
    }
    
    // Code to handle install prompt on desktop
    
    let deferredPrompt;
    const addBtn = document.querySelector('.addweb');
    addBtn.style.display = 'none';
    
    window.addEventListener('beforeinstallprompt', (e) => {
      // Prevent Chrome 67 and earlier from automatically showing the prompt
      e.preventDefault();
      // Stash the event so it can be triggered later.
      deferredPrompt = e;
      // Update UI to notify the user they can add to home screen
      addBtn.style.display = 'inline-block';
    
      addBtn.addEventListener('click', () => {
        // hide our user interface that shows our A2HS button
        addBtn.style.display = 'none';
    
        // Show the prompt
        deferredPrompt.prompt();
        // Wait for the user to respond to the prompt
        deferredPrompt.userChoice.then((choiceResult) => {
          if (choiceResult.outcome === 'accepted') {
            console.log('User accepted the Add Web App prompt');
          } else {
            console.log('User dismissed the Add Web App prompt');
          }
          deferredPrompt = null;
        });
      });
    });
    

    In admin panel the best solution should be add a checkbox and a text field for:
    – activate the checkbox in widget popup, for example: add a chekbox to install web app
    – add a field to show text next to the checkbox for example: Install our Web App to you device.

    Can you give me some tip to edit / develope your code?
    Do you offer a service of cutom code?
    Thank you.

Viewing 1 replies (of 1 total)
  • Plugin Author Perfecty

    (@perfecty)

    Hi Otta, absolutely you can do it and place any HTML element inside the widget programatically. You can put a sibling element next to the ‘perfecty-push-settings-subscribed’ label. You can do it after the plugin has been loaded.

    Currently we don’t have any JS hooks that you could use to know when we’ve draw the widget but maybe we can do it. We’ve added a ticket here: https://github.com/perfectyorg/perfecty-push-wp/issues/144

    If you still need to contact us, please do it through our web page: https://perfecty.org/contact

    Regards,

    Perfecty Team

Viewing 1 replies (of 1 total)
  • The topic ‘Custom Code in Widget Popup’ is closed to new replies.