kernelsu 1.0.6 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -10,12 +10,12 @@ yarn add kernelsu
10
10
 
11
11
  ### exec
12
12
 
13
- Spawns a **root** shell and runs a command within that shell, passing the `stdout` and `stderr` to a Promise when complete.
13
+ Spawns a **root** shell and runs a command within that shell, returning a Promise that resolves with the `stdout` and `stderr` outputs upon completion.
14
14
 
15
15
  - `command` `<string>` The command to run, with space-separated arguments.
16
16
  - `options` `<Object>`
17
- - `cwd` - Current working directory of the child process
18
- - `env` - Environment key-value pairs
17
+ - `cwd` - Current working directory of the child process.
18
+ - `env` - Environment key-value pairs.
19
19
 
20
20
  ```javascript
21
21
  import { exec } from 'kernelsu';
@@ -31,13 +31,13 @@ if (errno === 0) {
31
31
 
32
32
  Spawns a new process using the given `command` in **root** shell, with command-line arguments in `args`. If omitted, `args` defaults to an empty array.
33
33
 
34
- Returns a `ChildProcess`, Instances of the ChildProcess represent spawned child processes.
34
+ Returns a `ChildProcess` instance. Instances of `ChildProcess` represent spawned child processes.
35
35
 
36
36
  - `command` `<string>` The command to run.
37
37
  - `args` `<string[]>` List of string arguments.
38
38
  - `options` `<Object>`:
39
- - `cwd` `<string>` - Current working directory of the child process
40
- - `env` `<Object>` - Environment key-value pairs
39
+ - `cwd` `<string>` - Current working directory of the child process.
40
+ - `env` `<Object>` - Environment key-value pairs.
41
41
 
42
42
  Example of running `ls -lh /data`, capturing `stdout`, `stderr`, and the exit code:
43
43
 
@@ -63,9 +63,9 @@ ls.on('exit', (code) => {
63
63
 
64
64
  ##### Event 'exit'
65
65
 
66
- - `code` `<number>` The exit code if the child exited on its own.
66
+ - `code` `<number>` The exit code if the child process exited on its own.
67
67
 
68
- The `'exit'` event is emitted after the child process ends. If the process exited, `code` is the final exit code of the process, otherwise null
68
+ The `'exit'` event is emitted when the child process ends. If the process exits, `code` contains the final exit code; otherwise, it is null.
69
69
 
70
70
  ##### Event 'error'
71
71
 
@@ -109,3 +109,57 @@ Show a toast message.
109
109
  import { toast } from 'kernelsu';
110
110
  toast('Hello, world!');
111
111
  ```
