diff options
author | Kevin <[email protected]> | 2024-10-16 00:49:16 -0300 |
---|---|---|
committer | Kevin <[email protected]> | 2024-10-16 00:49:16 -0300 |
commit | 2b1e8501b46056b79d97e90c6ec94e3ad36d0ab2 (patch) | |
tree | 6486e98bd1ba523b1aeb4bd2566d1ff6e5c41798 /core/gjs/src/process.ts | |
parent | 03f2c4706faba7dac5aee71b10255eac218cbeec (diff) | |
parent | 236487001ab2a6c9c8e87e5db0ced9e5ab3ed791 (diff) |
Merge branch 'adapt-upstream-changes'
Diffstat (limited to 'core/gjs/src/process.ts')
-rw-r--r-- | core/gjs/src/process.ts | 68 |
1 files changed, 0 insertions, 68 deletions
diff --git a/core/gjs/src/process.ts b/core/gjs/src/process.ts deleted file mode 100644 index bf8ea28..0000000 --- a/core/gjs/src/process.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { Astal } from "./imports.js" - -type Args = { - cmd: string | string[] - out?: (stdout: string) => void - err?: (stderr: string) => void -} - -export function subprocess(args: Args): Astal.Process - -export function subprocess( - cmd: string | string[], - onOut?: (stdout: string) => void, - onErr?: (stderr: string) => void, -): Astal.Process - -export function subprocess( - argsOrCmd: Args | string | string[], - onOut: (stdout: string) => void = print, - onErr: (stderr: string) => void = printerr, -) { - const args = Array.isArray(argsOrCmd) || typeof argsOrCmd === "string" - const { cmd, err, out } = { - cmd: args ? argsOrCmd : argsOrCmd.cmd, - err: args ? onErr : argsOrCmd.err || onErr, - out: args ? onOut : argsOrCmd.out || onOut, - } - - const proc = Array.isArray(cmd) - ? Astal.Process.subprocessv(cmd) - : Astal.Process.subprocess(cmd) - - proc.connect("stdout", (_, stdout: string) => out(stdout)) - proc.connect("stderr", (_, stderr: string) => err(stderr)) - return proc -} - -/** @throws {GLib.Error} Throws stderr */ -export function exec(cmd: string | string[]) { - return Array.isArray(cmd) - ? Astal.Process.execv(cmd) - : Astal.Process.exec(cmd) -} - -export function execAsync(cmd: string | string[]): Promise<string> { - return new Promise((resolve, reject) => { - if (Array.isArray(cmd)) { - Astal.Process.exec_asyncv(cmd, (_, res) => { - try { - resolve(Astal.Process.exec_asyncv_finish(res)) - } - catch (error) { - reject(error) - } - }) - } - else { - Astal.Process.exec_async(cmd, (_, res) => { - try { - resolve(Astal.Process.exec_finish(res)) - } - catch (error) { - reject(error) - } - }) - } - }) -} |