const electron = require('electron');
  
class Notifier {
  constructor () {
    this.activeNotifications = 0;
    this.nextY = 0;
    this.gap = 0;
    this.queue = [];
    if (process.type === 'renderer') {
      this.BrowserWindow = electron.remote.BrowserWindow;
    } else {
      this.BrowserWindow = electron.BrowserWindow;
    }
  }

  notify (title, data) {
    const options = Object.assign({}, data);
    const size = electron.screen.getPrimaryDisplay().workAreaSize;
    let verticalSpace = 0;
    if (options.vertical && options.buttons && options.buttons.length) {
      verticalSpace = Math.min(options.buttons.length * 40, 80);
    } else {
      options.vertical = false;
    }
    const notificationWindow = new this.BrowserWindow({
      width: 440,
      height: 120 + verticalSpace,
      x: size.width - 440,
      //  TODO - is.windows()? pop up from bottom : pop down from top
      y: this.nextY,
      frame: false,
      transparent: true,
      minimizable: false,
      maximizable: false,
      alwaysOnTop: true,
      skipTaskbar: true,
      titleBarStyle: 'hidden',
      show: false
    });
    this.queue.push({ notificationWindow, title, options });
    this.showIfPending();
    return notificationWindow;
  }

  showIfPending () {
    if (this.queue.length === 0) {
      return;
    }
    this.activeNotifications++;

    const notification = this.queue.shift();
    const { title, options } = notification;
    let { notificationWindow } = notification;

    //  TODO - we have a lot of visible space between notifications - fix this
    this.nextY += notificationWindow.getBounds().height+this.gap;
    
    notificationWindow.loadURL('file://' + __dirname + '/assets/notification.html');

    notificationWindow.webContents.on('did-finish-load', () => {
      notificationWindow.show();
      notificationWindow.webContents.send('setup', title, options);
    })
    const timeout = setTimeout(() => {
      this.activeNotifications--;
      this.nextY -= notificationWindow.getBounds().height + this.gap;
      notificationWindow.close()
    }, options.duration || 4000);

    notificationWindow.on('click', () => {
      if (notificationWindow) {
        console.log('clicked');
      }
    });
    const currentWindow = electron.remote && electron.remote.getCurrentWindow()
    if (currentWindow) {
      currentWindow.on('close', () => {
        if (notificationWindow) {
          notificationWindow.removeAllListeners();
          notificationWindow.webContents.removeAllListeners();
        }
      });
    }
    this.showIfPending();
    notificationWindow.on('closed', () => {
      clearTimeout(timeout);
      notificationWindow = null;
    });
  }
}

module.exports = Notifier;

@@ -138,24 +138,47 @@
 is.gap = 0;%0A
+    this.maxStack = 7;%0A
     this.que
@@ -186,16 +186,16 @@
 e = %5B%5D;%0A
-
     if (
@@ -1333,32 +1333,135 @@
   return;%0A    %7D%0A
+    if(!(this.activeNotifications %3C this.maxStack)) %7B%0A    %09//TODO - enqueue until the next close%0A    %7D%0A
     this.activeN
@@ -2699,24 +2699,24 @@
 fPending();%0A
-
     notifica
@@ -2743,24 +2743,147 @@
 d', () =%3E %7B%0A
+      // TODO - do a pretty slide up/down to collapse list if a notification in the middle closes out of order with others%0A
       clearT

add idea of maxStack + TODO's