Skip to content

Instantly share code, notes, and snippets.

@SomeKay
Last active August 21, 2018 05:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SomeKay/19c859e8cedd407bfdac to your computer and use it in GitHub Desktop.
Save SomeKay/19c859e8cedd407bfdac to your computer and use it in GitHub Desktop.
var remote = require('remote');
var Tray = remote.require('tray');
var Menu = remote.require('menu');
var path = require('path');
var trayIcon = null;
if (process.platform === 'darwin') {
trayIcon = new Tray(path.join(__dirname, 'img/tray-iconTemplate.png'));
}
else {
trayIcon = new Tray(path.join(__dirname, 'img/tray-icon-alt.png'));
}
var trayMenuTemplate = [
{
label: 'Sound machine',
enabled: false
},
{
label: 'Settings',
click: function () {
ipc.send('open-settings-window');
}
},
{
label: 'Quit',
click: function () {
ipc.send('close-main-window');
}
}
];
var trayMenu = Menu.buildFromTemplate(trayMenuTemplate);
trayIcon.setContextMenu(trayMenu);
@una
Copy link

una commented Sep 18, 2017

You'll need these variables to make it work:

const {ipcMain, ipcRenderer, dialog, session, app, BrowserWindow, remote} = require('electron');
const {Menu, Tray} = require('electron').remote;
const path = require('path');

@lornally
Copy link

lornally commented Jan 8, 2018

una is right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment