2020-02-21 05:17:03 -09:00
|
|
|
import * as regTypes from './typings/native-reg';
|
|
|
|
|
if (process.platform === 'win32') {
|
|
|
|
|
try {
|
|
|
|
|
// eslint-disable-next-line no-var, @typescript-eslint/no-var-requires
|
|
|
|
|
var Registry: typeof regTypes = require('native-reg');
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error(err);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-22 03:06:03 -09:00
|
|
|
|
|
|
|
|
const appPath = `"${process.execPath}"`;
|
2020-02-21 05:17:03 -09:00
|
|
|
const regKey = `Software\\Classes\\Directory\\background\\shell\\Hyper`;
|
2016-11-22 03:06:03 -09:00
|
|
|
const regParts = [
|
2017-09-10 05:35:10 -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
|
|
|
];
|
|
|
|
|
|
2020-02-21 05:17:03 -09:00
|
|
|
function addValues(hyperKey: regTypes.HKEY, commandKey: regTypes.HKEY, callback: Function) {
|
|
|
|
|
try {
|
|
|
|
|
Registry.setValueSZ(hyperKey, regParts[1].name, regParts[1].value);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
Registry.setValueSZ(hyperKey, regParts[2].name, regParts[2].value);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error(err);
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
Registry.setValueSZ(commandKey, regParts[0].name, regParts[0].value);
|
|
|
|
|
} catch (err_) {
|
|
|
|
|
console.error(err_);
|
|
|
|
|
}
|
|
|
|
|
callback();
|
2016-11-22 03:06:03 -09:00
|
|
|
}
|
|
|
|
|
|
2020-01-02 05:44:11 -09:00
|
|
|
export const add = (callback: Function) => {
|
2020-02-21 05:17:03 -09:00
|
|
|
try {
|
|
|
|
|
const hyperKey =
|
|
|
|
|
Registry.openKey(Registry.HKCU, regKey, Registry.Access.ALL_ACCESS) ||
|
|
|
|
|
Registry.createKey(Registry.HKCU, regKey, Registry.Access.ALL_ACCESS);
|
|
|
|
|
const commandKey =
|
|
|
|
|
Registry.openKey(Registry.HKCU, `${regKey}\\${regParts[0].key}`, Registry.Access.ALL_ACCESS) ||
|
|
|
|
|
Registry.createKey(Registry.HKCU, `${regKey}\\${regParts[0].key}`, Registry.Access.ALL_ACCESS);
|
|
|
|
|
addValues(hyperKey, commandKey, callback);
|
|
|
|
|
Registry.closeKey(hyperKey);
|
|
|
|
|
Registry.closeKey(commandKey);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
}
|
2016-11-22 03:06:03 -09:00
|
|
|
};
|
|
|
|
|
|
2020-01-02 05:44:11 -09:00
|
|
|
export const remove = (callback: Function) => {
|
2020-02-21 05:17:03 -09:00
|
|
|
try {
|
|
|
|
|
Registry.deleteTree(Registry.HKCU, regKey);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error(err);
|
|
|
|
|
}
|
|
|
|
|
callback();
|
2016-11-22 03:06:03 -09:00
|
|
|
};
|