From 2fb5334ac6371720a2346984b39275d1f24af5da Mon Sep 17 00:00:00 2001 From: Mufanc <47652878+Mufanc@users.noreply.github.com> Date: Mon, 26 Feb 2024 15:35:23 +0800 Subject: [PATCH] fix kernelsu.spawn && add type definitions (#1395) --- js/index.d.ts | 45 +++++++++++++++++++++++++++++++++++++++++++++ js/index.js | 2 +- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 js/index.d.ts diff --git a/js/index.d.ts b/js/index.d.ts new file mode 100644 index 00000000..b65248e3 --- /dev/null +++ b/js/index.d.ts @@ -0,0 +1,45 @@ +interface ExecOptions { + cwd?: string, + env?: { [key: string]: string } +} + +interface ExecResults { + errno: number, + stdout: string, + stderr: string +} + +declare function exec(command: string): Promise; +declare function exec(command: string, options: ExecOptions): Promise; + +interface SpawnOptions { + cwd?: string, + env?: { [key: string]: string } +} + +interface Stdio { + on(event: 'data', callback: (data: string) => void) +} + +interface ChildProcess { + stdout: Stdio, + stderr: Stdio, + on(event: 'exit', callback: (code: number) => void) + on(event: 'error', callback: (err: any) => void) +} + +declare function spawn(command: string): ChildProcess; +declare function spawn(command: string, args: string[]): ChildProcess; +declare function spawn(command: string, options: SpawnOptions): ChildProcess; +declare function spawn(command: string, args: string[], options: SpawnOptions): ChildProcess; + +declare function fullScreen(isFullScreen: boolean); + +declare function toast(message: string); + +export { + exec, + spawn, + fullScreen, + toast +} diff --git a/js/index.js b/js/index.js index 7d547425..4b64e9c4 100644 --- a/js/index.js +++ b/js/index.js @@ -71,7 +71,7 @@ function Stdio() { export function spawn(command, args, options) { if (typeof args === "undefined") { args = []; - } else if (typeof args === "object") { + } else if (!(args instanceof Array)) { // allow for (command, options) signature options = args; }