Move system-context-menu.ts to utils
This commit is contained in:
parent
3f8a6969f1
commit
f169c2e906
1 changed files with 1 additions and 1 deletions
63
app/utils/system-context-menu.ts
Normal file
63
app/utils/system-context-menu.ts
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
import {Registry, loadRegistry} from './registry';
|
||||
import type {HKEY} from 'native-reg';
|
||||
|
||||
const appPath = `"${process.execPath}"`;
|
||||
const regKeys = [
|
||||
`Software\\Classes\\Directory\\Background\\shell\\Hyper`,
|
||||
`Software\\Classes\\Directory\\shell\\Hyper`,
|
||||
`Software\\Classes\\Drive\\shell\\Hyper`
|
||||
];
|
||||
const regParts = [
|
||||
{key: 'command', name: '', value: `${appPath} "%V"`},
|
||||
{name: '', value: 'Open Hyper here'},
|
||||
{name: 'Icon', value: `${appPath}`}
|
||||
];
|
||||
|
||||
function addValues(hyperKey: HKEY, commandKey: HKEY) {
|
||||
if (!loadRegistry()) return;
|
||||
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_);
|
||||
}
|
||||
}
|
||||
|
||||
export const add = () => {
|
||||
if (!loadRegistry()) return;
|
||||
regKeys.forEach((regKey) => {
|
||||
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);
|
||||
Registry.closeKey(hyperKey);
|
||||
Registry.closeKey(commandKey);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const remove = () => {
|
||||
if (!loadRegistry()) return;
|
||||
regKeys.forEach((regKey) => {
|
||||
try {
|
||||
Registry.deleteTree(Registry.HKCU, regKey);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
});
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue