mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-24 17:26:06 +08:00
58 lines
1.4 KiB
CoffeeScript
58 lines
1.4 KiB
CoffeeScript
|
{Emitter, Disposable} = require 'event-kit'
|
||
|
Notification = require '../src/notification'
|
||
|
|
||
|
# Experimental: Allows messaging the user. This will likely change, dont use
|
||
|
# quite yet!
|
||
|
module.exports =
|
||
|
class NotificationManager
|
||
|
constructor: ->
|
||
|
@notifications = []
|
||
|
@emitter = new Emitter
|
||
|
|
||
|
###
|
||
|
Section: Events
|
||
|
###
|
||
|
|
||
|
onDidAddNotification: (callback) ->
|
||
|
@emitter.on 'did-add-notification', callback
|
||
|
|
||
|
###
|
||
|
Section: Adding Notifications
|
||
|
###
|
||
|
|
||
|
addSuccess: (message, options) ->
|
||
|
@addNotification(new Notification('success', message, options))
|
||
|
|
||
|
addInfo: (message, options) ->
|
||
|
@addNotification(new Notification('info', message, options))
|
||
|
|
||
|
addWarning: (message, options) ->
|
||
|
@addNotification(new Notification('warning', message, options))
|
||
|
|
||
|
addError: (message, options) ->
|
||
|
@addNotification(new Notification('error', message, options))
|
||
|
|
||
|
addFatalError: (message, options) ->
|
||
|
@addNotification(new Notification('fatal', message, options))
|
||
|
|
||
|
add: (type, message, options) ->
|
||
|
@addNotification(new Notification(type, message, options))
|
||
|
|
||
|
addNotification: (notification) ->
|
||
|
@notifications.push(notification)
|
||
|
@emitter.emit('did-add-notification', notification)
|
||
|
notification
|
||
|
|
||
|
###
|
||
|
Section: Getting Notifications
|
||
|
###
|
||
|
|
||
|
getNotifications: -> @notifications
|
||
|
|
||
|
###
|
||
|
Section: Managing Notifications
|
||
|
###
|
||
|
|
||
|
clear: ->
|
||
|
@notifications = []
|