Reputation: 1364
Perhaps I'm being stupid but I can't seem to find any documentation on how to get the startup arguments for an electron app. My scenario is something like this:
I can get the electron app to open, but how do I work with the file that was right-clicked?
Upvotes: 2
Views: 1972
Reputation: 165
try {
var electron = require('electron');
var app = electron.remote;
if (app.process.platform == 'win32' && app.process.argv.length >= 2) {
var openFilePath = app.process.argv[1];
if (openFilePath !== "") {
console.log(openFilePath);
}
}
} catch (e) {
}
Upvotes: 1
Reputation: 2800
Assuming that you have the "Open with" portion working, Windows will pass the filename as a command line argument. So just get the file name/path from process.argv
if(process.argv.length >= 2) {
let filePath = process.argv[1];
//open, read, handle file
}
Upvotes: 4