56 lines
1.1 KiB
JavaScript
56 lines
1.1 KiB
JavaScript
var electron = require('electron');
|
|
var app = electron.app;
|
|
var ipc = electron.ipcMain;
|
|
|
|
var argv = sliceArgv(process.argv);
|
|
var win;
|
|
function init(window) {
|
|
if (win) {
|
|
console.error("can't initiliaze drag-and-drop multiple times");
|
|
return;
|
|
}
|
|
win = window;
|
|
|
|
ipc.once('ipcReady', function () {
|
|
app.ipcReady = true;
|
|
processArgv(argv);
|
|
});
|
|
}
|
|
|
|
app.on('open-file', onOpen);
|
|
app.on('open-url', onOpen);
|
|
function onOpen(e, filename) {
|
|
e.preventDefault();
|
|
|
|
if (app.ipcReady) {
|
|
processArgv([ filename ]);
|
|
} else {
|
|
argv.push(filename);
|
|
}
|
|
}
|
|
function sliceArgv(argv) {
|
|
var count = 1;
|
|
// We need to determine if we were run using electron or as a system installed app.
|
|
if (argv[0].search('electron') >= 0) {
|
|
count += 1;
|
|
}
|
|
return argv.slice(count);
|
|
}
|
|
|
|
function processArgv(argv) {
|
|
var files = [];
|
|
argv.forEach(function(arg) {
|
|
if (arg.substr(0 ,2) == '--') {
|
|
console.log('received argument', arg);
|
|
} else {
|
|
files.push(arg);
|
|
}
|
|
});
|
|
|
|
if (files.length > 0) {
|
|
win.webContents.send('files', files);
|
|
}
|
|
}
|
|
|
|
module.exports.init = init;
|