-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redirect exec calls from renderer to main process
- Loading branch information
1 parent
146d89a
commit 5ec7878
Showing
3 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import {ipcRenderer} from 'electron'; | ||
|
||
export function exec(command: string, options?: any, callback?: (..._args: any) => void) { | ||
if (typeof options === 'function') { | ||
callback = options; | ||
options = {}; | ||
} | ||
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'); | ||
} | ||
|
||
export function execFile(file: string, args?: any, options?: any, callback?: (..._args: any) => void) { | ||
if (typeof options === 'function') { | ||
callback = options; | ||
options = null; | ||
} | ||
if (typeof args === 'function') { | ||
callback = args; | ||
args = null; | ||
options = null; | ||
} | ||
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters