mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-13 04:28:41 -09:00
Import native-reg directly
This commit is contained in:
parent
4d486f80ba
commit
eb2517d300
5 changed files with 3 additions and 134 deletions
|
|
@ -1,10 +1,9 @@
|
||||||
import {shell} from 'electron';
|
import {shell} from 'electron';
|
||||||
import {cfgPath} from './paths';
|
import {cfgPath} from './paths';
|
||||||
import {Registry, loadRegistry} from '../utils/registry';
|
import * as Registry from 'native-reg';
|
||||||
import {exec} from 'child_process';
|
import {exec} from 'child_process';
|
||||||
|
|
||||||
const getUserChoiceKey = () => {
|
const getUserChoiceKey = () => {
|
||||||
if (!loadRegistry()) return;
|
|
||||||
try {
|
try {
|
||||||
// Load FileExts keys for .js files
|
// Load FileExts keys for .js files
|
||||||
const fileExtsKeys = Registry.openKey(
|
const fileExtsKeys = Registry.openKey(
|
||||||
|
|
@ -27,7 +26,6 @@ const getUserChoiceKey = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const hasDefaultSet = () => {
|
const hasDefaultSet = () => {
|
||||||
if (!loadRegistry()) return false;
|
|
||||||
const userChoice = getUserChoiceKey();
|
const userChoice = getUserChoiceKey();
|
||||||
if (!userChoice) return false;
|
if (!userChoice) return false;
|
||||||
|
|
||||||
|
|
|
||||||
106
app/ext-modules.d.ts
vendored
106
app/ext-modules.d.ts
vendored
|
|
@ -6,109 +6,3 @@ declare module 'default-shell' {
|
||||||
const val: string;
|
const val: string;
|
||||||
export default val;
|
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;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import notify from '../notify';
|
import notify from '../notify';
|
||||||
import {cliScriptPath, cliLinkPath} from '../config/paths';
|
import {cliScriptPath, cliLinkPath} from '../config/paths';
|
||||||
import {Registry, loadRegistry} from './registry';
|
import * as Registry from 'native-reg';
|
||||||
import type {ValueType} from 'native-reg';
|
import type {ValueType} from 'native-reg';
|
||||||
import sudoPrompt from 'sudo-prompt';
|
import sudoPrompt from 'sudo-prompt';
|
||||||
import {clipboard, dialog} from 'electron';
|
import {clipboard, dialog} from 'electron';
|
||||||
|
|
@ -73,10 +73,6 @@ sudo ln -sf "${cliScriptPath}" "${cliLinkPath}"`,
|
||||||
|
|
||||||
const addBinToUserPath = () => {
|
const addBinToUserPath = () => {
|
||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
if (!loadRegistry()) {
|
|
||||||
reject('Failed to load Registry Module');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
const envKey = Registry.openKey(Registry.HKCU, 'Environment', Registry.Access.ALL_ACCESS)!;
|
const envKey = Registry.openKey(Registry.HKCU, 'Environment', Registry.Access.ALL_ACCESS)!;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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;
|
|
||||||
};
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import {Registry, loadRegistry} from './registry';
|
import * as Registry from 'native-reg';
|
||||||
import type {HKEY} from 'native-reg';
|
import type {HKEY} from 'native-reg';
|
||||||
|
|
||||||
const appPath = `"${process.execPath}"`;
|
const appPath = `"${process.execPath}"`;
|
||||||
|
|
@ -14,7 +14,6 @@ const regParts = [
|
||||||
];
|
];
|
||||||
|
|
||||||
function addValues(hyperKey: HKEY, commandKey: HKEY) {
|
function addValues(hyperKey: HKEY, commandKey: HKEY) {
|
||||||
if (!loadRegistry()) return;
|
|
||||||
try {
|
try {
|
||||||
Registry.setValueSZ(hyperKey, regParts[1].name, regParts[1].value);
|
Registry.setValueSZ(hyperKey, regParts[1].name, regParts[1].value);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
@ -33,7 +32,6 @@ function addValues(hyperKey: HKEY, commandKey: HKEY) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const add = () => {
|
export const add = () => {
|
||||||
if (!loadRegistry()) return;
|
|
||||||
regKeys.forEach((regKey) => {
|
regKeys.forEach((regKey) => {
|
||||||
try {
|
try {
|
||||||
const hyperKey =
|
const hyperKey =
|
||||||
|
|
@ -52,7 +50,6 @@ export const add = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const remove = () => {
|
export const remove = () => {
|
||||||
if (!loadRegistry()) return;
|
|
||||||
regKeys.forEach((regKey) => {
|
regKeys.forEach((regKey) => {
|
||||||
try {
|
try {
|
||||||
Registry.deleteTree(Registry.HKCU, regKey);
|
Registry.deleteTree(Registry.HKCU, regKey);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue