Add shell menu feature (#1017)

* Add shell menu feature

* Rename and remove cofig option
This commit is contained in:
Liudas Dzisevicius 2016-11-22 14:06:03 +02:00 committed by Matheus Fernandes
parent ed76f4e4af
commit 0c30fc0bcf
3 changed files with 78 additions and 5 deletions

View file

@ -1,7 +1,30 @@
// eslint-disable-next-line curly, unicorn/no-process-exit
if (require('electron-squirrel-startup')) process.exit();
// handle startup squirrel events
if (process.platform === 'win32') {
// eslint-disable-next-line import/order
const systemContextMenu = require('./system-context-menu');
switch (process.argv[1]) {
case '--squirrel-install':
case '--squirrel-updated':
systemContextMenu.add(() => {
// eslint-disable-next-line curly, unicorn/no-process-exit
if (require('electron-squirrel-startup')) process.exit();
});
break;
case '--squirrel-uninstall':
systemContextMenu.remove(() => {
// eslint-disable-next-line curly, unicorn/no-process-exit
if (require('electron-squirrel-startup')) process.exit();
});
break;
default:
// eslint-disable-next-line curly, unicorn/no-process-exit
if (require('electron-squirrel-startup')) process.exit();
}
}
// Native
const {resolve} = require('path');
const {resolve, isAbsolute} = require('path');
// Packages
const {parse: parseUrl} = require('url');
@ -180,7 +203,7 @@ app.on('ready', () => installDevExtensions(isDev).then(() => {
}
});
rpc.on('new', ({rows = 40, cols = 100, cwd = process.env.HOME || process.env.HOMEPATH, splitDirection}) => {
rpc.on('new', ({rows = 40, cols = 100, cwd = process.argv[1] && isAbsolute(process.argv[1]) ? process.argv[1] : process.env.HOMEPATH || process.env.HOME, splitDirection}) => {
const shell = cfg.shell;
const shellArgs = cfg.shellArgs && Array.from(cfg.shellArgs);

View file

@ -26,6 +26,7 @@
"pty.js": "https://github.com/Tyriar/pty.js/tarball/c75c2dcb6dcad83b0cb3ef2ae42d0448fb912642",
"semver": "5.3.0",
"shell-env": "0.2.0",
"uuid": "3.0.0"
"uuid": "3.0.0",
"winreg": "1.2.2"
}
}

View file

@ -0,0 +1,49 @@
const Registry = require('winreg');
const appPath = `"${process.execPath}"`;
const regKey = `\\Software\\Classes\\Directory\\background\\shell\\Hyper`;
const regParts = [
{key: 'command', name: '', value: `${appPath} "%V"`},
{name: '', value: 'Open Hyper here'},
{name: 'Icon', value: `${appPath}`}
];
function isRegistered(callback) {
new Registry({
hive: 'HKCU',
key: `${regKey}\\${regParts[0].key}`
}).get(regParts[0].name, (err, entry) => {
callback(!err && entry && entry.value === regParts[0].value);
});
}
exports.add = function (callback) {
isRegistered(registered => {
if (!registered) {
const regPromises = [];
regParts.forEach(part => {
const reg = new Registry({hive: 'HKCU', key: part.key ? `${regKey}\\${part.key}` : regKey});
reg.create(() => {
regPromises.push(new Promise((resolve, reject) => {
reg.set(part.name, Registry.REG_SZ, part.value, err => {
if (err === null) {
resolve(true);
} else {
return reject(err);
}
});
}));
});
});
Promise.all(regPromises).then(() => callback());
}
});
};
exports.remove = function (callback) {
isRegistered(registered => {
if (registered) {
new Registry({hive: 'HKCU', key: regKey}).destroy(() => callback());
}
});
};