🎉 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
This commit is contained in:
Albin Ekblom 2017-05-26 18:23:25 +02:00 committed by Philippe Potvin
parent 0128db9022
commit 07ef0079fa
4 changed files with 43 additions and 6 deletions

View file

@ -6,6 +6,7 @@ const gaze = require('gaze');
const Config = require('electron-config');
const notify = require('./notify');
const _paths = require('./config/paths');
const _openConfig = require('./config/open');
// local storage
const winCfg = new Config({
@ -123,6 +124,10 @@ exports.getConfig = function () {
return cfg.config;
};
exports.openConfig = function () {
return _openConfig();
};
exports.getPlugins = function () {
return {
plugins: cfg.plugins,

33
app/config/open.js Normal file
View file

@ -0,0 +1,33 @@
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));
}

View file

@ -1,8 +1,8 @@
// This menu label is overrided by OSX to be the appName
// The label is set to appName here so it matches actual behavior
const {app, shell} = require('electron');
const {app} = require('electron');
const {accelerators} = require('../../accelerators');
const {confPath} = require('../../config/paths');
const {openConfig} = require('../../config');
module.exports = function () {
return {
@ -18,7 +18,7 @@ module.exports = function () {
label: 'Preferences...',
accelerator: accelerators.preferences,
click() {
shell.openItem(confPath);
openConfig();
}
},
{

View file

@ -1,6 +1,5 @@
const {shell} = require('electron');
const {accelerators} = require('../../accelerators');
const {confPath} = require('../../config/paths');
const {openConfig} = require('../../config');
module.exports = function () {
const submenu = [
@ -52,7 +51,7 @@ module.exports = function () {
label: 'Preferences...',
accelerator: accelerators.preferences,
click() {
shell.openItem(confPath);
openConfig();
}
}
);