kokorobox-native 0.15.0 → 0.16.1

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.
Files changed (4) hide show
  1. package/README.md +13 -115
  2. package/index.d.ts +11 -0
  3. package/index.js +18 -0
  4. package/package.json +7 -7
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # kokorobox-native
2
2
 
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.
3
+ Native Node.js APIs used by KokoroBox Desktop. This ESM package selects the
4
+ native binary for the current operating system and architecture.
5
5
 
6
6
  ## Installation
7
7
 
@@ -9,8 +9,8 @@ it selects the native binary for the current operating system and architecture.
9
9
  pnpm add kokorobox-native
10
10
  ```
11
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
12
+ Prebuilt optional packages support x64 and arm64 Windows (MSVC), macOS, and
13
+ GNU/Linux. For local development, the loader also accepts
14
14
  `NAPI_RS_NATIVE_LIBRARY_PATH`.
15
15
 
16
16
  ## Usage
@@ -19,125 +19,23 @@ macOS, and GNU/Linux. The loader also accepts a development binary through
19
19
  import {
20
20
  getNativeCapabilities,
21
21
  getNetworkContext,
22
- getTrafficPresenterPath,
23
22
  inspectApplication,
24
23
  } from "kokorobox-native";
25
24
 
26
25
  const capabilities = getNativeCapabilities();
27
26
  const network = await getNetworkContext();
28
27
  const app = await inspectApplication("/Applications/KokoroBox.app");
29
- const presenter = getTrafficPresenterPath();
30
28
  ```
31
29
 
32
- The full TypeScript declarations are shipped in
33
- [`index.d.ts`](index.d.ts).
30
+ Check `getNativeCapabilities()` before using optional platform features.
34
31
 
35
- ## API overview
32
+ ## Documentation
36
33
 
37
- | Area | Exports |
38
- | --- | --- |
39
- | Capabilities | `getNativeCapabilities` |
40
- | Traffic presenter | `getTrafficPresenterPath` |
41
- | Icons | `fileToDataUrl`, `getAppName` |
42
- | Applications | `inspectApplication`, `scanWindowsApplications`, `findExecutables` |
43
- | Rules | `fileToStr` |
44
- | Platform | `getLaunchAtLogin`, `setLaunchAtLogin`, `getNetworkContext` |
45
- | macOS service | `getMacosManagedServiceStatus`, `registerMacosManagedService`, `unregisterMacosManagedService`, `reloadMacosManagedService`, `openMacosLoginItemsSettings` |
46
- | macOS application routing | `applyMacosApplicationRouting`, `getMacosApplicationRoutingStatus`, `stopMacosApplicationRouting`, `openMacosApplicationRoutingSettings` |
47
- | Core permissions | `getCorePrivilegeStatus`, `setCorePrivileges` |
48
- | Privileged operations | `runServiceLifecycleElevated`, `cleanupLegacyMacosService`, `stopMacosManagedService`, `repairManagedFilePermissions` |
49
- | Windows | `getCurrentUserSid`, `isRunningAsAdmin`, `relaunchCurrentApplicationWithPrivilege`, `ensureKokoroBoxCoreFirewall` |
34
+ - [JavaScript API guide](../docs/api.md)
35
+ - [TypeScript declarations](index.d.ts)
36
+ - [Platform behavior and security contract](../docs/platform-services.md)
37
+ - [Traffic presenter protocol](../docs/traffic-presenter.md)
38
+ - [Repository layout and build commands](../README.md)
50
39
 
