// Electron entry point

var app = require("app");
var BrowserWindow = require("browser-window");
var shortcuts = require("global-shortcut");
var path = require("path");

require("crash-reporter").start();

var mainWindow = null;

app.on("ready", function() {
    mainWindow = new BrowserWindow({
        width: 800,
        height: 560,
        frame: false,
        resizable: true,
        icon: path.join(__dirname, "/icons/icon32.png")
    });

    // and load the index.html of the app.
    mainWindow.loadUrl(path.join(__dirname, "index.html"));

    // Open the devtools.
    mainWindow.openDevTools();

    // Registed keyboard shortcuts
    var register_play = shortcuts.register("ctrl+alt+space", function(){
        mainWindow.webContents.send("ping", "play-pause");
    });

    var register_prev = shortcuts.register("ctrl+alt+left", function(){
        mainWindow.webContents.send("ping", "prev");
    });

    var register_next = shortcuts.register("ctrl+alt+right", function(){
        mainWindow.webContents.send("ping", "next");
    });

    // Windows thumbar
    // mainWindow.setThumbarButtons([
    //     {
    //         tooltip: "prev",
    //         icon: path.join(__dirname, "/icons/iconPrev.png"),
    //         click: function() {
    //             mainWindow.webContents.send("ping", "prev");
    //         }
    //     },
    //     {
    //         tooltip: "play/pause",
    //         icon: path.join(__dirname, "/icons/iconPlay.png"),
    //         click: function() {
    //             mainWindow.webContents.send("ping", "play-pause");
    //         }
    //     },
    //     {
    //         tooltip: "next",
    //         icon: path.join(__dirname, "/icons/iconNext.png"),
    //         click: function() {
    //             mainWindow.webContents.send("ping", "next");
    //         }

    //     }
    // ]);

    // Emitted when the window is closed.
    mainWindow.on("closed", function() {
        mainWindow = null;
    });
});

@@ -162,16 +162,72 @@
 %22path%22);
+%0Avar tray = require(%22tray%22);%0Avar menu = require(%22menu%22);
 %0A%0Arequir
@@ -278,16 +278,36 @@
  = null;
+%0Avar appIcon = null;
 %0A%0Aapp.on
@@ -515,24 +515,539 @@
 %22)%0A    %7D);%0A%0A
+    // Tray icon%0A    appIcon = new tray(path.join(__dirname, %22/icons/icon16.png%22));%0A    appIcon.setToolTip(%22blackbird%22);%0A    var trayMenu = menu.buildFromTemplate(%5B%0A        %7B%0A            label: %22Exit%22,%0A            click: function() %7B%0A                app.quit();%0A            %7D%0A        %7D%0A    %5D);%0A    appIcon.setContextMenu(trayMenu);%0A    appIcon.on(%22clicked%22, function() %7B%0A        if (mainWindow.isVisible()) %7B%0A            mainWindow.hide();%0A        %7D%0A        else %7B%0A            mainWindow.show();%0A        %7D%0A    %7D);%0A%0A
     // and l
@@ -1652,441 +1652,54 @@
  // 
-Windows thumbar%0A    // mainWindow.setThumbarButtons(%5B%0A    //     %7B%0A    //         tooltip: %22prev%22,%0A    //         icon: path.join(__dirname, %22/icons/iconPrev.png%22),%0A    //         click: function() %7B%0A    //             mainWindow.webContents.send(%22ping%22, %22prev%22);%0A    //         %7D%0A    //     %7D,%0A    //     %7B%0A    //         tooltip: %22play/pause%22,%0A    //         icon: path.join(__dirname, %22/icons/iconPlay.png%22),%0A    //         click:
+Hide on minimize%0A    mainWindow.on(%22minimize%22,
  fun
@@ -1709,34 +1709,23 @@
 on() %7B%0A 
-   //
        
-      
 mainWind
@@ -1731,328 +1731,21 @@
 dow.
-webContents.send(%22ping%22, %22play-pause%22);%0A    //         %7D%0A    //     %7D,%0A    //     %7B%0A    //         tooltip: %22next%22,%0A    //         icon: path.join(__dirname, %22/icons/iconNext.png%22),%0A    //         click: function() %7B%0A    //             mainWindow.webContents.send(%22ping%22, %22next%22);%0A    //         %7D%0A%0A    //     %7D%0A    // %5D
+hide();%0A    %7D
 );%0A%0A

Add tray icon