custom menus, tray
custom menus, tray

file:a/main.js -> file:b/main.js
--- a/main.js
+++ b/main.js
@@ -5,86 +5,108 @@
 const app = electron.app;
 // Module to create native browser window.
 const BrowserWindow = electron.BrowserWindow;
+const globalShortcut = electron.globalShortcut;
 
-const Menu = electron.Menu;
-const Tray = electron.Tray;
+const path = require('path');
+const AppMenus = require("./menus.js");
 
 // Keep a global reference of the window object, if you don't, the window will
 // be closed automatically when the JavaScript object is garbage collected.
 let mainWindow;
 
-function createWindow () {
-  // Create the browser window.
-  mainWindow = new BrowserWindow({width: 800, height: 600, show: false});
+function createWindow() {
+    // Create the browser window.
+    var electronScreen = electron.screen;
+    var size = electronScreen.getPrimaryDisplay().workAreaSize;
+    var width = 9 * size.width/10;
+    var height = 9 * size.height/10;
+    mainWindow = new BrowserWindow({width: width, height: height, show: true, skipTaskbar: true});
+    //mainWindow = new BrowserWindow({width: 1000, height: 800, show: false});
 
-  // and load the index.html of the app.
-  mainWindow.loadURL('file://' + __dirname + '/index.html');
+    // and load the index.html of the app.
+    //mainWindow.loadURL('file://' + __dirname + '/index.html');
+    mainWindow.loadURL('http://deadline-app.dev.webstyler.ro/backend_base/backend-dashboard');
 
-  // Open the DevTools.
-  //mainWindow.webContents.openDevTools();
+    // Open the DevTools.
+    //mainWindow.webContents.openDevTools();
 
-  // Emitted when the window is closed.
-  mainWindow.on('closed', function() {
-    // Dereference the window object, usually you would store windows
-    // in an array if your app supports multi windows, this is the time
-    // when you should delete the corresponding element.
-    mainWindow = null;
-  });
+    // Emitted when the window is closed.
+    mainWindow.on('closed', function() {
+        // Dereference the window object, usually you would store windows
+        // in an array if your app supports multi windows, this is the time
+        // when you should delete the corresponding element.
+        mainWindow = null;
+    });
 
-  // Emitted when the window is closed.
-  mainWindow.on('close', function() {
-      this.hide();
-  });
+    // Emitted when the window is closed.
+    mainWindow.on('close', function(event) {
+        event.preventDefault();
+        this.hide();
+    });
 
-  mainWindow.on('minimize', function() {
+    mainWindow.on('minimize', function() {
         // Hide window
         this.hide();
-  });
+    });
 
-  var appIcon = null;
-  appIcon = new Tray('app.ico');
-  var contextMenu = Menu.buildFromTemplate([
-    {
-      label: 'Show',
-      accelerator: 'Alt+Command+S',
-      click: function() {
-        mainWindow.show();
-      }
-    },
-    {
-      label: 'Toggle DevTools',
-      accelerator: 'Alt+Command+I',
-      click: function() {
-        mainWindow.show();
-        mainWindow.toggleDevTools();
-      }
-    },
-    { label: 'Quit',
-      accelerator: 'Command+Q',
-      selector: 'terminate:',
+    /*mainWindow.setThumbarButtons([
+        {
+            tooltip: "button1",
+            icon: path.join(__dirname, 'button1.png'),
+            click: function() { console.log("button2 clicked"); }
+        }
+    ]);*/
+    mainWindow.setAutoHideMenuBar(true);
+
+    /*new Notification('Demo', {
+        body: 'Notification with icon',
+        icon: 'icon.ico'
+    });*/
+
+    var ap = new AppMenus(mainWindow, electron).render();
+
+    var accelerator = 'CmdOrCtrl+Shift+D';
+    if (globalShortcut.isRegistered(accelerator) == false) {
+        globalShortcut.register(accelerator, function() {
+            mainWindow.show();
+        });
     }
-  ]);
-  appIcon.setToolTip('This is my application.');
-  appIcon.setContextMenu(contextMenu);
 }
 
 // This method will be called when Electron has finished
 // initialization and is ready to create browser windows.
 app.on('ready', createWindow);
 
+app.on('will-quit', function(event) {
+    globalShortcut.unregisterAll();
+});
+
 // Quit when all windows are closed.
-app.on('window-all-closed', function () {
-  // On OS X it is common for applications and their menu bar
-  // to stay active until the user quits explicitly with Cmd + Q
-  if (process.platform !== 'darwin') {
-    app.quit();
-  }
+app.on('window-all-closed', function (event) {
+    // On OS X it is common for applications and their menu bar
+    // to stay active until the user quits explicitly with Cmd + Q
+    if (process.platform !== 'darwin') {
+        app.quit();
+    }
 });
 
 app.on('activate', function () {
-  // On OS X it's common to re-create a window in the app when the
-  // dock icon is clicked and there are no other windows open.
-  if (mainWindow === null) {
-    createWindow();
-  }
+    // On OS X it's common to re-create a window in the app when the
+    // dock icon is clicked and there are no other windows open.
+    if (mainWindow === null) {
+        createWindow();
+    }
 });
+
+var shouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory) {
+    if (mainWindow) {
+        mainWindow.show();
+        if (mainWindow.isMinimized()) mainWindow.restore();
+            mainWindow.focus();
+        }
+    return true;
+});
+
+if (shouldQuit) {
+    app.exit(0);
+}

file:b/menus.js (new)
--- /dev/null
+++ b/menus.js
@@ -1,1 +1,171 @@
+'use strict';
 
+let app;
+let Menu;
+let Tray;
+let globalShortcut;
+let mainWindow;
+
+function AppMenus(win, electron){
+    mainWindow = win;
+    app = electron.app;
+    Menu = electron.Menu;
+    Tray = electron.Tray;
+    globalShortcut = electron.globalShortcut;
+
+    return this;
+}
+
+AppMenus.prototype.tray = function() {
+    var appIcon = null;
+    appIcon = new Tray('app.ico');
+    var contextMenu = Menu.buildFromTemplate([
+        {
+            label: 'Show',
+            accelerator: 'CmdOrCtrl+Shift+D',
+            click: function() {
+                mainWindow.show();
+            }
+        },
+        {
+            label: 'Toggle DevTools',
+            click: function() {
+                mainWindow.show();
+                mainWindow.toggleDevTools();
+            }
+        },
+        {
+            label: 'Quit',
+            selector: 'terminate:',
+            click: function() {
+                app.exit(0);
+            }
+        }
+    ]);
+    appIcon.setToolTip('DeadlineApp by Webstyler');
+    appIcon.setContextMenu(contextMenu);
+    appIcon.on('double-click', function() {
+        mainWindow.show();
+    });
+    appIcon.on('click', function() {
+        mainWindow.show();
+    });
+}
+
+AppMenus.prototype.menu = function() {
+   var template = [
+      {
+        label: 'Edit',
+        submenu: [
+          {
+            label: 'Undo',
+            accelerator: 'CmdOrCtrl+Z',
+            role: 'undo'
+          },
+          {
+            label: 'Redo',
+            accelerator: 'Shift+CmdOrCtrl+Z',
+            role: 'redo'
+          },
+          {
+            type: 'separator'
+          },
+          {
+            label: 'Cut',
+            accelerator: 'CmdOrCtrl+X',
+            role: 'cut'
+          },
+          {
+            label: 'Copy',
+            accelerator: 'CmdOrCtrl+C',
+            role: 'copy'
+          },
+          {
+            label: 'Paste',
+            accelerator: 'CmdOrCtrl+V',
+            role: 'paste'
+          },
+          {
+            label: 'Select All',
+            accelerator: 'CmdOrCtrl+A',
+            role: 'selectall'
+          },
+        ]
+      },
+      {
+        label: 'View',
+        submenu: [
+          {
+            label: 'Reload',
+            accelerator: 'F5',
+            click: function(item, focusedWindow) {
+              if (focusedWindow)
+                focusedWindow.reload();
+            }
+          },
+          {
+            label: 'Toggle Full Screen',
+            accelerator: (function() {
+              if (process.platform == 'darwin')
+                return 'Ctrl+Command+F';
+              else
+                return 'F11';
+            })(),
+            click: function(item, focusedWindow) {
+              if (focusedWindow)
+                focusedWindow.setFullScreen(!focusedWindow.isFullScreen());
+            }
+          },
+          {
+            label: 'Toggle Developer Tools',
+            accelerator: (function() {
+              if (process.platform == 'darwin')
+                return 'Alt+Command+I';
+              else
+                return 'Ctrl+Shift+I';
+            })(),
+            click: function(item, focusedWindow) {
+              if (focusedWindow)
+                focusedWindow.toggleDevTools();
+            }
+          },
+        ]
+      },
+      {
+        label: 'Window',
+        role: 'window',
+        submenu: [
+            {
+                label: 'Minimize',
+                accelerator: 'CmdOrCtrl+M',
+                role: 'minimize'
+            },
+            {
+                label: 'Close',
+                accelerator: 'CmdOrCtrl+W',
+                role: 'close'
+            },
+        ]
+      },
+      /*{
+        label: 'Help',
+        role: 'help',
+        submenu: [
+          {
+            label: 'Learn More',
+            click: function() { require('electron').shell.openExternal('http://electron.atom.io') }
+          },
+        ]
+      },*/
+    ];
+
+    var menu = Menu.buildFromTemplate(template);
+    Menu.setApplicationMenu(menu);
+}
+
+AppMenus.prototype.render = function() {
+    this.tray();
+    this.menu();
+}
+
+module.exports = AppMenus;

--- a/package.json
+++ b/package.json
@@ -1,5 +1,5 @@
 {
-  "name"    : "demo",
+  "name"    : "deadline",
   "version" : "0.1.0",
   "main"    : "main.js"
 }

comments