@qpjoy/electron-tunnel 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 +53 -0
- package/dist/admin/AdminServer.d.ts +10 -0
- package/dist/admin/AdminServer.js +362 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +92 -0
- package/dist/config/renderRuntimeConfig.d.ts +3 -0
- package/dist/config/renderRuntimeConfig.js +151 -0
- package/dist/createElectronTunnel.d.ts +21 -0
- package/dist/createElectronTunnel.js +49 -0
- package/dist/db/TunnelDatabase.d.ts +23 -0
- package/dist/db/TunnelDatabase.js +296 -0
- package/dist/db/schema.d.ts +1 -0
- package/dist/db/schema.js +70 -0
- package/dist/defaults.d.ts +18 -0
- package/dist/defaults.js +68 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +25 -0
- package/dist/ipc/registerTunnelIpc.d.ts +7 -0
- package/dist/ipc/registerTunnelIpc.js +70 -0
- package/dist/mihomo/MihomoApi.d.ts +11 -0
- package/dist/mihomo/MihomoApi.js +56 -0
- package/dist/mihomo/MihomoManager.d.ts +75 -0
- package/dist/mihomo/MihomoManager.js +635 -0
- package/dist/security.d.ts +3 -0
- package/dist/security.js +24 -0
- package/dist/system/electronProxy.d.ts +4 -0
- package/dist/system/electronProxy.js +30 -0
- package/dist/types.d.ts +98 -0
- package/dist/types.js +2 -0
- package/package.json +52 -0
- package/resources/engine/darwin-arm64/mihomo.gz +0 -0
- package/resources/engine/darwin-x64/mihomo.gz +0 -0
- package/resources/engine/linux-arm64/mihomo.gz +0 -0
- package/resources/engine/linux-x64/mihomo.gz +0 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { MihomoApiResponse, RuntimeSettings } from '../types';
|
|
2
|
+
export declare class MihomoApi {
|
|
3
|
+
private readonly getSettings;
|
|
4
|
+
constructor(getSettings: () => RuntimeSettings);
|
|
5
|
+
request<T = unknown>(path: string, init?: RequestInit): Promise<MihomoApiResponse<T>>;
|
|
6
|
+
version(): Promise<MihomoApiResponse>;
|
|
7
|
+
proxies(): Promise<MihomoApiResponse>;
|
|
8
|
+
connections(): Promise<MihomoApiResponse>;
|
|
9
|
+
reloadConfig(configPath: string): Promise<MihomoApiResponse>;
|
|
10
|
+
selectProxy(groupName: string, proxyName: string): Promise<MihomoApiResponse>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MihomoApi = void 0;
|
|
4
|
+
class MihomoApi {
|
|
5
|
+
getSettings;
|
|
6
|
+
constructor(getSettings) {
|
|
7
|
+
this.getSettings = getSettings;
|
|
8
|
+
}
|
|
9
|
+
async request(path, init = {}) {
|
|
10
|
+
const settings = this.getSettings();
|
|
11
|
+
const url = `http://127.0.0.1:${settings.ports.controller}${path}`;
|
|
12
|
+
const headers = new Headers(init.headers);
|
|
13
|
+
headers.set('Authorization', `Bearer ${settings.controllerSecret}`);
|
|
14
|
+
const response = await fetch(url, {
|
|
15
|
+
...init,
|
|
16
|
+
headers
|
|
17
|
+
});
|
|
18
|
+
const contentType = response.headers.get('content-type') ?? '';
|
|
19
|
+
const data = contentType.includes('application/json')
|
|
20
|
+
? await response.json()
|
|
21
|
+
: await response.text();
|
|
22
|
+
return {
|
|
23
|
+
ok: response.ok,
|
|
24
|
+
status: response.status,
|
|
25
|
+
data
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
version() {
|
|
29
|
+
return this.request('/version');
|
|
30
|
+
}
|
|
31
|
+
proxies() {
|
|
32
|
+
return this.request('/proxies');
|
|
33
|
+
}
|
|
34
|
+
connections() {
|
|
35
|
+
return this.request('/connections');
|
|
36
|
+
}
|
|
37
|
+
reloadConfig(configPath) {
|
|
38
|
+
return this.request('/configs?force=true', {
|
|
39
|
+
method: 'PUT',
|
|
40
|
+
body: JSON.stringify({ path: configPath }),
|
|
41
|
+
headers: {
|
|
42
|
+
'content-type': 'application/json'
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
async selectProxy(groupName, proxyName) {
|
|
47
|
+
return this.request(`/proxies/${encodeURIComponent(groupName)}`, {
|
|
48
|
+
method: 'PUT',
|
|
49
|
+
body: JSON.stringify({ name: proxyName }),
|
|
50
|
+
headers: {
|
|
51
|
+
'content-type': 'application/json'
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.MihomoApi = MihomoApi;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import { TunnelDatabase } from '../db/TunnelDatabase';
|
|
3
|
+
import { type DomainPresetId } from '../defaults';
|
|
4
|
+
import { MihomoApi } from './MihomoApi';
|
|
5
|
+
import type { DomainRule, RuntimeMode, SubscriptionInput, SubscriptionRecord, TunnelManagerOptions, TunnelSnapshot, TunnelPorts, TunnelStatus } from '../types';
|
|
6
|
+
interface ManagerPaths {
|
|
7
|
+
root: string;
|
|
8
|
+
db: string;
|
|
9
|
+
profiles: string;
|
|
10
|
+
runtime: string;
|
|
11
|
+
config: string;
|
|
12
|
+
core: string;
|
|
13
|
+
}
|
|
14
|
+
export declare class MihomoManager extends EventEmitter {
|
|
15
|
+
private readonly options;
|
|
16
|
+
readonly db: TunnelDatabase;
|
|
17
|
+
readonly api: MihomoApi;
|
|
18
|
+
readonly paths: ManagerPaths;
|
|
19
|
+
private child;
|
|
20
|
+
private elevatedPid;
|
|
21
|
+
private operation;
|
|
22
|
+
constructor(options: TunnelManagerOptions);
|
|
23
|
+
status(): TunnelStatus;
|
|
24
|
+
snapshot(): Promise<TunnelSnapshot>;
|
|
25
|
+
trafficSummary(): Promise<{
|
|
26
|
+
available: boolean;
|
|
27
|
+
connections: number;
|
|
28
|
+
uploadTotal: number;
|
|
29
|
+
downloadTotal: number;
|
|
30
|
+
}>;
|
|
31
|
+
listSubscriptions(): SubscriptionRecord[];
|
|
32
|
+
listRules(): DomainRule[];
|
|
33
|
+
listEvents(): import("../types").EventRecord[];
|
|
34
|
+
createSubscription(input: SubscriptionInput): Promise<SubscriptionRecord>;
|
|
35
|
+
private localSubscriptionPath;
|
|
36
|
+
private fetchSubscriptionContent;
|
|
37
|
+
deleteSubscription(id: number): void;
|
|
38
|
+
setActiveSubscription(id: number): SubscriptionRecord;
|
|
39
|
+
setMode(mode: RuntimeMode): boolean;
|
|
40
|
+
setLocalPorts(ports: Partial<Pick<TunnelPorts, 'mixed' | 'dns'>>): Promise<void>;
|
|
41
|
+
installTunFeature(): void;
|
|
42
|
+
uninstallTunFeature(): void;
|
|
43
|
+
installCoreFromPath(sourcePath: string): string;
|
|
44
|
+
setCorePath(corePath: string): void;
|
|
45
|
+
updateSubscription(id: number): Promise<SubscriptionRecord>;
|
|
46
|
+
updateActiveSubscription(): Promise<SubscriptionRecord>;
|
|
47
|
+
addDomainRule(kind: 'allow' | 'block', domain: string, source?: string): DomainRule;
|
|
48
|
+
addPreset(preset: DomainPresetId): DomainRule[];
|
|
49
|
+
removeDomainRule(id: number): void;
|
|
50
|
+
renderConfig(): string;
|
|
51
|
+
private runExclusive;
|
|
52
|
+
start(): Promise<void>;
|
|
53
|
+
private startUnlocked;
|
|
54
|
+
private resolveCorePath;
|
|
55
|
+
private findBundledCore;
|
|
56
|
+
private installBundledCore;
|
|
57
|
+
private runElevatedShell;
|
|
58
|
+
private startElevated;
|
|
59
|
+
private readElevatedLogTail;
|
|
60
|
+
private elevatedPidPath;
|
|
61
|
+
private readElevatedPid;
|
|
62
|
+
private rememberElevatedPid;
|
|
63
|
+
private clearElevatedPid;
|
|
64
|
+
private isRunning;
|
|
65
|
+
private isElevatedRunning;
|
|
66
|
+
private reloadRuntimeConfig;
|
|
67
|
+
stop(): Promise<void>;
|
|
68
|
+
private stopUnlocked;
|
|
69
|
+
restart(): Promise<void>;
|
|
70
|
+
applyRuntimeConfigChange(): Promise<void>;
|
|
71
|
+
handleNetworkChanged(reason: string): Promise<void>;
|
|
72
|
+
close(): void;
|
|
73
|
+
private log;
|
|
74
|
+
}
|
|
75
|
+
export {};
|