kernelsu 1.0.6 → 3.0.0
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 +76 -8
- package/index.d.ts +66 -0
- package/index.js +28 -1
- package/package.json +2 -1
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,
|
|
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
|
|
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
|
|
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
|
|
|
@@ -101,6 +101,20 @@ import { fullScreen } from 'kernelsu';
|
|
|
101
101
|
fullScreen(true);
|
|
102
102
|
```
|
|
103
103
|
|
|
104
|
+
### enableInsets
|
|
105
|
+
|
|
106
|
+
Request the WebView to set padding to 0 or system bar insets
|
|
107
|
+
|
|
108
|
+
- tips: this is disabled by default but if you request resource from `internal/insets.css`, this will be enabled automatically.
|
|
109
|
+
- To get insets value and enable this automatically, you can
|
|
110
|
+
- add `@import "https://mui.kernelsu.org/internal/insets.css";` in css OR
|
|
111
|
+
- add `<link rel="stylesheet" type="text/css" href="/internal/insets.css" />` in html.
|
|
112
|
+
|
|
113
|
+
```javascript
|
|
114
|
+
import { enableInsets } from 'kernelsu';
|
|
115
|
+
enableInsets(true);
|
|
116
|
+
```
|
|
117
|
+
|
|
104
118
|
### toast
|
|
105
119
|
|
|
106
120
|
Show a toast message.
|
|
@@ -109,3 +123,57 @@ Show a toast message.
|
|
|
109
123
|
import { toast } from 'kernelsu';
|
|
110
124
|
toast('Hello, world!');
|
|
111
125
|
```
|
|
126
|
+
|
|
127
|
+
### moduleInfo
|
|
128
|
+
|
|
129
|
+
Get module info.
|
|
130
|
+
|
|
131
|
+
```javascript
|
|
132
|
+
import { moduleInfo } from 'kernelsu';
|
|
133
|
+
// print moduleId in console
|
|
134
|
+
console.log(moduleInfo());
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### listPackages
|
|
138
|
+
|
|
139
|
+
List installed packages.
|
|
140
|
+
|
|
141
|
+
Returns an array of package names.
|
|
142
|
+
|
|
143
|
+
- `type` `<string>` The type of packages to list: "user", "system", or "all".
|
|
144
|
+
|
|
145
|
+
```javascript
|
|
146
|
+
import { listPackages } from 'kernelsu';
|
|
147
|
+
// list user packages
|
|
148
|
+
const packages = listPackages("user");
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
- tips: when `listPackages` api is available, you can use ksu://icon/{packageName} to get app icon.
|
|
152
|
+
|
|
153
|
+
``` javascript
|
|
154
|
+
img.src = "ksu://icon/" + packageName;
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### getPackagesInfo
|
|
158
|
+
|
|
159
|
+
Get information for a list of packages.
|
|
160
|
+
|
|
161
|
+
Returns an array of `PackagesInfo` objects.
|
|
162
|
+
|
|
163
|
+
- `packages` `<string[]>` The list of package names.
|
|
164
|
+
|
|
165
|
+
```javascript
|
|
166
|
+
import { getPackagesInfo } from 'kernelsu';
|
|
167
|
+
const packages = getPackagesInfo(['com.android.settings', 'com.android.shell']);
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
#### PackagesInfo
|
|
171
|
+
|
|
172
|
+
An object contains:
|
|
173
|
+
|
|
174
|
+
- `packageName` `<string>` Package name of the application.
|
|
175
|
+
- `versionName` `<string>` Version of the application.
|
|
176
|
+
- `versionCode` `<number>` Version code of the application.
|
|
177
|
+
- `appLabel` `<string>` Display name of the application.
|
|
178
|
+
- `isSystem` `<boolean>` Whether the application is a system app.
|
|
179
|
+
- `uid` `<number>` UID of the application.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
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 enableInsets(enable: boolean)
|
|
39
|
+
|
|
40
|
+
declare function toast(message: string);
|
|
41
|
+
|
|
42
|
+
declare function moduleInfo(): string;
|
|
43
|
+
|
|
44
|
+
interface PackagesInfo {
|
|
45
|
+
packageName: string;
|
|
46
|
+
versionName: string;
|
|
47
|
+
versionCode: number;
|
|
48
|
+
appLabel: string;
|
|
49
|
+
isSystem: boolean;
|
|
50
|
+
uid: number;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
declare function listPackages(type: string): string[];
|
|
54
|
+
|
|
55
|
+
declare function getPackagesInfo(packages: string[]): PackagesInfo[];
|
|
56
|
+
|
|
57
|
+
export {
|
|
58
|
+
exec,
|
|
59
|
+
spawn,
|
|
60
|
+
fullScreen,
|
|
61
|
+
enableInsets,
|
|
62
|
+
toast,
|
|
63
|
+
moduleInfo,
|
|
64
|
+
listPackages,
|
|
65
|
+
getPackagesInfo,
|
|
66
|
+
}
|
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 (
|
|
74
|
+
} else if (!(args instanceof Array)) {
|
|
75
75
|
// allow for (command, options) signature
|
|
76
76
|
options = args;
|
|
77
77
|
}
|
|
@@ -110,6 +110,33 @@ export function fullScreen(isFullScreen) {
|
|
|
110
110
|
ksu.fullScreen(isFullScreen);
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
+
export function enableInsets(enable) {
|
|
114
|
+
ksu.enableInsets(enable);
|
|
115
|
+
}
|
|
116
|
+
|
|
113
117
|
export function toast(message) {
|
|
114
118
|
ksu.toast(message);
|
|
115
119
|
}
|
|
120
|
+
|
|
121
|
+
export function moduleInfo() {
|
|
122
|
+
return ksu.moduleInfo();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function listPackages(type) {
|
|
126
|
+
try {
|
|
127
|
+
return JSON.parse(ksu.listPackages(type));
|
|
128
|
+
} catch (error) {
|
|
129
|
+
return [];
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function getPackagesInfo(packages) {
|
|
134
|
+
try {
|
|
135
|
+
if (typeof packages !== "string") {
|
|
136
|
+
packages = JSON.stringify(packages);
|
|
137
|
+
}
|
|
138
|
+
return JSON.parse(ksu.getPackagesInfo(packages));
|
|
139
|
+
} catch (error) {
|
|
140
|
+
return [];
|
|
141
|
+
}
|
|
142
|
+
}
|