51
- `inspectApplication` validates the input for the current platform and resolves
52
- it to a routing identifier: an executable path on Windows and Linux, or a code
53
- signing identifier on macOS. `scanWindowsApplications` is asynchronous and
54
- Windows-only; it accepts an optional result limit and executable-name exclusion
55
- list.
56
-
57
- `findExecutables` asynchronously searches absolute additional directories,
58
- `PATH`, and platform-standard binary locations without spawning command-line
59
- tools. It returns canonical paths for stable deduplication; prefix matching is
60
- available only when explicitly requested.
61
-
62
- `ensureKokoroBoxCoreFirewall` accepts the two Mihomo executable paths and the
63
- KokoroBox application path. Native fixes the three rule names and validates
64
- the executable basenames before changing Windows Firewall state.
65
-
66
- `fileToStr` converts a rule file and returns each generated output keyed by its
67
- behavior, metadata for those outputs, and rules that were skipped. Its optional
68
- `RuleConvertOptions` accepts Mihomo, General, Egern, and sing-box targets and
69
- the formats listed in the TypeScript declaration.
70
-
71
- Launch-at-login requires a stable filesystem-safe `identifier`, a display name,
72
- and an absolute executable path. It returns the selected backend: the Windows
73
- current-user Run key, macOS `SMAppService.mainApp`, or Linux XDG Autostart. On
74
- macOS, `requiresApproval` reports when the entry is registered but still needs
75
- approval in System Settings. Network context is best-effort, so optional fields
76
- such as the default interface and SSID may be absent. macOS obtains this state
77
- directly from SystemConfiguration without parsing command output.
78
- Windows obtains the preferred interface and DNS servers from IP Helper and the
79
- SSID from Native Wi-Fi, without spawning PowerShell.
80
-
81
- The macOS managed-service functions accept the basename of an embedded
82
- LaunchDaemon plist and use `SMAppService` directly. They return an explicit
83
- `requires-approval` state when an administrator must approve the daemon in
84
- System Settings.
85
-
86
- The macOS application-routing functions run the bounded control plane off the
87
- Node.js main thread. Their typed configuration omits fixed protocol details
88
- such as version, fail-closed behavior, loopback hosts, and reserved ports; the
89
- native layer owns and validates that wire envelope. Packet forwarding continues
90
- to run in the separate System Extension process.
91
-
92
- Core-file privilege APIs are supported on macOS and Linux. They accept only
93
- canonical, existing executables named `mihomo` or `mihomo-alpha`; callers cannot
94
- use them as a general privileged-command interface. See the repository's
95
- [platform-services contract](../docs/platform-services.md) for validation and
96
- platform behavior.
97
-
98
- `getTrafficPresenterPath()` returns the presenter executable shipped in the
99
- same platform package as the loaded native binding. The presenter accepts the
100
- versioned JSON-lines protocol documented by the `traffic-presenter` crate on
101
- standard input and terminates when its parent closes that stream.
102
-
103
- ## Platform behavior
104
-
105
- Use `getNativeCapabilities()` before enabling an optional system feature.
106
- Windows account, elevation, Firewall, and application-scan APIs report an
107
- `UNSUPPORTED_PLATFORM:` error on other operating systems instead of behaving as
108
- no-ops.
109
-
110
- The capability contract includes dedicated flags for APIs that have narrower
111
- support than the package itself:
112
-
113
- | Capability | Supported platforms |
114
- | --- | --- |
115
- | `serviceLifecycle` | Windows, macOS, Linux |
116
- | `managedFilePermissions` | macOS, Linux |
117
- | `windowsPrivilegeRelaunch` | Windows |
118
- | `windowsUwpLoopback` | Windows |
119
-
120
- Use these flags instead of inferring availability from `process.platform` or
121
- from a related but broader capability.
122
-
123
- `runServiceLifecycleElevated(options)` accepts only the KokoroBox Service
124
- `init`, `install`, `uninstall`, `start`, `stop`, and `restart` actions. macOS
125
- legacy-service cleanup, managed-service stopping, and managed-file permission
126
- repair are separate purpose-specific APIs.
127
-
128
- `relaunchCurrentApplicationWithPrivilege(args, elevated)` starts a new copy of
129
- the current Windows application without accepting an executable path. An
130
- elevated relaunch presents the standard UAC prompt; the unelevated path uses
131
- the interactive desktop shell token. It does not configure persistent
132
- elevation.
133
-
134
- ## Contributing
135
-
136
- The source is a two-crate Rust workspace. The root crate implements native
137
- behavior; `napi/` maps it into this package’s JavaScript API. See the root
138
- [README](../README.md#repository-structure) for the complete layout and build
139
- commands.
140
-
141
- This project is derived from
142
- [`UruhaLushia/sparkle-native`](https://github.com/UruhaLushia/sparkle-native)
143
- and is licensed under GPL-3.0-only.
40
+ Derived from [UruhaLushia/sparkle-native](https://github.com/UruhaLushia/sparkle-native)
41
+ and licensed under GPL-3.0-only.
package/index.d.ts CHANGED
@@ -25,12 +25,15 @@ export interface NativeCapabilities {
25
25
  serviceLifecycle: boolean;
26
26
  managedFilePermissions: boolean;
27
27
  macosServiceManagement: boolean;
28
+ macosServiceProcessStatus: boolean;
28
29
  macosApplicationRouting: boolean;
29
30
  windowsPrivilegeRelaunch: boolean;
30
31
  windowsUwpLoopback: boolean;
32
+ windowsServiceStatus: boolean;
31
33
  coreFilePrivileges: boolean;
32
34
  serviceIdentity: boolean;
33
35
  linuxTerminalProxy: boolean;
36
+ linuxServiceStatus: boolean;
34
37
  }
35
38
 
36
39
  export interface ExecutableSearchOptions {
@@ -190,12 +193,18 @@ export function fileToStr(
190
193
  ): RuleStringResult;
191
194
  export function getAppName(path: string): string;
192
195
  export function getNativeCapabilities(): NativeCapabilities;
196
+ /** Read-only status of KokoroBoxService from the Windows Service Control Manager. */
197
+ export function getWindowsServiceStatus(): "running" | "stopped" | "paused" | "not-installed" | "unknown";
198
+ /** Read-only status of the system-wide KokoroBoxService systemd unit. */
199
+ export function getLinuxServiceStatus(): Promise<"running" | "stopped" | "not-installed" | "unknown">;
193
200
  /** Write KokoroBox's Linux user-session proxy file and update systemd --user over D-Bus. */
194
201
  export function setTerminalProxyEnvironment(host: string, port: number, bypass: string[]): Promise<boolean>;
195
202
  /** Remove only KokoroBox's Linux user-session proxy file and clear its session variables. */
196
203
  export function clearTerminalProxyEnvironment(): Promise<boolean | null>;
197
204
  /** Resolve the executable shipped beside the current platform binding. */
198
205
  export function getTrafficPresenterPath(): string;
206
+ /** Resolve the Windows portable updater sidecar shipped with the native platform package. */
207
+ export function getPortableUpdaterPath(): string;
199
208
  export function findExecutables(options: ExecutableSearchOptions): Promise<ExecutableCandidate[]>;
200
209
  export function getLaunchAtLogin(options: LaunchAtLoginOptions): Promise<LaunchAtLoginStatus>;
201
210
  export function setLaunchAtLogin(
@@ -210,6 +219,8 @@ export function waitForNetworkContextChange(
210
219
  ): Promise<NetworkContext | null>;
211
220
  /** Query a LaunchDaemon plist embedded in the calling macOS application. */
212
221
  export function getMacosManagedServiceStatus(plistName: string): MacOSManagedServiceStatus;
222
+ /** Query launchd's process state for the fixed KokoroBoxService system daemon. */
223
+ export function getMacosServiceProcessStatus(): Promise<"running" | "stopped" | "not-installed" | "unknown">;
213
224
  export function registerMacosManagedService(plistName: string): MacOSManagedServiceStatus;
214
225
  export function unregisterMacosManagedService(plistName: string): MacOSManagedServiceStatus;
215
226
  export function reloadMacosManagedService(plistName: string): MacOSManagedServiceStatus;
package/index.js CHANGED
@@ -59,6 +59,21 @@ export function getTrafficPresenterPath() {
59
59
  );
60
60
  }
61
61
 
62
+ export function getPortableUpdaterPath() {
63
+ if (process.platform !== "win32") {
64
+ throw new Error("Portable updater is only available on Windows");
65
+ }
66
+ const filename = "kokorobox-portable-updater.exe";
67
+ const localPath = join(__dirname, filename);
68
+ if (existsSync(localPath)) return localPath;
69
+ if (loadedTuple) {
70
+ const packageEntry = require.resolve(`${packageName}-${loadedTuple}`);
71
+ const packagedPath = join(dirname(packageEntry), filename);
72
+ if (existsSync(packagedPath)) return packagedPath;
73
+ }
74
+ throw new Error(`Portable updater is missing for ${process.platform} ${process.arch}`);
75
+ }
76
+
62
77
  function requireNative() {
63
78
  if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
64
79
  try {
@@ -100,6 +115,8 @@ export const fileToDataUrl = nativeBinding.fileToDataUrl;
100
115
  export const fileToStr = nativeBinding.fileToStr;
101
116
  export const getAppName = nativeBinding.getAppName;
102
117
  export const getNativeCapabilities = nativeBinding.getNativeCapabilities;
118
+ export const getWindowsServiceStatus = nativeBinding.getWindowsServiceStatus;
119
+ export const getLinuxServiceStatus = nativeBinding.getLinuxServiceStatus;
103
120
  export const setTerminalProxyEnvironment = nativeBinding.setTerminalProxyEnvironment;
104
121
  export const clearTerminalProxyEnvironment = nativeBinding.clearTerminalProxyEnvironment;
105
122
  export const findExecutables = nativeBinding.findExecutables;
@@ -108,6 +125,7 @@ export const setLaunchAtLogin = nativeBinding.setLaunchAtLogin;
108
125
  export const getNetworkContext = nativeBinding.getNetworkContext;
109
126
  export const waitForNetworkContextChange = nativeBinding.waitForNetworkContextChange;
110
127
  export const getMacosManagedServiceStatus = nativeBinding.getMacosManagedServiceStatus;
128
+ export const getMacosServiceProcessStatus = nativeBinding.getMacosServiceProcessStatus;
111
129
  export const registerMacosManagedService = nativeBinding.registerMacosManagedService;
112
130
  export const unregisterMacosManagedService = nativeBinding.unregisterMacosManagedService;
113
131
  export const reloadMacosManagedService = nativeBinding.reloadMacosManagedService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kokorobox-native",
3
- "version": "0.15.0",
3
+ "version": "0.16.1",
4
4
  "description": "KokoroBox native bridge",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -48,11 +48,11 @@
48
48
  "access": "public"
49
49
  },
50
50
  "optionalDependencies": {
51
- "kokorobox-native-win32-x64-msvc": "0.15.0",
52
- "kokorobox-native-win32-arm64-msvc": "0.15.0",
53
- "kokorobox-native-darwin-x64": "0.15.0",
54
- "kokorobox-native-darwin-arm64": "0.15.0",
55
- "kokorobox-native-linux-x64-gnu": "0.15.0",
56
- "kokorobox-native-linux-arm64-gnu": "0.15.0"
51
+ "kokorobox-native-win32-x64-msvc": "0.16.1",
52
+ "kokorobox-native-win32-arm64-msvc": "0.16.1",
53
+ "kokorobox-native-darwin-x64": "0.16.1",
54
+ "kokorobox-native-darwin-arm64": "0.16.1",
55
+ "kokorobox-native-linux-x64-gnu": "0.16.1",
56
+ "kokorobox-native-linux-arm64-gnu": "0.16.1"
57
57
  }
58
58
  }