Reputation: 1
On my electron app I use electron.shell (shell.openItem()) to open file (docx, pdf, tiff, ...).
Now I want to close this file after one specific action.
There is a way to close it with electron API or node JS ?
thanks
Upvotes: 0
Views: 651
Reputation: 1244
As this is not possible in shell.openItem()
you maybe could use the node child process for this.
I have an App where I open unhandled Filetypes with
let child;
child = cp.exec(' "' + fullPath+'"', function (error, stdout, stderr) {
if (error) {
console.error(`exec error: ${error}`);
}
});
If the Application is closed by the user you can react via
child.on('close', function (code) {
//your code here
}
If you want to end the child process from electron it should be possible using child.kill()
Upvotes: 1
Reputation: 5446
shell.openItem() opens the respective file with whichever program the OS has referenced for that files type. Furthermore, it does not return a reference to the process that was opened.
This means that you have no idea what process the file has been opened in, and given the huge amount of possible programs that can open your the types of files you listed, you will have a hard time finding out that specific program.
Given these circumstances, I see no way of achieving what you want to achieve.
Upvotes: 2