hyper/lib/utils/ipc-child-process.ts

60 lines
1.5 KiB
TypeScript
Raw Normal View History

2023-06-26 03:17:43 -08:00
import type {ExecFileOptions, ExecOptions} from 'child_process';
2023-07-22 05:57:32 -08:00
import {ipcRenderer} from './ipc';
2023-06-26 03:17:43 -08:00
export function exec(command: string, options: ExecOptions, callback: (..._args: any) => void) {
if (typeof options === 'function') {
callback = options;
options = {};
}
2023-06-26 01:22:59 -08:00
ipcRenderer.invoke('child_process.exec', command, options).then(
({stdout, stderr}) => callback?.(null, stdout, stderr),
(error) => callback?.(error, '', '')
);
}
export function execSync() {
console.error('Calling execSync from renderer is disabled');
}
2023-06-26 03:17:43 -08:00
export function execFile(file: string, args: string[], options: ExecFileOptions, callback: (..._args: any) => void) {
if (typeof options === 'function') {
callback = options;
2023-06-26 03:17:43 -08:00
options = {};
}
if (typeof args === 'function') {
callback = args;
2023-06-26 03:17:43 -08:00
args = [];
options = {};
}
2023-06-26 01:22:59 -08:00
ipcRenderer.invoke('child_process.execFile', file, args, options).then(
({stdout, stderr}) => callback?.(null, stdout, stderr),
(error) => callback?.(error, '', '')
);
}
export function execFileSync() {
console.error('Calling execFileSync from renderer is disabled');
}
export function spawn() {
console.error('Calling spawn from renderer is disabled');
}
export function spawnSync() {
console.error('Calling spawnSync from renderer is disabled');
}
export function fork() {
console.error('Calling fork from renderer is disabled');
}
export default {
exec,
execSync,
execFile,
execFileSync,
spawn,
spawnSync,
fork
};