2016-11-22 03:06:03 -09:00
|
|
|
const Registry = require('winreg');
|
|
|
|
|
|
|
|
|
|
const appPath = `"${process.execPath}"`;
|
|
|
|
|
const regKey = `\\Software\\Classes\\Directory\\background\\shell\\Hyper`;
|
|
|
|
|
const regParts = [
|
2018-04-16 06:17:17 -08:00
|
|
|
{key: 'command', name: '', value: `${appPath} "%V"`},
|
|
|
|
|
{name: '', value: 'Open Hyper here'},
|
|
|
|
|
{name: 'Icon', value: `${appPath}`}
|
2016-11-22 03:06:03 -09:00
|
|
|
];
|
|
|
|
|
|
2017-05-20 09:46:33 -08:00
|
|
|
function addValues(hyperKey, commandKey, callback) {
|
2018-04-16 06:17:17 -08:00
|
|
|
hyperKey.set(regParts[1].name, Registry.REG_SZ, regParts[1].value, error => {
|
|
|
|
|
if (error) {
|
|
|
|
|
//eslint-disable-next-line no-console
|
|
|
|
|
console.error(error.message);
|
2017-05-20 09:46:33 -08:00
|
|
|
}
|
|
|
|
|
hyperKey.set(regParts[2].name, Registry.REG_SZ, regParts[2].value, err => {
|
|
|
|
|
if (err) {
|
2018-04-16 06:17:17 -08:00
|
|
|
//eslint-disable-next-line no-console
|
2017-05-20 09:46:33 -08:00
|
|
|
console.error(err.message);
|
|
|
|
|
}
|
2018-04-16 06:17:17 -08:00
|
|
|
commandKey.set(regParts[0].name, Registry.REG_SZ, regParts[0].value, err_ => {
|
|
|
|
|
if (err_) {
|
|
|
|
|
//eslint-disable-next-line no-console
|
|
|
|
|
console.error(err_.message);
|
2017-05-20 09:46:33 -08:00
|
|
|
}
|
|
|
|
|
callback();
|
|
|
|
|
});
|
|
|
|
|
});
|
2016-11-22 03:06:03 -09:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-16 06:17:17 -08:00
|
|
|
exports.add = callback => {
|
2017-05-20 09:46:33 -08:00
|
|
|
const hyperKey = new Registry({hive: 'HKCU', key: regKey});
|
2018-04-16 06:17:17 -08:00
|
|
|
const commandKey = new Registry({
|
|
|
|
|
hive: 'HKCU',
|
|
|
|
|
key: `${regKey}\\${regParts[0].key}`
|
|
|
|
|
});
|
2017-05-20 09:46:33 -08:00
|
|
|
|
2018-04-16 06:17:17 -08:00
|
|
|
hyperKey.keyExists((error, exists) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
//eslint-disable-next-line no-console
|
|
|
|
|
console.error(error.message);
|
2017-05-20 09:46:33 -08:00
|
|
|
}
|
|
|
|
|
if (exists) {
|
2018-04-16 06:17:17 -08:00
|
|
|
commandKey.keyExists((err_, exists_) => {
|
|
|
|
|
if (err_) {
|
|
|
|
|
//eslint-disable-next-line no-console
|
|
|
|
|
console.error(err_.message);
|
2017-05-20 09:46:33 -08:00
|
|
|
}
|
2018-04-16 06:17:17 -08:00
|
|
|
if (exists_) {
|
2017-05-20 09:46:33 -08:00
|
|
|
addValues(hyperKey, commandKey, callback);
|
|
|
|
|
} else {
|
|
|
|
|
commandKey.create(err => {
|
|
|
|
|
if (err) {
|
2018-04-16 06:17:17 -08:00
|
|
|
//eslint-disable-next-line no-console
|
2017-05-20 09:46:33 -08:00
|
|
|
console.error(err.message);
|
|
|
|
|
}
|
|
|
|
|
addValues(hyperKey, commandKey, callback);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
hyperKey.create(err => {
|
|
|
|
|
if (err) {
|
2018-04-16 06:17:17 -08:00
|
|
|
//eslint-disable-next-line no-console
|
2017-05-20 09:46:33 -08:00
|
|
|
console.error(err.message);
|
|
|
|
|
}
|
2018-04-16 06:17:17 -08:00
|
|
|
commandKey.create(err_ => {
|
|
|
|
|
if (err_) {
|
|
|
|
|
//eslint-disable-next-line no-console
|
|
|
|
|
console.error(err_.message);
|
2017-05-20 09:46:33 -08:00
|
|
|
}
|
|
|
|
|
addValues(hyperKey, commandKey, callback);
|
2016-11-22 03:06:03 -09:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2018-04-16 06:17:17 -08:00
|
|
|
exports.remove = callback => {
|
2017-05-20 09:46:33 -08:00
|
|
|
new Registry({hive: 'HKCU', key: regKey}).destroy(err => {
|
|
|
|
|
if (err) {
|
2018-04-16 06:17:17 -08:00
|
|
|
//eslint-disable-next-line no-console
|
2017-05-20 09:46:33 -08:00
|
|
|
console.error(err.message);
|
2016-11-22 03:06:03 -09:00
|
|
|
}
|
2017-05-20 09:46:33 -08:00
|
|
|
callback();
|
2016-11-22 03:06:03 -09:00
|
|
|
});
|
|
|
|
|
};
|