/
githubmirror
/
client
Обзор
Документация
Войти
/
githubmirror
/
client
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
shared/desktop/app/exec.desktop.tsx
69 строк
2 KB
chrisnojima-zoom
Version 670 - clean2 (#29122)
08 июн 2026, 19:31
Не верифицирован
08 июн 2026, 19:31
1943197
Код
Авторство
О чём код?
import {exec as _exec, type ExecException} from 'child_process' import fs from 'fs' import os from 'os' import {runMode} from '@/constants/platform' // Execute at path with args. // If you specify platformOnly or runModeOnly, then callback will be called // without error if we don't match that environment. // If killOnExit is true, then the executing process will be killed if the // parent process is killed. // Callback is optional and accepts (error, boolean), where boolean is if we // attempted to execute. export default function exec( path: string | undefined, args: Array<string>, platformOnly: undefined | ReturnType<typeof os.platform>, runModeOnly: string | undefined, killOnExit: boolean, callback: (err: ExecException | null, attempted: boolean, stdout: string, stderr: string) => void ): void { const platform = os.platform() if (platformOnly && platform !== platformOnly) { console.log('Exec (%s) not available for platform: %s != %s', path, platformOnly, platform) callback(null, false, '', '') return } if (!path) { console.log('Exec path not available:', path) callback(null, false, '', '') return } if (runModeOnly && runMode !== runModeOnly) { console.log('Exec path not available for this run mode: %s != %s', runModeOnly, runMode) callback(null, false, '', '') return } fs.access(path, fs.constants.X_OK, function (err) { if (err) { console.log('Exec path not found (or accessible as executable):', path) callback(null, false, '', '') return } args.unshift(`'${path}'`) // protect against spaces in path const cmd = args.join(' ') console.log('Executing:', cmd) const procExec = _exec(cmd, function (execErr, stdout, stderr) { if (stdout) { console.log('Exec (stdout):', stdout) } if (stderr) { console.log('Exec (stderr):', stderr) } if (execErr) { console.log('Exec (err):', execErr) } callback(execErr, true, stdout, stderr) }) if (killOnExit) { // Kill the process if parent process exits process.on('exit', function () { procExec.kill() }) } }) }