Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfix: opening file with preferred application on Windows
- Loading branch information
1 parent
449d627
commit 296ec21
Showing
1 changed file
with
2 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,10 @@ | ||
import formatFilePath from './formatFilePath'; | ||
|
||
const childProcess = require('child_process'); | ||
|
||
const getOpenProgramName = () => { | ||
switch (process.platform) { | ||
case 'darwin': | ||
return 'open'; | ||
case 'win32': | ||
return 'start'; | ||
case 'win64': | ||
return 'start'; | ||
default: | ||
return 'xdg-open'; | ||
} | ||
}; | ||
import { shell } from 'electron'; | ||
|
||
const openFileByName = (fileName) => { | ||
const filePath = formatFilePath(fileName); | ||
const openProgramProcess = childProcess.exec(`${getOpenProgramName()} "${filePath}"`); | ||
openProgramProcess.stderr.on('data', (data) => { | ||
console.log('Error while trying to open file:', data); | ||
}); | ||
shell.openItem(filePath); | ||
}; | ||
|
||
export default openFileByName; |