kernelsu 1.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/index.js +48 -0
- package/package.json +25 -0
package/index.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
let callbackCounter = 0;
|
|
2
|
+
function getUniqueCallbackName() {
|
|
3
|
+
return `_callback_${Date.now()}_${callbackCounter++}`;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
function exec(command, options) {
|
|
7
|
+
if (typeof options === "undefined") {
|
|
8
|
+
options = {};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
12
|
+
// Generate a unique callback function name
|
|
13
|
+
const callbackFuncName = getUniqueCallbackName();
|
|
14
|
+
|
|
15
|
+
// Define the success callback function
|
|
16
|
+
window[callbackFuncName] = (stdout, stderr) => {
|
|
17
|
+
resolve({ stdout, stderr });
|
|
18
|
+
cleanup(callbackFuncName);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// Define the failure callback function
|
|
22
|
+
const errorFuncName = callbackFuncName + "_error";
|
|
23
|
+
window[errorFuncName] = (error) => {
|
|
24
|
+
reject(error);
|
|
25
|
+
cleanup(callbackFuncName, errorFuncName);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// Cleanup function to remove the callbacks
|
|
29
|
+
function cleanup(successName, errorName = successName) {
|
|
30
|
+
delete window[successName];
|
|
31
|
+
if (errorName) {
|
|
32
|
+
delete window[errorName];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
ksu.exec(
|
|
38
|
+
command,
|
|
39
|
+
JSON.stringify(options),
|
|
40
|
+
callbackFuncName,
|
|
41
|
+
errorFuncName
|
|
42
|
+
);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
reject(error);
|
|
45
|
+
cleanup(callbackFuncName, errorFuncName);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "kernelsu",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Library for KernelSU's module WebUI",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "npm run test"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/tiann/KernelSU.git"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"su",
|
|
15
|
+
"kernelsu",
|
|
16
|
+
"module",
|
|
17
|
+
"webui"
|
|
18
|
+
],
|
|
19
|
+
"author": "weishu",
|
|
20
|
+
"license": "GPL-3.0-or-later",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/tiann/KernelSU/issues"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://github.com/tiann/KernelSU#readme"
|
|
25
|
+
}
|