Coder Social home page Coder Social logo

Comments (8)

jobisoft avatar jobisoft commented on September 26, 2024 1

I have this scheduled for tomorrow.

from developer-docs.

Alecaddd avatar Alecaddd commented on September 26, 2024 1

Great, thanks for taking care of this.
Notifications can be added almost anywhere as far as there's a container with an ID to use as a target.

Eg.

const myNotification = {};
XPCOMUtils.defineLazyGetter(myNotification, "notificationbox", () => {
    return new MozElements.NotificationBox(element => {
        element.setAttribute("flex", "1");
        document.getElementById("targetID").append(element);
    });
});

At that point, the developer can use myNotification.notificationbox to append his own notifications.

from developer-docs.

jobisoft avatar jobisoft commented on September 26, 2024

@Alecaddd : Could you have a look at
https://developer.thunderbird.net/add-ons/tb68/changes#less-than-notificationbox-greater-than

What happens, if the addon author wants to add a notification to a window, that does not have a notification box?

from developer-docs.

jobisoft avatar jobisoft commented on September 26, 2024

Wow! Would it then be the better "update strategy" to just rename the <notificationbox> to <hbox> in my code and do the above in JS? This way I do not have to search for the correct box?

Or should authors use the default notification box of messenger and composer? And the above is just for custom dialogs?

from developer-docs.

RealRaven2000 avatar RealRaven2000 commented on September 26, 2024

I knew that something like this should be possible - that JavaScript is something an average Add-on author would not be able to come up with so we definitely should add this to the documentation. I will try this out on my Add-on quickFilters where I currently show a notification panel in the filters dialog. The old overlay contained:

<panel id="quickFilterNotification" noautohide="true">  
  <notificationbox flex="1" id="quickFilterNotificationBox" >
    <!-- <notification type="warning" label="Test" id="quickFiltersNotificationContent"/> -->
  </notificationbox>
</panel>

and this was the main js code for displaying the notification:

util.popupAlert(
  util.getBundleString('quickfilters.debug.fixFilters.result','{0} filters were fixed.').replace('{0}',countFixed),
  "quickFilters", "debug-success.png", 0
);


popupAlert: function popupAlert(text, title, icon, timeOut) {
  try {
    let isTimeout = !(timeOut == 0);
    if (!timeOut) timeOut = 4000;
    let panel = document.getElementById('quickFilterNotification');
    if (panel) {
      panel.openPopup(null, "after_start", 0, 0, false, false);
      let notificationBox = document.getElementById('quickFilterNotificationBox'),
          priority = notificationBox.PRIORITY_WARNING_MEDIUM,
          note = notificationBox.appendNotification( text , null , icon , priority, null, null ); 
      notificationBox.addEventListener('alertclose', function() { alert('test'); });
      if (isTimeout)
        window.setTimeout(function() {try{notificationBox.removeNotification(note)}catch(e){};panel.hidePopup();}, timeOut);
    }
    else {
      let prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
                                    .getService(Components.interfaces.nsIPromptService);
      prompts.alert(window, title, text); 
    }
  }
  catch(e) {
    alert(text);
  }
}
  

from developer-docs.

Alecaddd avatar Alecaddd commented on September 26, 2024

@jobisoft, it really depends on the situation, but using built-in notification ensures visual consistency and style.

from developer-docs.

Alecaddd avatar Alecaddd commented on September 26, 2024

@RealRaven2000 Indeed, documenting this approach would be very useful for add-on developers.
It's a pretty easy implementation that depends on importing the XPCOMUtils object

from developer-docs.

jobisoft avatar jobisoft commented on September 26, 2024

I am sorry, I forgot about this one. I added it to the documentation.

from developer-docs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.