From b904680f1330b1662e6c966e256ded513be5891a Mon Sep 17 00:00:00 2001 From: weishu Date: Thu, 22 Feb 2024 22:09:13 +0800 Subject: [PATCH] js: Add more API and README --- js/README.md | 43 +++++++++++++++++++++++++++++++++++++++++++ js/index.js | 10 +++++++++- js/package.json | 2 +- 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 js/README.md diff --git a/js/README.md b/js/README.md new file mode 100644 index 00000000..e8fa2bb0 --- /dev/null +++ b/js/README.md @@ -0,0 +1,43 @@ +# Library for KernelSU's module WebUI + +## Install + +```sh +yarn add kernelsu +``` + +## API + +### exec + +Execute a command in the **root** shell. + +options: + +- `cwd` - Current working directory of the child process +- `env` - Environment key-value pairs + +```javascript +import { exec } from 'kernelsu'; + +const { stdout, stderr } = await exec('ls -l', { cwd: '/tmp'}); +console.log(stdout); +``` + +### fullScreen + +Request the WebView enter/exit full screen. + +```javascript +import { fullScreen } from 'kernelsu'; +fullScreen(true); +``` + +### toast + +Show a toast message. + +```javascript +import { toast } from 'kernelsu'; +toast('Hello, world!'); +``` diff --git a/js/index.js b/js/index.js index bf291bb1..a261d81d 100644 --- a/js/index.js +++ b/js/index.js @@ -3,7 +3,7 @@ function getUniqueCallbackName() { return `_callback_${Date.now()}_${callbackCounter++}`; } -function exec(command, options) { +export function exec(command, options) { if (typeof options === "undefined") { options = {}; } @@ -46,3 +46,11 @@ function exec(command, options) { } }); } + +export function fullScreen(isFullScreen) { + ksu.fullScreen(isFullScreen); +} + +export function toast(message) { + ksu.toast(message); +} \ No newline at end of file diff --git a/js/package.json b/js/package.json index 8b6b5ec8..d06a4f86 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "kernelsu", - "version": "1.0.0", + "version": "1.0.2", "description": "Library for KernelSU's module WebUI", "main": "index.js", "scripts": {