112
+
113
+ ### moduleInfo
114
+
115
+ Get module info.
116
+
117
+ ```javascript
118
+ import { moduleInfo } from 'kernelsu';
119
+ // print moduleId in console
120
+ console.log(moduleInfo());
121
+ ```
122
+
123
+ ### listPackages
124
+
125
+ List installed packages.
126
+
127
+ Returns an array of package names.
128
+
129
+ - `type` `<string>` The type of packages to list: "user", "system", or "all".
130
+
131
+ ```javascript
132
+ import { listPackages } from 'kernelsu';
133
+ // list user packages
134
+ const packages = listPackages("user");
135
+ ```
136
+
137
+ - tips: when `listPackages` api is available, you can use ksu://icon/{packageName} to get app icon.
138
+
139
+ ``` javascript
140
+ img.src = "ksu://icon/" + packageName;
141
+ ```
142
+
143
+ ### getPackagesInfo
144
+
145
+ Get information for a list of packages.
146
+
147
+ Returns an array of `PackagesInfo` objects.
148
+
149
+ - `packages` `<string[]>` The list of package names.
150
+
151
+ ```javascript
152
+ import { getPackagesInfo } from 'kernelsu';
153
+ const packages = getPackagesInfo(['com.android.settings', 'com.android.shell']);
154
+ ```
155
+
156
+ #### PackagesInfo
157
+
158
+ An object contains:
159
+
160
+ - `packageName` `<string>` Package name of the application.
161
+ - `versionName` `<string>` Version of the application.
162
+ - `versionCode` `<number>` Version code of the application.
163
+ - `appLabel` `<string>` Display name of the application.
164
+ - `isSystem` `<boolean>` Whether the application is a system app.
165
+ - `uid` `<number>` UID of the application.
package/index.d.ts ADDED
@@ -0,0 +1,63 @@
1
+ interface ExecOptions {
2
+ cwd?: string,
3
+ env?: { [key: string]: string }
4
+ }
5
+
6
+ interface ExecResults {
7
+ errno: number,
8
+ stdout: string,
9
+ stderr: string
10
+ }
11
+
12
+ declare function exec(command: string): Promise<ExecResults>;
13
+ declare function exec(command: string, options: ExecOptions): Promise<ExecResults>;
14
+
15
+ interface SpawnOptions {
16
+ cwd?: string,
17
+ env?: { [key: string]: string }
18
+ }
19
+
20
+ interface Stdio {
21
+ on(event: 'data', callback: (data: string) => void)
22
+ }
23
+
24
+ interface ChildProcess {
25
+ stdout: Stdio,
26
+ stderr: Stdio,
27
+ on(event: 'exit', callback: (code: number) => void)
28
+ on(event: 'error', callback: (err: any) => void)
29
+ }
30
+
31
+ declare function spawn(command: string): ChildProcess;
32
+ declare function spawn(command: string, args: string[]): ChildProcess;
33
+ declare function spawn(command: string, options: SpawnOptions): ChildProcess;
34
+ declare function spawn(command: string, args: string[], options: SpawnOptions): ChildProcess;
35
+
36
+ declare function fullScreen(isFullScreen: boolean);
37
+
38
+ declare function toast(message: string);
39
+
40
+ declare function moduleInfo(): string;
41
+
42
+ interface PackagesInfo {
43
+ packageName: string;
44
+ versionName: string;
45
+ versionCode: number;
46
+ appLabel: string;
47
+ isSystem: boolean;
48
+ uid: number;
49
+ }
50
+
51
+ declare function listPackages(type: string): string[];
52
+
53
+ declare function getPackagesInfo(packages: string[]): PackagesInfo[];
54
+
55
+ export {
56
+ exec,
57
+ spawn,
58
+ fullScreen,
59
+ toast,
60
+ moduleInfo,
61
+ listPackages,
62
+ getPackagesInfo,
63
+ }
package/index.js CHANGED
@@ -71,7 +71,7 @@ function Stdio() {
71
71
  export function spawn(command, args, options) {
72
72
  if (typeof args === "undefined") {
73
73
  args = [];
74
- } else if (typeof args === "object") {
74
+ } else if (!(args instanceof Array)) {
75
75
  // allow for (command, options) signature
76
76
  options = args;
77
77
  }
@@ -113,3 +113,26 @@ export function fullScreen(isFullScreen) {
113
113
  export function toast(message) {
114
114
  ksu.toast(message);
115
115
  }
116
+
117
+ export function moduleInfo() {
118
+ return ksu.moduleInfo();
119
+ }
120
+
121
+ export function listPackages(type) {
122
+ try {
123
+ return JSON.parse(ksu.listPackages(type));
124
+ } catch (error) {
125
+ return [];
126
+ }
127
+ }
128
+
129
+ export function getPackagesInfo(packages) {
130
+ try {
131
+ if (typeof packages !== "string") {
132
+ packages = JSON.stringify(packages);
133
+ }
134
+ return JSON.parse(ksu.getPackagesInfo(packages));
135
+ } catch (error) {
136
+ return [];
137
+ }
138
+ }
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "kernelsu",
3
- "version": "1.0.6",
3
+ "version": "2.1.1",
4
4
  "description": "Library for KernelSU's module WebUI",
5
5
  "main": "index.js",
6
+ "types": "index.d.ts",
6
7
  "scripts": {
7
8
  "test": "npm run test"
8
9
  },