tauri-plugin-shizuku-api 0.1.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 +104 -0
- package/dist-js/index.cjs +45 -0
- package/dist-js/index.d.ts +50 -0
- package/dist-js/index.js +37 -0
- package/package.json +33 -0
package/README.md
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# Tauri Plugin Shizuku
|
|
2
|
+
|
|
3
|
+
Android Tauri v2 plugin for communicating with Shizuku.
|
|
4
|
+
|
|
5
|
+
Current capabilities:
|
|
6
|
+
|
|
7
|
+
- Shizuku service status detection
|
|
8
|
+
- Shizuku permission request trigger
|
|
9
|
+
- Open Shizuku app (or download page when not installed)
|
|
10
|
+
- Execute shell/adb style commands through Shizuku
|
|
11
|
+
- Query Android system properties
|
|
12
|
+
- List installed packages
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
Rust side:
|
|
17
|
+
|
|
18
|
+
```toml
|
|
19
|
+
[dependencies]
|
|
20
|
+
tauri-plugin-shizuku = { path = "../tauri-plugin-shizuku" }
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
JS side:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
bun tauri add tauri-plugin-shizuku-api
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Register plugin:
|
|
30
|
+
|
|
31
|
+
```rust
|
|
32
|
+
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
|
33
|
+
pub fn run() {
|
|
34
|
+
tauri::Builder::default()
|
|
35
|
+
.plugin(tauri_plugin_shizuku::init())
|
|
36
|
+
.run(tauri::generate_context!())
|
|
37
|
+
.expect("error while running tauri application");
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Rust API (Out-of-the-box)
|
|
42
|
+
|
|
43
|
+
After plugin registration, call directly from Rust:
|
|
44
|
+
|
|
45
|
+
```rust
|
|
46
|
+
use tauri_plugin_shizuku::ShizukuExt;
|
|
47
|
+
|
|
48
|
+
let status = app.shizuku().get_status()?;
|
|
49
|
+
let _ = app.shizuku().request_permission(Default::default())?;
|
|
50
|
+
let cmd = app.shizuku().run_adb_command(tauri_plugin_shizuku::RunAdbCommandRequest {
|
|
51
|
+
command: "id".to_string(),
|
|
52
|
+
timeout_ms: Some(15_000),
|
|
53
|
+
})?;
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
No extra manifest edits are required by plugin users. The Android provider and native code are shipped inside this plugin.
|
|
57
|
+
|
|
58
|
+
## JavaScript API
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import {
|
|
62
|
+
getStatus,
|
|
63
|
+
requestPermission,
|
|
64
|
+
openShizuku,
|
|
65
|
+
runAdbCommand,
|
|
66
|
+
getSystemProperty,
|
|
67
|
+
listPackages,
|
|
68
|
+
} from 'tauri-plugin-shizuku-api'
|
|
69
|
+
|
|
70
|
+
const status = await getStatus()
|
|
71
|
+
if (!status.permissionGranted) {
|
|
72
|
+
await openShizuku()
|
|
73
|
+
await requestPermission()
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const commandResult = await runAdbCommand({ command: 'id', timeoutMs: 15000 })
|
|
77
|
+
const release = await getSystemProperty('ro.build.version.release')
|
|
78
|
+
const packages = await listPackages({ includeSystem: false, limit: 30 })
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Android Behavior Notes
|
|
82
|
+
|
|
83
|
+
- This plugin depends on `dev.rikka.shizuku:api` and `dev.rikka.shizuku:provider`.
|
|
84
|
+
- End users still need to install and start Shizuku (or Sui) because this is required by Shizuku's runtime model.
|
|
85
|
+
- `runAdbCommand` currently uses `Shizuku.newProcess` for command execution.
|
|
86
|
+
|
|
87
|
+
## Example App
|
|
88
|
+
|
|
89
|
+
An interactive test console is provided at `examples/tauri-app`.
|
|
90
|
+
|
|
91
|
+
Run steps:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
cd examples/tauri-app
|
|
95
|
+
bun tauri android dev
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
In app:
|
|
99
|
+
|
|
100
|
+
1. Tap `Open Shizuku`
|
|
101
|
+
2. Start Shizuku service in Shizuku app
|
|
102
|
+
3. Tap `Request Permission`
|
|
103
|
+
4. Tap `Refresh Status`
|
|
104
|
+
5. Run command/property/package tests
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@tauri-apps/api/core');
|
|
4
|
+
|
|
5
|
+
async function ping(value) {
|
|
6
|
+
return await core.invoke('plugin:shizuku|ping', {
|
|
7
|
+
payload: {
|
|
8
|
+
value,
|
|
9
|
+
},
|
|
10
|
+
}).then((r) => (r.value ? r.value : null));
|
|
11
|
+
}
|
|
12
|
+
async function getStatus() {
|
|
13
|
+
return await core.invoke('plugin:shizuku|get_status');
|
|
14
|
+
}
|
|
15
|
+
async function requestPermission(payload) {
|
|
16
|
+
return await core.invoke('plugin:shizuku|request_permission', {
|
|
17
|
+
payload,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
async function openShizuku() {
|
|
21
|
+
return await core.invoke('plugin:shizuku|open_shizuku');
|
|
22
|
+
}
|
|
23
|
+
async function runAdbCommand(payload) {
|
|
24
|
+
return await core.invoke('plugin:shizuku|run_adb_command', {
|
|
25
|
+
payload,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
async function getSystemProperty(key) {
|
|
29
|
+
return await core.invoke('plugin:shizuku|get_system_property', {
|
|
30
|
+
payload: { key },
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async function listPackages(payload) {
|
|
34
|
+
return await core.invoke('plugin:shizuku|list_packages', {
|
|
35
|
+
payload,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
exports.getStatus = getStatus;
|
|
40
|
+
exports.getSystemProperty = getSystemProperty;
|
|
41
|
+
exports.listPackages = listPackages;
|
|
42
|
+
exports.openShizuku = openShizuku;
|
|
43
|
+
exports.ping = ping;
|
|
44
|
+
exports.requestPermission = requestPermission;
|
|
45
|
+
exports.runAdbCommand = runAdbCommand;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export declare function ping(value: string): Promise<string | null>;
|
|
2
|
+
export interface ShizukuStatus {
|
|
3
|
+
serviceAvailable: boolean;
|
|
4
|
+
preV11: boolean;
|
|
5
|
+
permissionGranted: boolean;
|
|
6
|
+
shouldShowRequestRationale: boolean;
|
|
7
|
+
canRequestPermission: boolean;
|
|
8
|
+
serverUid?: number;
|
|
9
|
+
serverVersion?: number;
|
|
10
|
+
message?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface RequestPermissionRequest {
|
|
13
|
+
requestCode?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface RequestPermissionResponse {
|
|
16
|
+
requested: boolean;
|
|
17
|
+
granted: boolean;
|
|
18
|
+
message?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface OpenShizukuResponse {
|
|
21
|
+
opened: boolean;
|
|
22
|
+
message?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface RunAdbCommandRequest {
|
|
25
|
+
command: string;
|
|
26
|
+
timeoutMs?: number;
|
|
27
|
+
}
|
|
28
|
+
export interface RunAdbCommandResponse {
|
|
29
|
+
exitCode: number;
|
|
30
|
+
stdout: string;
|
|
31
|
+
stderr: string;
|
|
32
|
+
durationMs: number;
|
|
33
|
+
}
|
|
34
|
+
export interface GetSystemPropertyResponse {
|
|
35
|
+
key: string;
|
|
36
|
+
value?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface ListPackagesRequest {
|
|
39
|
+
includeSystem?: boolean;
|
|
40
|
+
limit?: number;
|
|
41
|
+
}
|
|
42
|
+
export interface ListPackagesResponse {
|
|
43
|
+
packages: string[];
|
|
44
|
+
}
|
|
45
|
+
export declare function getStatus(): Promise<ShizukuStatus>;
|
|
46
|
+
export declare function requestPermission(payload?: RequestPermissionRequest): Promise<RequestPermissionResponse>;
|
|
47
|
+
export declare function openShizuku(): Promise<OpenShizukuResponse>;
|
|
48
|
+
export declare function runAdbCommand(payload: RunAdbCommandRequest): Promise<RunAdbCommandResponse>;
|
|
49
|
+
export declare function getSystemProperty(key: string): Promise<GetSystemPropertyResponse>;
|
|
50
|
+
export declare function listPackages(payload?: ListPackagesRequest): Promise<ListPackagesResponse>;
|
package/dist-js/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { invoke } from '@tauri-apps/api/core';
|
|
2
|
+
|
|
3
|
+
async function ping(value) {
|
|
4
|
+
return await invoke('plugin:shizuku|ping', {
|
|
5
|
+
payload: {
|
|
6
|
+
value,
|
|
7
|
+
},
|
|
8
|
+
}).then((r) => (r.value ? r.value : null));
|
|
9
|
+
}
|
|
10
|
+
async function getStatus() {
|
|
11
|
+
return await invoke('plugin:shizuku|get_status');
|
|
12
|
+
}
|
|
13
|
+
async function requestPermission(payload) {
|
|
14
|
+
return await invoke('plugin:shizuku|request_permission', {
|
|
15
|
+
payload,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
async function openShizuku() {
|
|
19
|
+
return await invoke('plugin:shizuku|open_shizuku');
|
|
20
|
+
}
|
|
21
|
+
async function runAdbCommand(payload) {
|
|
22
|
+
return await invoke('plugin:shizuku|run_adb_command', {
|
|
23
|
+
payload,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
async function getSystemProperty(key) {
|
|
27
|
+
return await invoke('plugin:shizuku|get_system_property', {
|
|
28
|
+
payload: { key },
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
async function listPackages(payload) {
|
|
32
|
+
return await invoke('plugin:shizuku|list_packages', {
|
|
33
|
+
payload,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { getStatus, getSystemProperty, listPackages, openShizuku, ping, requestPermission, runAdbCommand };
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tauri-plugin-shizuku-api",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"author": "You",
|
|
5
|
+
"description": "",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"types": "./dist-js/index.d.ts",
|
|
8
|
+
"main": "./dist-js/index.cjs",
|
|
9
|
+
"module": "./dist-js/index.js",
|
|
10
|
+
"exports": {
|
|
11
|
+
"types": "./dist-js/index.d.ts",
|
|
12
|
+
"import": "./dist-js/index.js",
|
|
13
|
+
"require": "./dist-js/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist-js",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "rollup -c",
|
|
21
|
+
"prepublishOnly": "pnpm build",
|
|
22
|
+
"pretest": "pnpm build"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@tauri-apps/api": "^2.0.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@rollup/plugin-typescript": "^12.0.0",
|
|
29
|
+
"rollup": "^4.9.6",
|
|
30
|
+
"typescript": "^5.3.3",
|
|
31
|
+
"tslib": "^2.6.2"
|
|
32
|
+
}
|
|
33
|
+
}
|