kokorobox-native 0.3.0 → 0.5.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 +78 -9
- package/index.d.ts +45 -0
- package/index.js +5 -2
- package/package.json +8 -12
package/README.md
CHANGED
|
@@ -1,15 +1,84 @@
|
|
|
1
1
|
# kokorobox-native
|
|
2
2
|
|
|
3
|
-
Native Node.js APIs used by KokoroBox Desktop.
|
|
3
|
+
Native Node.js APIs used by KokoroBox Desktop. This package is an ESM loader:
|
|
4
|
+
it selects the native binary for the current operating system and architecture.
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
directory scanning, rule conversion, Windows elevation and SID queries, and Windows Firewall rule
|
|
7
|
-
management. Platform-specific N-API binaries are selected at runtime.
|
|
6
|
+
## Installation
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
```sh
|
|
9
|
+
pnpm add kokorobox-native
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Prebuilt optional packages are available for x64 and arm64 Windows (MSVC),
|
|
13
|
+
macOS, and GNU/Linux. The loader also accepts a development binary through
|
|
14
|
+
`NAPI_RS_NATIVE_LIBRARY_PATH`.
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import {
|
|
20
|
+
getNativeCapabilities,
|
|
21
|
+
getNetworkContext,
|
|
22
|
+
inspectApplication,
|
|
23
|
+
} from "kokorobox-native";
|
|
24
|
+
|
|
25
|
+
const capabilities = getNativeCapabilities();
|
|
26
|
+
const network = await getNetworkContext();
|
|
27
|
+
const app = await inspectApplication("/Applications/KokoroBox.app");
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The full TypeScript declarations are shipped in
|
|
31
|
+
[`index.d.ts`](index.d.ts).
|
|
32
|
+
|
|
33
|
+
## API overview
|
|
34
|
+
|
|
35
|
+
| Area | Exports |
|
|
36
|
+
| --- | --- |
|
|
37
|
+
| Capabilities | `getNativeCapabilities` |
|
|
38
|
+
| Icons | `fileToDataUrl`, `getAppName` |
|
|
39
|
+
| Applications | `inspectApplication`, `scanWindowsApplications` |
|
|
40
|
+
| Rules | `fileToStr` |
|
|
41
|
+
| Platform | `getLaunchAtLogin`, `setLaunchAtLogin`, `getNetworkContext` |
|
|
42
|
+
| Core permissions | `getCorePrivilegeStatus`, `setCorePrivileges` |
|
|
43
|
+
| Windows | `getCurrentUserSid`, `isRunningAsAdmin`, `runElevated`, `setupFirewallRules` |
|
|
44
|
+
|
|
45
|
+
`inspectApplication` validates the input for the current platform and resolves
|
|
46
|
+
it to a routing identifier: an executable path on Windows and Linux, or a code
|
|
47
|
+
signing identifier on macOS. `scanWindowsApplications` is asynchronous and
|
|
48
|
+
Windows-only; it accepts an optional result limit and executable-name exclusion
|
|
49
|
+
list.
|
|
50
|
+
|
|
51
|
+
`fileToStr` converts a rule file and returns each generated output keyed by its
|
|
52
|
+
behavior, metadata for those outputs, and rules that were skipped. Its optional
|
|
53
|
+
`RuleConvertOptions` accepts Mihomo, General, Egern, and sing-box targets and
|
|
54
|
+
the formats listed in the TypeScript declaration.
|
|
55
|
+
|
|
56
|
+
Launch-at-login requires a stable filesystem-safe `identifier`, a display name,
|
|
57
|
+
and an absolute executable path. It returns the selected backend: Windows Task
|
|
58
|
+
Scheduler, macOS Login Items, or Linux XDG Autostart. Network context is
|
|
59
|
+
best-effort, so optional fields such as the default interface and SSID may be
|
|
60
|
+
absent.
|
|
61
|
+
|
|
62
|
+
Core-file privilege APIs are supported on macOS and Linux. They accept only
|
|
63
|
+
canonical, existing executables named `mihomo` or `mihomo-alpha`; callers cannot
|
|
64
|
+
use them as a general privileged-command interface. See the repository's
|
|
65
|
+
[platform-services contract](../docs/platform-services.md) for validation and
|
|
66
|
+
platform behavior.
|
|
67
|
+
|
|
68
|
+
## Platform behavior
|
|
69
|
+
|
|
70
|
+
Use `getNativeCapabilities()` before enabling an optional system feature.
|
|
71
|
+
Windows account, elevation, Firewall, and application-scan APIs report an
|
|
72
|
+
`UNSUPPORTED_PLATFORM:` error on other operating systems instead of behaving as
|
|
73
|
+
no-ops.
|
|
74
|
+
|
|
75
|
+
## Contributing
|
|
76
|
+
|
|
77
|
+
The source is a two-crate Rust workspace. The root crate implements native
|
|
78
|
+
behavior; `napi/` maps it into this package’s JavaScript API. See the root
|
|
79
|
+
[README](../README.md#repository-structure) for the complete layout and build
|
|
80
|
+
commands.
|
|
11
81
|
|
|
12
82
|
This project is derived from
|
|
13
|
-
[`UruhaLushia/sparkle-native`](https://github.com/UruhaLushia/sparkle-native)
|
|
14
|
-
under GPL-3.0-only.
|
|
15
|
-
evolve with product-specific APIs.
|
|
83
|
+
[`UruhaLushia/sparkle-native`](https://github.com/UruhaLushia/sparkle-native)
|
|
84
|
+
and is licensed under GPL-3.0-only.
|
package/index.d.ts
CHANGED
|
@@ -9,6 +9,38 @@ export interface NativeCapabilities {
|
|
|
9
9
|
windowsAccount: boolean;
|
|
10
10
|
windowsElevation: boolean;
|
|
11
11
|
windowsFirewall: boolean;
|
|
12
|
+
launchAtLogin: boolean;
|
|
13
|
+
networkContext: boolean;
|
|
14
|
+
coreFilePrivileges: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface LaunchAtLoginOptions {
|
|
18
|
+
/** Stable, filesystem-safe identifier, such as `com.amamiyakokoro.kokorobox`. */
|
|
19
|
+
identifier: string;
|
|
20
|
+
displayName: string;
|
|
21
|
+
executablePath: string;
|
|
22
|
+
arguments?: string[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface LaunchAtLoginStatus {
|
|
26
|
+
enabled: boolean;
|
|
27
|
+
backend: "windows-task-scheduler" | "macos-login-item" | "linux-xdg-autostart";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Best-effort active-network state. Unavailable fields are omitted instead of guessed. */
|
|
31
|
+
export interface NetworkContext {
|
|
32
|
+
defaultInterface?: string;
|
|
33
|
+
/** Active network-service name. Currently populated on macOS and Linux. */
|
|
34
|
+
defaultService?: string;
|
|
35
|
+
dnsServers: string[];
|
|
36
|
+
ssid?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface CorePrivilegeStatus {
|
|
40
|
+
/** Canonical path validated by the native library. */
|
|
41
|
+
path: string;
|
|
42
|
+
/** Whether the set-user-ID bit is present. */
|
|
43
|
+
granted: boolean;
|
|
12
44
|
}
|
|
13
45
|
|
|
14
46
|
export interface ApplicationInfo {
|
|
@@ -75,6 +107,19 @@ export function fileToStr(
|
|
|
75
107
|
): RuleStringResult;
|
|
76
108
|
export function getAppName(path: string): string;
|
|
77
109
|
export function getNativeCapabilities(): NativeCapabilities;
|
|
110
|
+
export function getLaunchAtLogin(options: LaunchAtLoginOptions): Promise<LaunchAtLoginStatus>;
|
|
111
|
+
export function setLaunchAtLogin(
|
|
112
|
+
options: LaunchAtLoginOptions,
|
|
113
|
+
enabled: boolean,
|
|
114
|
+
): Promise<LaunchAtLoginStatus>;
|
|
115
|
+
export function getNetworkContext(): Promise<NetworkContext>;
|
|
116
|
+
/** Inspect only validated `mihomo` and `mihomo-alpha` executable paths. */
|
|
117
|
+
export function getCorePrivilegeStatus(paths: string[]): CorePrivilegeStatus[];
|
|
118
|
+
/** Grant or revoke the constrained Unix core-file privilege. */
|
|
119
|
+
export function setCorePrivileges(
|
|
120
|
+
paths: string[],
|
|
121
|
+
enabled: boolean,
|
|
122
|
+
): Promise<CorePrivilegeStatus[]>;
|
|
78
123
|
export function inspectApplication(path: string): Promise<ApplicationInfo>;
|
|
79
124
|
export function scanWindowsApplications(
|
|
80
125
|
directory: string,
|
package/index.js
CHANGED
|
@@ -52,14 +52,12 @@ function requireNative() {
|
|
|
52
52
|
if (process.platform === "win32") {
|
|
53
53
|
if (process.arch === "x64") return requireBinding("win32-x64-msvc");
|
|
54
54
|
if (process.arch === "arm64") return requireBinding("win32-arm64-msvc");
|
|
55
|
-
if (process.arch === "ia32") return requireBinding("win32-ia32-msvc");
|
|
56
55
|
} else if (process.platform === "darwin") {
|
|
57
56
|
if (process.arch === "x64") return requireBinding("darwin-x64");
|
|
58
57
|
if (process.arch === "arm64") return requireBinding("darwin-arm64");
|
|
59
58
|
} else if (process.platform === "linux") {
|
|
60
59
|
if (process.arch === "x64") return requireBinding("linux-x64-gnu");
|
|
61
60
|
if (process.arch === "arm64") return requireBinding("linux-arm64-gnu");
|
|
62
|
-
if (process.arch === "loong64") return requireBinding("linux-loong64-gnu");
|
|
63
61
|
}
|
|
64
62
|
|
|
65
63
|
loadErrors.push(
|
|
@@ -83,6 +81,11 @@ export const fileToDataUrl = nativeBinding.fileToDataUrl;
|
|
|
83
81
|
export const fileToStr = nativeBinding.fileToStr;
|
|
84
82
|
export const getAppName = nativeBinding.getAppName;
|
|
85
83
|
export const getNativeCapabilities = nativeBinding.getNativeCapabilities;
|
|
84
|
+
export const getLaunchAtLogin = nativeBinding.getLaunchAtLogin;
|
|
85
|
+
export const setLaunchAtLogin = nativeBinding.setLaunchAtLogin;
|
|
86
|
+
export const getNetworkContext = nativeBinding.getNetworkContext;
|
|
87
|
+
export const getCorePrivilegeStatus = nativeBinding.getCorePrivilegeStatus;
|
|
88
|
+
export const setCorePrivileges = nativeBinding.setCorePrivileges;
|
|
86
89
|
export const inspectApplication = nativeBinding.inspectApplication;
|
|
87
90
|
export const scanWindowsApplications = nativeBinding.scanWindowsApplications;
|
|
88
91
|
export const getCurrentUserSid = nativeBinding.getCurrentUserSid;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kokorobox-native",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "KokoroBox native bridge",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -24,13 +24,11 @@
|
|
|
24
24
|
"binaryName": "kokorobox-native",
|
|
25
25
|
"targets": [
|
|
26
26
|
"x86_64-pc-windows-msvc",
|
|
27
|
-
"i686-pc-windows-msvc",
|
|
28
27
|
"aarch64-pc-windows-msvc",
|
|
29
28
|
"x86_64-apple-darwin",
|
|
30
29
|
"aarch64-apple-darwin",
|
|
31
30
|
"x86_64-unknown-linux-gnu",
|
|
32
|
-
"aarch64-unknown-linux-gnu"
|
|
33
|
-
"loongarch64-unknown-linux-gnu"
|
|
31
|
+
"aarch64-unknown-linux-gnu"
|
|
34
32
|
]
|
|
35
33
|
},
|
|
36
34
|
"scripts": {
|
|
@@ -49,13 +47,11 @@
|
|
|
49
47
|
"access": "public"
|
|
50
48
|
},
|
|
51
49
|
"optionalDependencies": {
|
|
52
|
-
"kokorobox-native-win32-x64-msvc": "0.
|
|
53
|
-
"kokorobox-native-win32-
|
|
54
|
-
"kokorobox-native-
|
|
55
|
-
"kokorobox-native-darwin-
|
|
56
|
-
"kokorobox-native-
|
|
57
|
-
"kokorobox-native-linux-
|
|
58
|
-
"kokorobox-native-linux-arm64-gnu": "0.3.0",
|
|
59
|
-
"kokorobox-native-linux-loong64-gnu": "0.3.0"
|
|
50
|
+
"kokorobox-native-win32-x64-msvc": "0.5.0",
|
|
51
|
+
"kokorobox-native-win32-arm64-msvc": "0.5.0",
|
|
52
|
+
"kokorobox-native-darwin-x64": "0.5.0",
|
|
53
|
+
"kokorobox-native-darwin-arm64": "0.5.0",
|
|
54
|
+
"kokorobox-native-linux-x64-gnu": "0.5.0",
|
|
55
|
+
"kokorobox-native-linux-arm64-gnu": "0.5.0"
|
|
60
56
|
}
|
|
61
57
|
}
|