diff --git a/app/config/open.ts b/app/config/open.ts index d2836dca..1d5047c9 100644 --- a/app/config/open.ts +++ b/app/config/open.ts @@ -1,10 +1,9 @@ import {shell} from 'electron'; import {cfgPath} from './paths'; -import {Registry, loadRegistry} from '../utils/registry'; +import * as Registry from 'native-reg'; import {exec} from 'child_process'; const getUserChoiceKey = () => { - if (!loadRegistry()) return; try { // Load FileExts keys for .js files const fileExtsKeys = Registry.openKey( @@ -27,7 +26,6 @@ const getUserChoiceKey = () => { }; const hasDefaultSet = () => { - if (!loadRegistry()) return false; const userChoice = getUserChoiceKey(); if (!userChoice) return false; diff --git a/app/ext-modules.d.ts b/app/ext-modules.d.ts index 812dcafb..443d58ee 100644 --- a/app/ext-modules.d.ts +++ b/app/ext-modules.d.ts @@ -6,109 +6,3 @@ declare module 'default-shell' { const val: string; export default val; } - -declare module 'native-reg' { - export enum HKEY { - CLASSES_ROOT = 2147483648, - CURRENT_USER = 2147483649, - LOCAL_MACHINE = 2147483650, - USERS = 2147483651, - PERFORMANCE_DATA = 2147483652, - PERFORMANCE_TEXT = 2147483728, - PERFORMANCE_NLSTEXT = 2147483744, - CURRENT_CONFIG = 2147483653, - DYN_DATA = 2147483654, - CURRENT_USER_LOCAL_SETTINGS = 2147483655 - } - export enum CreateKeyOptions { - NON_VOLATILE = 0, - VOLATILE = 1, - CREATE_LINK = 2, - BACKUP_RESTORE = 4 - } - export enum OpenKeyOptions { - OPEN_LINK = 8 - } - export enum Access { - QUERY_VALUE = 1, - SET_VALUE = 2, - CREATE_SUB_KEY = 4, - ENUMERATE_SUB_KEYS = 8, - NOTIFY = 16, - CREATE_LINK = 32, - WOW64_64KEY = 256, - WOW64_32KEY = 512, - READ = 131097, - WRITE = 131078, - EXECUTE = 131097, - ALL_ACCESS = 983103 - } - export enum ValueType { - NONE = 0, - SZ = 1, - EXPAND_SZ = 2, - BINARY = 3, - DWORD = 4, - DWORD_LITTLE_ENDIAN = 4, - DWORD_BIG_ENDIAN = 5, - LINK = 6, - MULTI_SZ = 7, - RESOURCE_LIST = 8, - FULL_RESOURCE_DESCRIPTOR = 9, - RESOURCE_REQUIREMENTS_LIST = 10, - QWORD = 11, - QWORD_LITTLE_ENDIAN = 11 - } - export enum GetValueFlags { - RT_ANY = 65535, - RT_REG_NONE = 1, - RT_REG_SZ = 2, - RT_REG_EXPAND_SZ = 4, - RT_REG_BINARY = 8, - RT_REG_DWORD = 16, - RT_REG_MULTI_SZ = 32, - RT_REG_QWORD = 64, - RT_DWORD = 24, - RT_QWORD = 72, - NO_EXPAND = 268435456, - SUBKEY_WOW6464KEY = 65536, - SUBKEY_WOW6432KEY = 131072 - } - export const HKCR = HKEY.CLASSES_ROOT; - export const HKCU = HKEY.CURRENT_USER; - export const HKLM = HKEY.LOCAL_MACHINE; - export const HKU = HKEY.USERS; - export type Value = Buffer & { - type: ValueType; - }; - export function isHKEY(hkey: any): hkey is HKEY; - export function createKey(hkey: HKEY, subKey: string, access: Access, options?: CreateKeyOptions): HKEY; - export function openKey(hkey: HKEY, subKey: string, access: Access, options?: OpenKeyOptions): HKEY | null; - export function openCurrentUser(access?: Access): HKEY; - export function loadAppKey(file: string, access: Access): HKEY | null; - export function enumKeyNames(hkey: HKEY): string[]; - export function enumValueNames(hkey: HKEY): string[]; - export function queryValueRaw(hkey: HKEY, valueName: string): Value | null; - export function getValueRaw(hkey: HKEY, subKey: string, valueName: string, flags?: GetValueFlags): Value | null; - export function setValueRaw(hkey: HKEY, valueName: string, valueType: ValueType, data: Buffer): void; - export function deleteKey(hkey: HKEY, subKey: string): boolean; - export function deleteTree(hkey: HKEY, subKey: string): boolean; - export function deleteKeyValue(hkey: HKEY, subKey: string, valueName: string): boolean; - export function deleteValue(hkey: HKEY, valueName: string): boolean; - export function closeKey(hkey: HKEY | null | undefined): void; - export type ParsedValue = number | string | string[] | Buffer; - export function parseValue(value: Value | null): ParsedValue | null; - export function parseString(value: Buffer): string; - export function parseMultiString(value: Buffer): string[]; - export function formatString(value: string): Buffer; - export function formatMultiString(values: string[]): Buffer; - export function formatDWORD(value: number): Buffer; - export function formatQWORD(value: number): Buffer; - export function setValueSZ(hkey: HKEY, valueName: string, value: string): void; - export function setValueEXPAND_SZ(hkey: HKEY, valueName: string, value: string): void; - export function setValueMULTI_SZ(hkey: HKEY, valueName: string, value: string[]): void; - export function setValueDWORD(hkey: HKEY, valueName: string, value: number): void; - export function setValueQWORD(hkey: HKEY, valueName: string, value: number): void; - export function getValue(hkey: HKEY, subKey: string, valueName: string, flags?: GetValueFlags): ParsedValue | null; - export function queryValue(hkey: HKEY, valueName: string): ParsedValue | null; -} diff --git a/app/utils/cli-install.ts b/app/utils/cli-install.ts index ff98d55d..7cac74a6 100644 --- a/app/utils/cli-install.ts +++ b/app/utils/cli-install.ts @@ -3,7 +3,7 @@ import fs from 'fs'; import path from 'path'; import notify from '../notify'; import {cliScriptPath, cliLinkPath} from '../config/paths'; -import {Registry, loadRegistry} from './registry'; +import * as Registry from 'native-reg'; import type {ValueType} from 'native-reg'; import sudoPrompt from 'sudo-prompt'; import {clipboard, dialog} from 'electron'; @@ -73,10 +73,6 @@ sudo ln -sf "${cliScriptPath}" "${cliLinkPath}"`, const addBinToUserPath = () => { return new Promise((resolve, reject) => { - if (!loadRegistry()) { - reject('Failed to load Registry Module'); - return; - } try { const envKey = Registry.openKey(Registry.HKCU, 'Environment', Registry.Access.ALL_ACCESS)!; diff --git a/app/utils/registry.ts b/app/utils/registry.ts deleted file mode 100644 index c8fd233b..00000000 --- a/app/utils/registry.ts +++ /dev/null @@ -1,16 +0,0 @@ -export let Registry: typeof import('native-reg'); - -export const loadRegistry = () => { - if (process.platform === 'win32') { - if (!Registry) { - try { - Registry = require('native-reg'); - } catch (error) { - console.error(error); - return false; - } - } - return true; - } - return false; -}; diff --git a/app/utils/system-context-menu.ts b/app/utils/system-context-menu.ts index 585a6416..e0c2b94e 100644 --- a/app/utils/system-context-menu.ts +++ b/app/utils/system-context-menu.ts @@ -1,4 +1,4 @@ -import {Registry, loadRegistry} from './registry'; +import * as Registry from 'native-reg'; import type {HKEY} from 'native-reg'; const appPath = `"${process.execPath}"`; @@ -14,7 +14,6 @@ const regParts = [ ]; function addValues(hyperKey: HKEY, commandKey: HKEY) { - if (!loadRegistry()) return; try { Registry.setValueSZ(hyperKey, regParts[1].name, regParts[1].value); } catch (error) { @@ -33,7 +32,6 @@ function addValues(hyperKey: HKEY, commandKey: HKEY) { } export const add = () => { - if (!loadRegistry()) return; regKeys.forEach((regKey) => { try { const hyperKey = @@ -52,7 +50,6 @@ export const add = () => { }; export const remove = () => { - if (!loadRegistry()) return; regKeys.forEach((regKey) => { try { Registry.deleteTree(Registry.HKCU, regKey);