mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-16 21:58:39 -09:00
🎉 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:
parent
0128db9022
commit
07ef0079fa
4 changed files with 43 additions and 6 deletions
|
|
@ -6,6 +6,7 @@ const gaze = require('gaze');
|
||||||
const Config = require('electron-config');
|
const Config = require('electron-config');
|
||||||
const notify = require('./notify');
|
const notify = require('./notify');
|
||||||
const _paths = require('./config/paths');
|
const _paths = require('./config/paths');
|
||||||
|
const _openConfig = require('./config/open');
|
||||||
|
|
||||||
// local storage
|
// local storage
|
||||||
const winCfg = new Config({
|
const winCfg = new Config({
|
||||||
|
|
@ -123,6 +124,10 @@ exports.getConfig = function () {
|
||||||
return cfg.config;
|
return cfg.config;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.openConfig = function () {
|
||||||
|
return _openConfig();
|
||||||
|
};
|
||||||
|
|
||||||
exports.getPlugins = function () {
|
exports.getPlugins = function () {
|
||||||
return {
|
return {
|
||||||
plugins: cfg.plugins,
|
plugins: cfg.plugins,
|
||||||
|
|
|
||||||
33
app/config/open.js
Normal file
33
app/config/open.js
Normal 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));
|
||||||
|
}
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
// This menu label is overrided by OSX to be the appName
|
// This menu label is overrided by OSX to be the appName
|
||||||
// The label is set to appName here so it matches actual behavior
|
// 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 {accelerators} = require('../../accelerators');
|
||||||
const {confPath} = require('../../config/paths');
|
const {openConfig} = require('../../config');
|
||||||
|
|
||||||
module.exports = function () {
|
module.exports = function () {
|
||||||
return {
|
return {
|
||||||
|
|
@ -18,7 +18,7 @@ module.exports = function () {
|
||||||
label: 'Preferences...',
|
label: 'Preferences...',
|
||||||
accelerator: accelerators.preferences,
|
accelerator: accelerators.preferences,
|
||||||
click() {
|
click() {
|
||||||
shell.openItem(confPath);
|
openConfig();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
const {shell} = require('electron');
|
|
||||||
const {accelerators} = require('../../accelerators');
|
const {accelerators} = require('../../accelerators');
|
||||||
const {confPath} = require('../../config/paths');
|
const {openConfig} = require('../../config');
|
||||||
|
|
||||||
module.exports = function () {
|
module.exports = function () {
|
||||||
const submenu = [
|
const submenu = [
|
||||||
|
|
@ -52,7 +51,7 @@ module.exports = function () {
|
||||||
label: 'Preferences...',
|
label: 'Preferences...',
|
||||||
accelerator: accelerators.preferences,
|
accelerator: accelerators.preferences,
|
||||||
click() {
|
click() {
|
||||||
shell.openItem(confPath);
|
openConfig();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue