hyper/app/config/open.js
Albin Ekblom 07ef0079fa 🎉 Check for WScript.exe (#1872)
* 🎉 Check for WScript.exe

* 🔥 Move openConfig

* 🔥 Make openNotepad mimic openItem

* 🌹 Add comments

* 🔥 Cleanup windows workaround

* 🔥 Cleanup

* 🎉 Use openConfig on darwin too
2017-05-26 12:23:25 -04:00

33 lines
1 KiB
JavaScript

const {shell} = require('electron');
const {confPath} = require('./paths');
module.exports = () => Promise.resolve(shell.openItem(confPath));
if (process.platform === 'win32') {
const exec = require('child_process').exec;
// This mimics shell.openItem, true if it worked, false if not.
const openNotepad = file => new Promise(resolve => {
exec(`start notepad.exe ${file}`, error => {
resolve(!error);
});
});
// Windows opens .js files with WScript.exe by default
// If the user hasn't set up an editor for .js files, we fallback to notepad.
const canOpenNative = () => new Promise((resolve, reject) => {
exec('ftype JSFile', (error, stdout) => {
if (error) {
reject(error);
} else if (stdout && stdout.includes('WScript.exe')) {
reject(new Error('WScript is the default editor for .js files'));
} else {
resolve(true);
}
});
});
module.exports = () => canOpenNative()
.then(() => shell.openItem(confPath))
.catch(() => openNotepad(confPath));
}