Close notification onDidClick


#1

Consider the following notification which contains a button:

atom.notifications.addWarning(
  "This package currently works in Developer Mode only",
  dismissable: true,
  buttons: [
    {
      text: 'Open in Developer Mode'
      onDidClick: -> atom.commands.dispatch atom.views.getView(atom.workspace), 'application:open-dev'
    }
  ]
)

How can I close this notification once the button is clicked (without affecting other notifications?)


#2

atom.notifications.add* returns a Notification object, which can be dismissed with Notification.dismiss() method. So, something like this should work:

notification = atom.notifications.addWarning(
  "This package currently works in Developer Mode only",
  dismissable: true,
  buttons: [
    {
      text: 'Open in Developer Mode'
      onDidClick: ->
        atom.commands.dispatch atom.views.getView(atom.workspace), 'application:open-dev'
        notification.dismiss()
    }
  ]
)

Bear in mind I didn’t test it.


#3

Ah, I tried destroy() and dispose()dismiss()works fine, thank you!