kokorobox-native 0.6.0 → 0.8.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 +20 -1
- package/index.d.ts +35 -0
- package/index.js +27 -2
- package/package.json +9 -8
package/README.md
CHANGED
|
@@ -19,12 +19,14 @@ macOS, and GNU/Linux. The loader also accepts a development binary through
|
|
|
19
19
|
import {
|
|
20
20
|
getNativeCapabilities,
|
|
21
21
|
getNetworkContext,
|
|
22
|
+
getTrafficPresenterPath,
|
|
22
23
|
inspectApplication,
|
|
23
24
|
} from "kokorobox-native";
|
|
24
25
|
|
|
25
26
|
const capabilities = getNativeCapabilities();
|
|
26
27
|
const network = await getNetworkContext();
|
|
27
28
|
const app = await inspectApplication("/Applications/KokoroBox.app");
|
|
29
|
+
const presenter = getTrafficPresenterPath();
|
|
28
30
|
```
|
|
29
31
|
|
|
30
32
|
The full TypeScript declarations are shipped in
|
|
@@ -35,10 +37,12 @@ The full TypeScript declarations are shipped in
|
|
|
35
37
|
| Area | Exports |
|
|
36
38
|
| --- | --- |
|
|
37
39
|
| Capabilities | `getNativeCapabilities` |
|
|
40
|
+
| Traffic presenter | `getTrafficPresenterPath` |
|
|
38
41
|
| Icons | `fileToDataUrl`, `getAppName` |
|
|
39
|
-
| Applications | `inspectApplication`, `scanWindowsApplications` |
|
|
42
|
+
| Applications | `inspectApplication`, `scanWindowsApplications`, `findExecutables` |
|
|
40
43
|
| Rules | `fileToStr` |
|
|
41
44
|
| Platform | `getLaunchAtLogin`, `setLaunchAtLogin`, `getNetworkContext` |
|
|
45
|
+
| macOS service | `getMacosManagedServiceStatus`, `registerMacosManagedService`, `unregisterMacosManagedService`, `reloadMacosManagedService`, `openMacosLoginItemsSettings` |
|
|
42
46
|
| Core permissions | `getCorePrivilegeStatus`, `setCorePrivileges` |
|
|
43
47
|
| Windows | `getCurrentUserSid`, `isRunningAsAdmin`, `runElevated`, `launchElevated`, `launchUnelevated`, `setupFirewallRules` |
|
|
44
48
|
|
|
@@ -48,6 +52,11 @@ signing identifier on macOS. `scanWindowsApplications` is asynchronous and
|
|
|
48
52
|
Windows-only; it accepts an optional result limit and executable-name exclusion
|
|
49
53
|
list.
|
|
50
54
|
|
|
55
|
+
`findExecutables` asynchronously searches absolute additional directories,
|
|
56
|
+
`PATH`, and platform-standard binary locations without spawning command-line
|
|
57
|
+
tools. It returns canonical paths for stable deduplication; prefix matching is
|
|
58
|
+
available only when explicitly requested.
|
|
59
|
+
|
|
51
60
|
`fileToStr` converts a rule file and returns each generated output keyed by its
|
|
52
61
|
behavior, metadata for those outputs, and rules that were skipped. Its optional
|
|
53
62
|
`RuleConvertOptions` accepts Mihomo, General, Egern, and sing-box targets and
|
|
@@ -63,12 +72,22 @@ directly from SystemConfiguration without parsing command output.
|
|
|
63
72
|
Windows obtains the preferred interface and DNS servers from IP Helper and the
|
|
64
73
|
SSID from Native Wi-Fi, without spawning PowerShell.
|
|
65
74
|
|
|
75
|
+
The macOS managed-service functions accept the basename of an embedded
|
|
76
|
+
LaunchDaemon plist and use `SMAppService` directly. They return an explicit
|
|
77
|
+
`requires-approval` state when an administrator must approve the daemon in
|
|
78
|
+
System Settings.
|
|
79
|
+
|
|
66
80
|
Core-file privilege APIs are supported on macOS and Linux. They accept only
|
|
67
81
|
canonical, existing executables named `mihomo` or `mihomo-alpha`; callers cannot
|
|
68
82
|
use them as a general privileged-command interface. See the repository's
|
|
69
83
|
[platform-services contract](../docs/platform-services.md) for validation and
|
|
70
84
|
platform behavior.
|
|
71
85
|
|
|
86
|
+
`getTrafficPresenterPath()` returns the presenter executable shipped in the
|
|
87
|
+
same platform package as the loaded native binding. The presenter accepts the
|
|
88
|
+
versioned JSON-lines protocol documented by the `traffic-presenter` crate on
|
|
89
|
+
standard input and terminates when its parent closes that stream.
|
|
90
|
+
|
|
72
91
|
## Platform behavior
|
|
73
92
|
|
|
74
93
|
Use `getNativeCapabilities()` before enabling an optional system feature.
|
package/index.d.ts
CHANGED
|
@@ -5,15 +5,41 @@ export interface FirewallRule {
|
|
|
5
5
|
|
|
6
6
|
export interface NativeCapabilities {
|
|
7
7
|
applicationInspection: boolean;
|
|
8
|
+
executableDiscovery: boolean;
|
|
8
9
|
windowsApplicationScan: boolean;
|
|
9
10
|
windowsAccount: boolean;
|
|
10
11
|
windowsElevation: boolean;
|
|
11
12
|
windowsFirewall: boolean;
|
|
12
13
|
launchAtLogin: boolean;
|
|
13
14
|
networkContext: boolean;
|
|
15
|
+
macosServiceManagement: boolean;
|
|
14
16
|
coreFilePrivileges: boolean;
|
|
15
17
|
}
|
|
16
18
|
|
|
19
|
+
export interface ExecutableSearchOptions {
|
|
20
|
+
/** Safe executable basenames, without directory components. */
|
|
21
|
+
names: string[];
|
|
22
|
+
/** Absolute directories searched before PATH and platform-standard locations. */
|
|
23
|
+
additionalPaths?: string[];
|
|
24
|
+
/** Also match executable names beginning with a supplied name. */
|
|
25
|
+
matchNamePrefixes?: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface ExecutableCandidate {
|
|
29
|
+
/** The discovered path, which may be a symlink. */
|
|
30
|
+
path: string;
|
|
31
|
+
/** The canonical executable path used for deduplication. */
|
|
32
|
+
canonicalPath: string;
|
|
33
|
+
name: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type MacOSManagedServiceStatus =
|
|
37
|
+
| "not-registered"
|
|
38
|
+
| "enabled"
|
|
39
|
+
| "requires-approval"
|
|
40
|
+
| "not-found"
|
|
41
|
+
| "unknown";
|
|
42
|
+
|
|
17
43
|
export interface LaunchAtLoginOptions {
|
|
18
44
|
/** Stable, filesystem-safe identifier, such as `com.amamiyakokoro.kokorobox`. */
|
|
19
45
|
identifier: string;
|
|
@@ -109,12 +135,21 @@ export function fileToStr(
|
|
|
109
135
|
): RuleStringResult;
|
|
110
136
|
export function getAppName(path: string): string;
|
|
111
137
|
export function getNativeCapabilities(): NativeCapabilities;
|
|
138
|
+
/** Resolve the executable shipped beside the current platform binding. */
|
|
139
|
+
export function getTrafficPresenterPath(): string;
|
|
140
|
+
export function findExecutables(options: ExecutableSearchOptions): Promise<ExecutableCandidate[]>;
|
|
112
141
|
export function getLaunchAtLogin(options: LaunchAtLoginOptions): Promise<LaunchAtLoginStatus>;
|
|
113
142
|
export function setLaunchAtLogin(
|
|
114
143
|
options: LaunchAtLoginOptions,
|
|
115
144
|
enabled: boolean,
|
|
116
145
|
): Promise<LaunchAtLoginStatus>;
|
|
117
146
|
export function getNetworkContext(): Promise<NetworkContext>;
|
|
147
|
+
/** Query a LaunchDaemon plist embedded in the calling macOS application. */
|
|
148
|
+
export function getMacosManagedServiceStatus(plistName: string): MacOSManagedServiceStatus;
|
|
149
|
+
export function registerMacosManagedService(plistName: string): MacOSManagedServiceStatus;
|
|
150
|
+
export function unregisterMacosManagedService(plistName: string): MacOSManagedServiceStatus;
|
|
151
|
+
export function reloadMacosManagedService(plistName: string): MacOSManagedServiceStatus;
|
|
152
|
+
export function openMacosLoginItemsSettings(): void;
|
|
118
153
|
/** Inspect only validated `mihomo` and `mihomo-alpha` executable paths. */
|
|
119
154
|
export function getCorePrivilegeStatus(paths: string[]): CorePrivilegeStatus[];
|
|
120
155
|
/** Grant or revoke the constrained Unix core-file privilege. */
|
package/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// @ts-nocheck
|
|
4
4
|
|
|
5
5
|
import { existsSync } from 'node:fs'
|
|
6
|
-
import { join } from "node:path";
|
|
6
|
+
import { dirname, join } from "node:path";
|
|
7
7
|
import { createRequire } from "node:module";
|
|
8
8
|
|
|
9
9
|
const require = createRequire(import.meta.url);
|
|
@@ -15,6 +15,7 @@ const __dirname = new URL(".", import.meta.url).pathname.replace(
|
|
|
15
15
|
const packageName = "kokorobox-native";
|
|
16
16
|
const binaryName = "kokorobox-native";
|
|
17
17
|
const loadErrors = [];
|
|
18
|
+
let loadedTuple = null;
|
|
18
19
|
|
|
19
20
|
function requireLocal(tuple) {
|
|
20
21
|
const filename = join(__dirname, `${binaryName}.${tuple}.node`);
|
|
@@ -37,7 +38,25 @@ function requirePackage(tuple) {
|
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
function requireBinding(tuple) {
|
|
40
|
-
|
|
41
|
+
const binding = requireLocal(tuple) || requirePackage(tuple);
|
|
42
|
+
if (binding) loadedTuple = tuple;
|
|
43
|
+
return binding;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function getTrafficPresenterPath() {
|
|
47
|
+
const filename = `kokorobox-traffic-presenter${process.platform === "win32" ? ".exe" : ""}`;
|
|
48
|
+
const localPath = join(__dirname, filename);
|
|
49
|
+
if (existsSync(localPath)) return localPath;
|
|
50
|
+
|
|
51
|
+
if (loadedTuple) {
|
|
52
|
+
const packageEntry = require.resolve(`${packageName}-${loadedTuple}`);
|
|
53
|
+
const packagedPath = join(dirname(packageEntry), filename);
|
|
54
|
+
if (existsSync(packagedPath)) return packagedPath;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
throw new Error(
|
|
58
|
+
`Traffic presenter is missing for ${process.platform} ${process.arch}`,
|
|
59
|
+
);
|
|
41
60
|
}
|
|
42
61
|
|
|
43
62
|
function requireNative() {
|
|
@@ -81,9 +100,15 @@ export const fileToDataUrl = nativeBinding.fileToDataUrl;
|
|
|
81
100
|
export const fileToStr = nativeBinding.fileToStr;
|
|
82
101
|
export const getAppName = nativeBinding.getAppName;
|
|
83
102
|
export const getNativeCapabilities = nativeBinding.getNativeCapabilities;
|
|
103
|
+
export const findExecutables = nativeBinding.findExecutables;
|
|
84
104
|
export const getLaunchAtLogin = nativeBinding.getLaunchAtLogin;
|
|
85
105
|
export const setLaunchAtLogin = nativeBinding.setLaunchAtLogin;
|
|
86
106
|
export const getNetworkContext = nativeBinding.getNetworkContext;
|
|
107
|
+
export const getMacosManagedServiceStatus = nativeBinding.getMacosManagedServiceStatus;
|
|
108
|
+
export const registerMacosManagedService = nativeBinding.registerMacosManagedService;
|
|
109
|
+
export const unregisterMacosManagedService = nativeBinding.unregisterMacosManagedService;
|
|
110
|
+
export const reloadMacosManagedService = nativeBinding.reloadMacosManagedService;
|
|
111
|
+
export const openMacosLoginItemsSettings = nativeBinding.openMacosLoginItemsSettings;
|
|
87
112
|
export const getCorePrivilegeStatus = nativeBinding.getCorePrivilegeStatus;
|
|
88
113
|
export const setCorePrivileges = nativeBinding.setCorePrivileges;
|
|
89
114
|
export const inspectApplication = nativeBinding.inspectApplication;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kokorobox-native",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "KokoroBox native bridge",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -35,7 +35,8 @@
|
|
|
35
35
|
"build": "napi build --platform --release --strip --no-js --dts napi.generated.d.ts",
|
|
36
36
|
"build:debug": "napi build --platform --no-js --dts napi.generated.d.ts",
|
|
37
37
|
"create-npm-dirs": "napi create-npm-dirs",
|
|
38
|
-
"artifacts": "napi artifacts"
|
|
38
|
+
"artifacts": "napi artifacts",
|
|
39
|
+
"package-presenters": "node package-presenters.mjs"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
42
|
"@napi-rs/cli": "^3.8.6"
|
|
@@ -47,11 +48,11 @@
|
|
|
47
48
|
"access": "public"
|
|
48
49
|
},
|
|
49
50
|
"optionalDependencies": {
|
|
50
|
-
"kokorobox-native-win32-x64-msvc": "0.
|
|
51
|
-
"kokorobox-native-win32-arm64-msvc": "0.
|
|
52
|
-
"kokorobox-native-darwin-x64": "0.
|
|
53
|
-
"kokorobox-native-darwin-arm64": "0.
|
|
54
|
-
"kokorobox-native-linux-x64-gnu": "0.
|
|
55
|
-
"kokorobox-native-linux-arm64-gnu": "0.
|
|
51
|
+
"kokorobox-native-win32-x64-msvc": "0.8.0",
|
|
52
|
+
"kokorobox-native-win32-arm64-msvc": "0.8.0",
|
|
53
|
+
"kokorobox-native-darwin-x64": "0.8.0",
|
|
54
|
+
"kokorobox-native-darwin-arm64": "0.8.0",
|
|
55
|
+
"kokorobox-native-linux-x64-gnu": "0.8.0",
|
|
56
|
+
"kokorobox-native-linux-arm64-gnu": "0.8.0"
|
|
56
57
|
}
|
|
57
58
|
}
|