Example #1
0
    var module = function(label, icons_path, controlPanelCallback, quitCallback)
    {
        idleIcon = {
            normal: icons_path + '/tray.png',
            pressed: icons_path + '/tray_pressed.png'
        };
        processIcon = {
            normal: icons_path + '/tray_process.png',
            pressed: icons_path + '/tray_process_pressed.png'
        };
        tray = new Tray(idleIcon.normal);
        tray.setToolTip(label);
        tray.setPressedImage(idleIcon.pressed);
        tray.setContextMenu(Menu.buildFromTemplate(
            [
                {
                    label: label,
                    enabled: false
                },
                {
                    type: 'separator'
                },
                {
                    label: 'Open control panel',
                    click: function()
                    {
                        controlPanelCallback();
                    }
                },
                {
                    type: 'separator'
                },
                {
                    label: 'About...',
                    selector: 'orderFrontStandardAboutPanel:'
                },
                {
                    label: 'Quit',
                    accelerator: 'Command+Q',
                    click: function()
                    {
                        quitCallback();
                    }
                }
            ]
        ));

        this.setIdle = function()
        {
            tray.setImage(idleIcon.normal);
            tray.setPressedImage(idleIcon.pressed);
        };

        this.setProcessing = function()
        {
            tray.setImage(processIcon.normal);
            tray.setPressedImage(processIcon.pressed);
        };
    };
