Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,47 @@ import { moduleInfo } from 'kernelsu';
// print moduleId in console
console.log(moduleInfo());
```

### listPackages

List installed packages.

Returns an array of package names.

- `type` `<string>` The type of packages to list: "user", "system", or "all".

```javascript
import { listPackages } from 'kernelsu';
// list user packages
const packages = listPackages("user");
```

- tips: when `listPackages` api is available, you can ksu://icon/{packageName} to get app icon.

``` javascript
img.src = "ksu://icon/" + packageName;
```

### getPackagesInfo

Get information for a list of packages.

Return an array of `PackagesInfo` objects.

- `packages` `<string[]>` The list of package names.

```javascript
import { getPackagesInfo } from 'kernelsu';
const packages = getPackagesInfo(['com.android.settings', 'com.android.shell']);
```

#### PackagesInfo

An object contains:

- `packageName` `<string>` Package name of the application.
- `versionName` `<string>` Version of the application.
- `versionCode` `<number>` Version code of the application.
- `appLabel` `<string>` Display name of the application.
- `isSystem` `<boolean>` Whether the application is a system app.
- `uid` `<number>` UID of the application.
17 changes: 16 additions & 1 deletion js/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,25 @@ declare function toast(message: string);

declare function moduleInfo(): string;

interface PackagesInfo {
packageName: string;
versionName: string;
versionCode: number;
appLabel: string;
isSystem: boolean;
uid: number;
}

declare function listPackages(type: string): string[];

declare function getPackagesInfo(packages: string[]): PackagesInfo[];

export {
exec,
spawn,
fullScreen,
toast,
moduleInfo
moduleInfo,
listPackages,
getPackagesInfo,
}
19 changes: 19 additions & 0 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,22 @@ export function toast(message) {
export function moduleInfo() {
return ksu.moduleInfo();
}

export function listPackages(type) {
try {
return JSON.parse(ksu.listPackages(type));
} catch (error) {
return [];
}
}

export function getPackagesInfo(packages) {
try {
if (typeof packages !== "string") {
packages = JSON.stringify(packages);
}
return JSON.parse(ksu.getPackagesInfo(packages));
} catch (error) {
return [];
}
}
Loading