Skip to content

Instantly share code, notes, and snippets.

@nishanths
Last active August 7, 2019 23:46
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nishanths/42eb1c00445f87a2dd6d to your computer and use it in GitHub Desktop.
Save nishanths/42eb1c00445f87a2dd6d to your computer and use it in GitHub Desktop.
Electron tray: Drag and Drop events demo
var app = require('app');
var Menu = require('menu');
var Tray = require('tray');
var appIcon = null;
app.on('ready', function(){
// image is null, so image will not be shown in menu bar
// so click around on the system menu bar to locate the space where the tray icon is
appIcon = new Tray(null);
var contextMenu = Menu.buildFromTemplate([
{ label: 'Item1', type: 'radio' },
{ label: 'Item2', type: 'radio' },
{ label: 'Item3', type: 'radio', checked: true },
{ label: 'Item4', type: 'radio' }
]);
appIcon.setToolTip('This is my application.');
appIcon.setContextMenu(contextMenu);
appIcon.on('drag-enter', function() {
console.log('drag-enter!');
});
appIcon.on('drag-leave', function() {
console.log('drag-leave!');
});
appIcon.on('drag-end', function() {
console.log('drag-end!');
});
appIcon.on('drop', function() {
console.log('drop!');
});
});
@veloxy
Copy link

veloxy commented Mar 9, 2016

For the people who end up here through google wondering how to drag and drop files 😊

appIcon.on('drop-files', function(event, files) {
  console.log('drop-files!');
  // Array with file paths!
  console.log(files);
});

@nishanths
Copy link
Author

Also, this is referenced in this atom/electron pull request.

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