Example #2
0
function createTray() {
  appIcon = new Tray(path.join(__dirname, 'media', 'logo-tray.png'));
  appIcon.setPressedImage(path.join(__dirname, 'media', 'logo-tray-white.png'));
  appIcon.setContextMenu(appMenu.trayMenu);

  appIcon.on('double-click', () => {
    mainWindow.show();
  });
}
Example #3
0
function showTray () {
  tray = new Tray(path.join(__dirname, '/assets/tray-icon-blackTemplate.png'))
  tray.setPressedImage(path.join(__dirname, '/assets/tray-icon-whiteTemplate.png'))

  let contextMenu = Menu.buildFromTemplate([
    {
      label: 'Ōryōki is recording',
      enabled: false
    },
    {
      type: 'separator'
    },
    {
      label: 'Stop Recording',
      accelerator: 'Cmd+Alt+Shift+P',
      click () {
        stopRecording()
      }
    }
  ])
  tray.setToolTip('Ōryōki • REC')
  tray.setContextMenu(contextMenu)
}
Example #4
0
app.on('ready', function() {
  if (shouldShowTrayIcon()) {
    // set up tray icon
    trayIcon = new Tray(trayImages.normal);
    if (process.platform === 'darwin') {
      trayIcon.setPressedImage(trayImages.clicked.normal);
      systemPreferences.subscribeNotification('AppleInterfaceThemeChangedNotification', (event, userInfo) => {
        switchMenuIconImages(trayImages, systemPreferences.isDarkMode());
        trayIcon.setImage(trayImages.normal);
      });
    }

    trayIcon.setToolTip(app.getName());
    trayIcon.on('click', function() {
      mainWindow.focus();
    });
    trayIcon.on('right-click', () => {
      trayIcon.popUpContextMenu();
    });
    trayIcon.on('balloon-click', function() {
      mainWindow.focus();
    });
    ipcMain.on('notified', function(event, arg) {
      if (process.platform === 'win32') {
        if (config.notifications.flashWindow === 2) {
          mainWindow.flashFrame(true);
        }
        // On Windows 8.1 and Windows 8, a shortcut with a Application User Model ID must be installed to the Start screen.
        // In current version, use tray balloon for notification
        if (osVersion.isLowerThanOrEqualWindows8_1()) {
          trayIcon.displayBalloon({
            icon: path.resolve(__dirname, 'resources/appicon.png'),
            title: arg.title,
            content: arg.options.body
          });
        }
      }
    });

    // Set overlay icon from dataURL
    // Set trayicon to show "dot"
    ipcMain.on('update-unread', function(event, arg) {
      if (process.platform === 'win32') {
        const overlay = arg.overlayDataURL ? nativeImage.createFromDataURL(arg.overlayDataURL) : null;
        mainWindow.setOverlayIcon(overlay, arg.description);
      }

      if (arg.mentionCount > 0) {
        trayIcon.setImage(trayImages.mention);
        if (process.platform === 'darwin') {
          trayIcon.setPressedImage(trayImages.clicked.mention);
        }
        trayIcon.setToolTip(arg.mentionCount + ' unread mentions');
      }
      else if (arg.unreadCount > 0) {
        trayIcon.setImage(trayImages.unread);
        if (process.platform === 'darwin') {
          trayIcon.setPressedImage(trayImages.clicked.unread);
        }
        trayIcon.setToolTip(arg.unreadCount + ' unread channels');
      }
      else {
        trayIcon.setImage(trayImages.normal);
        if (process.platform === 'darwin') {
          trayIcon.setPressedImage(trayImages.clicked.normal);
        }
        trayIcon.setToolTip(app.getName());
      }
    });
  }

  // Create the browser window.
  var bounds_info_path = path.resolve(app.getPath("userData"), "bounds-info.json");
  var window_options;
  try {
    window_options = JSON.parse(fs.readFileSync(bounds_info_path, 'utf-8'));
  }
  catch (e) {
    // follow Electron's defaults
    window_options = {};
  }
  if (process.platform === 'linux') {
    window_options.icon = path.resolve(__dirname, 'resources/appicon.png');
  }
  window_options.title = app.getName();
  mainWindow = new BrowserWindow(window_options);
  mainWindow.setFullScreenable(true); // fullscreenable option has no effect.
  if (window_options.maximized) {
    mainWindow.maximize();
  }
  if (window_options.fullscreen) {
    mainWindow.setFullScreen(true);
  }

  // and load the index.html of the app.
  mainWindow.loadURL('file://' + __dirname + '/browser/index.html');

  // Set application menu
  ipcMain.on('update-menu', (event, config) => {
    var app_menu = appMenu.createMenu(mainWindow, config);
    Menu.setApplicationMenu(app_menu);
  });
  ipcMain.emit('update-menu', true, config);

  // set up context menu for tray icon
  if (shouldShowTrayIcon()) {
    const tray_menu = require('./main/menus/tray').createDefault(mainWindow);
    trayIcon.setContextMenu(tray_menu);
  }

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

  var saveWindowState = function(file, window) {
    var window_state = window.getBounds();
    window_state.maximized = window.isMaximized();
    window_state.fullscreen = window.isFullScreen();
    try {
      fs.writeFileSync(bounds_info_path, JSON.stringify(window_state));
    }
    catch (e) {
      // [Linux] error happens only when the window state is changed before the config dir is creatied.
    }
  };

  mainWindow.on('close', function(event) {
    if (willAppQuit) { // when [Ctrl|Cmd]+Q
      saveWindowState(bounds_info_path, mainWindow);
    }
    else { // Minimize or hide the window for close button.
      event.preventDefault();
      switch (process.platform) {
        case 'win32':
        case 'linux':
          mainWindow.minimize();
          break;
        case 'darwin':
          mainWindow.hide();
          break;
        default:
      }
    }
  });

  // App should save bounds when a window is closed.
  // However, 'close' is not fired in some situations(shutdown, ctrl+c)
  // because main process is killed in such situations.
  // 'blur' event was effective in order to avoid this.
  // Ideally, app should detect that OS is shutting down.
  mainWindow.on('blur', function() {
    saveWindowState(bounds_info_path, mainWindow);
  });

  // 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;
  });

  // Deny drag&drop navigation in mainWindow.
  // Drag&drop is allowed in webview of index.html.
  mainWindow.webContents.on('will-navigate', function(event, url) {
    var dirname = __dirname;
    if (process.platform === 'win32') {
      dirname = '/' + dirname.replace(/\\/g, '/');
    }

    var index = url.indexOf('file://' + dirname);
    if (index !== 0) {
      event.preventDefault();
    }
  });
});
Example #5
0
 this.setProcessing = function()
 {
     tray.setImage(processIcon.normal);
     tray.setPressedImage(processIcon.pressed);
 };
Example #6
0
 this.setIdle = function()
 {
     tray.setImage(idleIcon.normal);
     tray.setPressedImage(idleIcon.pressed);
 };