@dlient/api-types 1.0.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 +39 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/app.d.ts +158 -0
- package/dist/modules/child.d.ts +89 -0
- package/dist/modules/clipboard.d.ts +95 -0
- package/dist/modules/dialog.d.ts +114 -0
- package/dist/modules/fs.d.ts +140 -0
- package/dist/modules/i18n.d.ts +12 -0
- package/dist/modules/log.d.ts +14 -0
- package/dist/modules/net.d.ts +58 -0
- package/dist/modules/notification.d.ts +84 -0
- package/dist/modules/os.d.ts +12 -0
- package/dist/modules/permission.d.ts +72 -0
- package/dist/modules/plugin.d.ts +184 -0
- package/dist/modules/powerSave.d.ts +16 -0
- package/dist/modules/screen.d.ts +84 -0
- package/dist/modules/system.d.ts +14 -0
- package/dist/modules/webview.d.ts +68 -0
- package/package.json +24 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fs host-api — typed single source.
|
|
3
|
+
* Real source of truth: app/src/main/api/fs.ts (handler reads these fields).
|
|
4
|
+
* All docs are English; keep in sync with the main-process api table.
|
|
5
|
+
* Path whitelist enforcement (fs-grants) is applied uniformly by executeHostApi,
|
|
6
|
+
* not by these option fields.
|
|
7
|
+
*/
|
|
8
|
+
/** Options accepted by fs.read (2nd argument; default = read text content). */
|
|
9
|
+
export interface FsReadOptions {
|
|
10
|
+
/** Read the file as raw bytes and return base64-encoded content. Defaults to false (UTF-8 text). */
|
|
11
|
+
base64?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/** Binary payload accepted by fs.write / fs.withLock when writing bytes (base64-encoded data). */
|
|
14
|
+
export interface FsWriteData {
|
|
15
|
+
/** File content as a base64 string (decoded before being written). */
|
|
16
|
+
base64: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Result of fs.stat: the serializable data fields of the Node fs.Stats object.
|
|
20
|
+
* IPC strips prototype methods (isFile/isDirectory) and only data fields survive;
|
|
21
|
+
* time fields are ms-epoch numbers (prefer mtimeMs over Date variants).
|
|
22
|
+
*/
|
|
23
|
+
export interface FsStatResult {
|
|
24
|
+
dev: number;
|
|
25
|
+
ino: number;
|
|
26
|
+
mode: number;
|
|
27
|
+
nlink: number;
|
|
28
|
+
uid: number;
|
|
29
|
+
gid: number;
|
|
30
|
+
rdev: number;
|
|
31
|
+
/** File size in bytes. */
|
|
32
|
+
size: number;
|
|
33
|
+
blksize: number;
|
|
34
|
+
blocks: number;
|
|
35
|
+
/** Access time, ms-epoch. */
|
|
36
|
+
atimeMs: number;
|
|
37
|
+
/** Modification time, ms-epoch. */
|
|
38
|
+
mtimeMs: number;
|
|
39
|
+
/** Status change time, ms-epoch. */
|
|
40
|
+
ctimeMs: number;
|
|
41
|
+
/** Creation time, ms-epoch. */
|
|
42
|
+
birthtimeMs: number;
|
|
43
|
+
}
|
|
44
|
+
/** Single entry returned by fs.listDir (best-effort size/mtime when stat fails are 0). */
|
|
45
|
+
export interface FsListDirEntry {
|
|
46
|
+
/** Entry file/dir name (basename within the listed directory). */
|
|
47
|
+
name: string;
|
|
48
|
+
/** Whether the entry is a directory. */
|
|
49
|
+
isDirectory: boolean;
|
|
50
|
+
/** Whether the entry is a regular file. */
|
|
51
|
+
isFile: boolean;
|
|
52
|
+
/** File size in bytes (0 for directories or when stat failed). */
|
|
53
|
+
size: number;
|
|
54
|
+
/** Modification time in ms-epoch (0 when stat failed). */
|
|
55
|
+
mtimeMs: number;
|
|
56
|
+
}
|
|
57
|
+
/** fs.listDir return type: an array of directory entries. */
|
|
58
|
+
export type FsListDirResult = FsListDirEntry[];
|
|
59
|
+
/** Result of fs.lock: the lock id that must be passed back to fs.unlock / fs.withLock. */
|
|
60
|
+
export interface FsLockResult {
|
|
61
|
+
/** Opaque lock id; pass it to fs.unlock to release this lock. */
|
|
62
|
+
lockId: string;
|
|
63
|
+
}
|
|
64
|
+
/** Options accepted by fs.lock / fs.withLock (3rd argument; per-path cross-process file lock). */
|
|
65
|
+
export interface FsLockOptions {
|
|
66
|
+
/** Lock auto-expiry in ms (guards against a dead holder). Defaults to 30000. */
|
|
67
|
+
ttlMs?: number;
|
|
68
|
+
/** Whether to queue when the path is already locked; false throws busy immediately. Defaults to true. */
|
|
69
|
+
wait?: boolean;
|
|
70
|
+
/** Max queue wait in ms before a TIMEOUT error. Defaults to 15000. */
|
|
71
|
+
timeoutMs?: number;
|
|
72
|
+
}
|
|
73
|
+
/** Single file operation executed by fs.withLock while holding the path lock. */
|
|
74
|
+
export type FsWithLockOperation =
|
|
75
|
+
/** Read the file (UTF-8 text). */
|
|
76
|
+
{
|
|
77
|
+
method: 'read';
|
|
78
|
+
}
|
|
79
|
+
/** Read the file metadata (same shape as fs.stat). */
|
|
80
|
+
| {
|
|
81
|
+
method: 'stat';
|
|
82
|
+
}
|
|
83
|
+
/** Write the file (string content or base64 payload). */
|
|
84
|
+
| {
|
|
85
|
+
method: 'write';
|
|
86
|
+
data: string | FsWriteData;
|
|
87
|
+
}
|
|
88
|
+
/** Append text to the file (creates parent directories first). */
|
|
89
|
+
| {
|
|
90
|
+
method: 'append';
|
|
91
|
+
data: string;
|
|
92
|
+
}
|
|
93
|
+
/** Delete the file/dir. */
|
|
94
|
+
| {
|
|
95
|
+
method: 'delete';
|
|
96
|
+
}
|
|
97
|
+
/** Rotate log files (SDK logger pre-write check; host-side log rotation). */
|
|
98
|
+
| {
|
|
99
|
+
method: 'rotate';
|
|
100
|
+
};
|
|
101
|
+
/** fs.withLock return type: 'read'/'stat' return data, other operations resolve with undefined. */
|
|
102
|
+
export type FsWithLockResult = string | FsStatResult | undefined;
|
|
103
|
+
/** Flat signature map for the fs module. */
|
|
104
|
+
export type FsModuleApi = {
|
|
105
|
+
/**
|
|
106
|
+
* Reads a file: UTF-8 text by default, or base64-encoded bytes when options.base64 is true.
|
|
107
|
+
* Requires an fs-grants read whitelist entry for the path.
|
|
108
|
+
*/
|
|
109
|
+
'fs.read'(path: string, options?: FsReadOptions): Promise<string>;
|
|
110
|
+
/** Returns file/dir metadata as a flat data object (throws when the path does not exist). */
|
|
111
|
+
'fs.stat'(path: string): Promise<FsStatResult>;
|
|
112
|
+
/** Lists directory entries with a best-effort size/mtime per entry. */
|
|
113
|
+
'fs.listDir'(path: string): Promise<FsListDirResult>;
|
|
114
|
+
/**
|
|
115
|
+
* Watches a directory for changes and returns a watch id. Changes are delivered to the
|
|
116
|
+
* calling plugin worker as `<pluginId>.fs-watch-event` with args [watchId, filename].
|
|
117
|
+
*/
|
|
118
|
+
'fs.watch'(path: string): Promise<string>;
|
|
119
|
+
/** Stops a directory watch started by fs.watch (idempotent; unknown ids are ignored). */
|
|
120
|
+
'fs.unwatch'(watchId: string): Promise<void>;
|
|
121
|
+
/** Creates a directory (recursive; no error when it already exists). */
|
|
122
|
+
'fs.mkdir'(path: string): Promise<void>;
|
|
123
|
+
/** Writes a file atomically (string content or base64 payload; parent dirs are created). */
|
|
124
|
+
'fs.write'(path: string, data: string | FsWriteData): Promise<void>;
|
|
125
|
+
/** Appends text to a file, creating parent directories first (log writes use this). */
|
|
126
|
+
'fs.append'(path: string, data: string): Promise<void>;
|
|
127
|
+
/** Deletes a file or directory (recursive, force). Requires a write whitelist entry. */
|
|
128
|
+
'fs.delete'(path: string): Promise<void>;
|
|
129
|
+
/**
|
|
130
|
+
* Copies a directory tree. dest must be inside the host userData directory;
|
|
131
|
+
* exclude filters out top-level entry names (e.g. node_modules, .git).
|
|
132
|
+
*/
|
|
133
|
+
'fs.copyDir'(src: string, dest: string, exclude?: string[]): Promise<void>;
|
|
134
|
+
/** Acquires a per-path cross-process file lock (worker-only scope); returns { lockId }. */
|
|
135
|
+
'fs.lock'(path: string, options?: FsLockOptions): Promise<FsLockResult>;
|
|
136
|
+
/** Releases a file lock previously acquired with fs.lock (idempotent on unknown lockId). */
|
|
137
|
+
'fs.unlock'(path: string, lockId: string): Promise<void>;
|
|
138
|
+
/** Runs a single file operation while holding the path lock (worker-only scope). */
|
|
139
|
+
'fs.withLock'(path: string, operation: FsWithLockOperation, options?: FsLockOptions): Promise<FsWithLockResult>;
|
|
140
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* i18n host-api — typed single source.
|
|
3
|
+
* Real source of truth: app/src/main/api/i18n.ts (handler reads these fields).
|
|
4
|
+
* All docs are English; keep in sync with the main-process api table.
|
|
5
|
+
*/
|
|
6
|
+
/** Host UI language codes (worker query result of i18n.getLocale). */
|
|
7
|
+
export type I18nLocale = 'zh-CN' | 'en-US';
|
|
8
|
+
/** Flat signature map for the i18n module. */
|
|
9
|
+
export type I18nModuleApi = {
|
|
10
|
+
/** Host current UI language ('zh-CN' / 'en-US'). */
|
|
11
|
+
'i18n.getLocale'(): Promise<I18nLocale>;
|
|
12
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* log host-api — typed single source.
|
|
3
|
+
* Real source of truth: app/src/main/api/log.ts (handler reads these fields).
|
|
4
|
+
* 声明 manifest.permissions 的 log(前缀组,覆盖 log.*)即可写入自身插件日志,无需 fs 权限。
|
|
5
|
+
*/
|
|
6
|
+
export interface LogModuleApi {
|
|
7
|
+
/**
|
|
8
|
+
* 写入插件日志(source 由宿主按调用方身份推导:worker→'worker' / ui→'renderer')。
|
|
9
|
+
* 落 plugin-data/<pluginId>/logs/main.log(含轮转与订阅推送);未声明 log 权限则拒绝。
|
|
10
|
+
*/
|
|
11
|
+
'log.write'(level?: 'debug' | 'info' | 'warn' | 'error', message?: string, data?: unknown): Promise<{
|
|
12
|
+
ok: boolean;
|
|
13
|
+
}>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* net host-api — typed single source.
|
|
3
|
+
* Real source of truth: app/src/main/api/net.ts (handler reads these fields).
|
|
4
|
+
* All docs are English; keep in sync with the main-process api table.
|
|
5
|
+
* net.fetch / net.request go through net-grants authorization (host policy blocks
|
|
6
|
+
* internal/loopback traffic and hard-denies cloud metadata endpoints).
|
|
7
|
+
*/
|
|
8
|
+
/** Request init accepted by net.fetch (serializable subset of Electron net.fetch init). */
|
|
9
|
+
export interface NetFetchInit {
|
|
10
|
+
/** HTTP method (e.g. 'GET' / 'POST'). Defaults to 'GET'. */
|
|
11
|
+
method?: string;
|
|
12
|
+
/** Request headers as a flat name → value map. */
|
|
13
|
+
headers?: Record<string, string>;
|
|
14
|
+
/** Request body (only string bodies are forwarded). */
|
|
15
|
+
body?: string;
|
|
16
|
+
}
|
|
17
|
+
/** Options accepted by net.request (net.fetch with the url moved into the options object). */
|
|
18
|
+
export interface NetRequestOptions {
|
|
19
|
+
/** Target URL. Required. */
|
|
20
|
+
url: string;
|
|
21
|
+
/** HTTP method (e.g. 'GET' / 'POST'). Defaults to 'GET'. */
|
|
22
|
+
method?: string;
|
|
23
|
+
/** Request headers as a flat name → value map. */
|
|
24
|
+
headers?: Record<string, string>;
|
|
25
|
+
/** Request body (only string bodies are forwarded). */
|
|
26
|
+
body?: string;
|
|
27
|
+
}
|
|
28
|
+
/** Result of a successful net.fetch / net.request call. */
|
|
29
|
+
export interface NetFetchResult {
|
|
30
|
+
/** Whether the response status was 2xx (mirrors fetch Response.ok). */
|
|
31
|
+
ok: boolean;
|
|
32
|
+
/** HTTP status code. */
|
|
33
|
+
status: number;
|
|
34
|
+
/** HTTP status text. */
|
|
35
|
+
statusText: string;
|
|
36
|
+
/** Response headers as a flat name → value map (last value wins per header). */
|
|
37
|
+
headers: Record<string, string>;
|
|
38
|
+
/** Response body bytes encoded as base64 (empty string when the body is empty). */
|
|
39
|
+
body: string;
|
|
40
|
+
}
|
|
41
|
+
/** Flat signature map for the net module. */
|
|
42
|
+
export type NetModuleApi = {
|
|
43
|
+
/** Whether the machine has an internet connection (read-only). */
|
|
44
|
+
'net.isOnline'(): Promise<boolean>;
|
|
45
|
+
/**
|
|
46
|
+
* Performs an HTTP request (net-grants authorization; see module header). Returns the
|
|
47
|
+
* full response with the body base64-encoded. User denial throws USER_DENIED.
|
|
48
|
+
* The `description` argument (optional) is the authorization request copy shown in the
|
|
49
|
+
* net-access permission dialog when this URL is not yet authorized (tell the user why).
|
|
50
|
+
*/
|
|
51
|
+
'net.fetch'(url: string, init?: NetFetchInit, description?: string): Promise<NetFetchResult>;
|
|
52
|
+
/** Performs an HTTP request from an options object (same authorization as net.fetch; its `description` argument is likewise shown in the net-access permission dialog as the authorization reason). */
|
|
53
|
+
'net.request'(options: NetRequestOptions, description?: string): Promise<NetFetchResult>;
|
|
54
|
+
/** Allocates a free TCP port on 127.0.0.1 (replaces worker-side node:net binding). */
|
|
55
|
+
'net.getFreePort'(): Promise<number>;
|
|
56
|
+
/** Probes whether a local TCP port is reachable on 127.0.0.1 (800ms timeout). */
|
|
57
|
+
'net.probePort'(port: number): Promise<boolean>;
|
|
58
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* notification host-api — typed single source.
|
|
3
|
+
* Real source of truth: app/src/main/api/notification.ts (handler reads these fields).
|
|
4
|
+
* All docs are English; keep in sync with the main-process api table.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Options accepted by notification.send.
|
|
8
|
+
* Identity fields (group_id/group_title/subtitle/icon) are NOT part of the public surface:
|
|
9
|
+
* the host derives them from the sending plugin and injects them when the notification is sent,
|
|
10
|
+
* so a plugin cannot impersonate another plugin or override its branding. Only content fields
|
|
11
|
+
* below may be provided by the caller.
|
|
12
|
+
*/
|
|
13
|
+
export interface NotificationSendOptions {
|
|
14
|
+
/** Notification title. Required. */
|
|
15
|
+
title: string;
|
|
16
|
+
/** Optional body text. */
|
|
17
|
+
body?: string;
|
|
18
|
+
/** Whether the notification is silent (no sound). Defaults to false. */
|
|
19
|
+
silent?: boolean;
|
|
20
|
+
/** Whether to show an inline reply box. Defaults to false. */
|
|
21
|
+
hasReply?: boolean;
|
|
22
|
+
/** Placeholder text for the reply box (only meaningful when hasReply is true). */
|
|
23
|
+
replyPlaceholder?: string;
|
|
24
|
+
/** Action buttons. 'reply' actions are carried by hasReply and mapped to buttons by the host. */
|
|
25
|
+
actions?: {
|
|
26
|
+
type: 'button' | 'reply';
|
|
27
|
+
text: string;
|
|
28
|
+
}[];
|
|
29
|
+
/** Custom close-button text (macOS system notification / in-app strip). */
|
|
30
|
+
closeButtonText?: string;
|
|
31
|
+
/** 'default' auto-dismisses; 'never' keeps the notification until dismissed (Windows system engine / in-app). */
|
|
32
|
+
timeoutType?: 'default' | 'never';
|
|
33
|
+
}
|
|
34
|
+
/** Result of a successful notification.send call: the handle id used for events/removal. */
|
|
35
|
+
export interface NotificationSendResult {
|
|
36
|
+
id: string;
|
|
37
|
+
}
|
|
38
|
+
/** Notification lifecycle event names delivered to the send handle via host push. */
|
|
39
|
+
export type NotificationEventName = 'click' | 'close' | 'reply' | 'action' | 'failed' | 'show';
|
|
40
|
+
/** Payload attached to notification events (action carries index, reply carries text, failed carries error). */
|
|
41
|
+
export interface NotificationEventPayload {
|
|
42
|
+
index?: number;
|
|
43
|
+
reply?: string;
|
|
44
|
+
error?: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Handle returned by notification.send on the SDK/UI surface (identical shape for worker
|
|
48
|
+
* `rpc.notification.send` and UI `api.notification.send`). The SDK performs the subscribe
|
|
49
|
+
* handshake; lifecycle events stream back to the local `on(...)` callbacks. close() closes
|
|
50
|
+
* this notification (owner-checked).
|
|
51
|
+
*/
|
|
52
|
+
export interface NotificationHandle {
|
|
53
|
+
readonly id: string;
|
|
54
|
+
/** Subscribes to notification lifecycle events ('click' | 'close' | 'reply' | 'action' | 'failed' | 'show'). */
|
|
55
|
+
on(event: NotificationEventName, cb: (payload?: NotificationEventPayload) => void): NotificationHandle;
|
|
56
|
+
/** Closes this notification (equivalent to notification.remove(id)). */
|
|
57
|
+
close(): Promise<void>;
|
|
58
|
+
}
|
|
59
|
+
/** Flat signature map for the notification module. */
|
|
60
|
+
export type NotificationModuleApi = {
|
|
61
|
+
/** Whether system notifications are supported on this platform. */
|
|
62
|
+
'notification.isSupported'(): Promise<boolean>;
|
|
63
|
+
/**
|
|
64
|
+
* Sends a notification and returns its handle id.
|
|
65
|
+
* Worker/UI SDKs wrap this into a handle supporting on('click'|'close'|'reply'|'action'|'failed'|'show').
|
|
66
|
+
* macOS foreground is routed to the in-app notification strip automatically.
|
|
67
|
+
*/
|
|
68
|
+
'notification.send'(options: NotificationSendOptions): Promise<NotificationSendResult>;
|
|
69
|
+
/**
|
|
70
|
+
* Closes a notification by id. Owner-checked: only notifications sent by this plugin can be closed;
|
|
71
|
+
* other plugins' ids return PERMISSION_DENIED. Works for both system and in-app engines.
|
|
72
|
+
*/
|
|
73
|
+
'notification.remove'(id: string): Promise<void>;
|
|
74
|
+
/** Closes all notifications sent by this plugin (both system and in-app engines). No argument needed. */
|
|
75
|
+
'notification.removeGroup'(): Promise<void>;
|
|
76
|
+
/** Subscribes to events of a notification id (owner-checked). Usually called automatically by the SDK handle. */
|
|
77
|
+
'notification.subscribe'(options: {
|
|
78
|
+
id: string;
|
|
79
|
+
}): Promise<void>;
|
|
80
|
+
/** Unsubscribes from events of a notification id (owner-checked). Usually called automatically by the SDK handle. */
|
|
81
|
+
'notification.unsubscribe'(options: {
|
|
82
|
+
id: string;
|
|
83
|
+
}): Promise<void>;
|
|
84
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* os host-api — typed single source.
|
|
3
|
+
* Real source of truth: app/src/main/api/os.ts (handler reads these fields).
|
|
4
|
+
* All docs are English; keep in sync with the main-process api table.
|
|
5
|
+
*/
|
|
6
|
+
/** Flat signature map for the os module. */
|
|
7
|
+
export type OsModuleApi = {
|
|
8
|
+
/** Opens an external URL with the system default app (http/https/mailto/...). System scope; dangerous. */
|
|
9
|
+
'os.openExternal'(url: string): Promise<void>;
|
|
10
|
+
/** Reveals a file or directory in the system file manager. System scope. */
|
|
11
|
+
'os.showItemInFolder'(path: string): Promise<void>;
|
|
12
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* permission host-api — typed single source.
|
|
3
|
+
* Real source of truth: app/src/main/api/permission.ts (handler reads these fields).
|
|
4
|
+
* All docs are English; keep in sync with the main-process api table.
|
|
5
|
+
*/
|
|
6
|
+
/** Resource kind a permission targets. */
|
|
7
|
+
export type PermissionResourceType = 'fs' | 'net' | 'spawn';
|
|
8
|
+
/** fs access mode requested in a permission.request fs item. */
|
|
9
|
+
export type PermissionFsMode = 'read' | 'write';
|
|
10
|
+
/** Lifetime of a granted permission. */
|
|
11
|
+
export type PermissionGrantScope = 'persistent' | 'session';
|
|
12
|
+
/** A single granted-resource record, as returned inside permission.list / permission.plugin.list. */
|
|
13
|
+
export interface PermissionGrant {
|
|
14
|
+
/** Resource kind of the grant (fs = path, net = URL prefix, spawn = command). */
|
|
15
|
+
type: PermissionResourceType;
|
|
16
|
+
/** fs: absolute path; net: URL prefix; spawn: command. */
|
|
17
|
+
target: string;
|
|
18
|
+
/** Owner plugin instance key (e.g. 'dev-tools' or 'nodejs@dev'). */
|
|
19
|
+
pluginId: string;
|
|
20
|
+
/** fs-only access mode ('read' | 'write'); absent for net/spawn grants. */
|
|
21
|
+
mode?: PermissionFsMode;
|
|
22
|
+
/** Whether the grant is persisted across host restarts (persistent) or session-only. */
|
|
23
|
+
scope: PermissionGrantScope;
|
|
24
|
+
/** Epoch milliseconds when the grant was recorded. */
|
|
25
|
+
grantedAt: number;
|
|
26
|
+
}
|
|
27
|
+
/** A plugin's resource grants grouped by kind (market "Permissions" page / own-grants view). */
|
|
28
|
+
export interface PermissionGrantList {
|
|
29
|
+
fs: PermissionGrant[];
|
|
30
|
+
net: PermissionGrant[];
|
|
31
|
+
spawn: PermissionGrant[];
|
|
32
|
+
}
|
|
33
|
+
/** One item of a permission.request batch: fs items carry path (+ optional mode), net items carry url, spawn items carry cmd. */
|
|
34
|
+
export interface PermissionRequestItem {
|
|
35
|
+
/** Resource kind: 'fs' (also used when omitted and path is set) | 'net' | 'spawn'. net requires url; spawn requires cmd. */
|
|
36
|
+
type?: PermissionResourceType;
|
|
37
|
+
/** fs: absolute path or alias to request (see the fs module dir-alias list). */
|
|
38
|
+
path?: string;
|
|
39
|
+
/** net: URL to request (only honored when type is 'net'). */
|
|
40
|
+
url?: string;
|
|
41
|
+
/** spawn: command to request (only honored when type is 'spawn'). */
|
|
42
|
+
cmd?: string;
|
|
43
|
+
/** fs-only access mode(s): 'read' | 'write' | both; defaults to read + write when omitted. */
|
|
44
|
+
mode?: PermissionFsMode | PermissionFsMode[];
|
|
45
|
+
}
|
|
46
|
+
/** Options accepted by permission.revoke (admin entry to revoke another plugin's resource grant). */
|
|
47
|
+
export interface PermissionRevokeOptions {
|
|
48
|
+
/** Target plugin instance key. */
|
|
49
|
+
pluginId?: string;
|
|
50
|
+
/** fs: path; net: URL prefix; spawn: command. */
|
|
51
|
+
target?: string;
|
|
52
|
+
}
|
|
53
|
+
/** Result of a successful permission.revoke call. */
|
|
54
|
+
export interface PermissionRevokeResult {
|
|
55
|
+
ok: boolean;
|
|
56
|
+
}
|
|
57
|
+
/** Result of permission.request: granted/denied are requested targets (denied = rejected by the user in the confirm dialog). */
|
|
58
|
+
export interface PermissionRequestResult {
|
|
59
|
+
granted: string[];
|
|
60
|
+
denied: string[];
|
|
61
|
+
}
|
|
62
|
+
/** Flat signature map for the permission module. */
|
|
63
|
+
export type PermissionModuleApi = {
|
|
64
|
+
/** Lists the resource grants of an arbitrary plugin (admin; market "Permissions" page). */
|
|
65
|
+
'permission.plugin.list'(pluginId: string): Promise<PermissionGrantList>;
|
|
66
|
+
/** Revokes one resource grant of a plugin by type + target (type ∈ fs | net | spawn; merged fs.revokeAccess / net.revokeUrl / auth.revokeGrant). */
|
|
67
|
+
'permission.revoke'(type: PermissionResourceType, options: PermissionRevokeOptions): Promise<PermissionRevokeResult>;
|
|
68
|
+
/** Batch pre-authorization: lists fs/net/spawn resources once so the user can grant them in a single dialog (avoids per-call prompts at runtime). */
|
|
69
|
+
'permission.request'(resources: PermissionRequestItem[], description?: string): Promise<PermissionRequestResult>;
|
|
70
|
+
/** Lists the current plugin's own resource grants (no argument needed; identity comes from the caller). */
|
|
71
|
+
'permission.list'(): Promise<PermissionGrantList>;
|
|
72
|
+
};
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* plugin host-api — typed single source.
|
|
3
|
+
* Real source of truth: app/src/main/api/plugin.ts (handler reads these fields).
|
|
4
|
+
* All docs are English; keep in sync with the main-process api table.
|
|
5
|
+
*/
|
|
6
|
+
/** Install source of a plugin. */
|
|
7
|
+
export type PluginSource = 'market' | 'local' | 'dev';
|
|
8
|
+
/** Plugin kind (what the plugin runs / ships). */
|
|
9
|
+
export type PluginType = 'full' | 'worker' | 'ui' | 'app';
|
|
10
|
+
/** Call-channel gate of a host api (plugin.capabilities entries). */
|
|
11
|
+
export type PluginCapabilityScope = 'all' | 'worker' | 'ui' | 'system';
|
|
12
|
+
/** Install-risk label of a host api (plugin.capabilities entries). */
|
|
13
|
+
export type PluginCapabilityLevel = 'default' | 'warn' | 'dangerous';
|
|
14
|
+
/** One capability entry returned by plugin.capabilities (full api-table metadata). */
|
|
15
|
+
export interface PluginCapability {
|
|
16
|
+
/** Full dotted api key (also the manifest.permissions declaration value). */
|
|
17
|
+
key: string;
|
|
18
|
+
/** Localized human-readable description. */
|
|
19
|
+
description: {
|
|
20
|
+
'zh-CN': string;
|
|
21
|
+
'en-US': string;
|
|
22
|
+
};
|
|
23
|
+
/** Who may invoke the api. */
|
|
24
|
+
scope: PluginCapabilityScope;
|
|
25
|
+
/** Risk label shown on the market permissions page. */
|
|
26
|
+
level: PluginCapabilityLevel;
|
|
27
|
+
}
|
|
28
|
+
/** An installed-plugin record, as returned by plugin.scanInstalled / plugin.system. */
|
|
29
|
+
export interface PluginInstalledEntry {
|
|
30
|
+
id: string;
|
|
31
|
+
name: string;
|
|
32
|
+
version: string;
|
|
33
|
+
/** Whether the plugin worker is enabled. */
|
|
34
|
+
enabled: boolean;
|
|
35
|
+
source: PluginSource;
|
|
36
|
+
type: PluginType;
|
|
37
|
+
/** True for system plugins (cannot be uninstalled). */
|
|
38
|
+
system?: boolean;
|
|
39
|
+
/** Icon (relative path inside the plugin root). */
|
|
40
|
+
icon?: string;
|
|
41
|
+
/** Plugin organization ('@xxx'); absent = no organization. */
|
|
42
|
+
organization?: string;
|
|
43
|
+
/** Plugin root directory (absolute). */
|
|
44
|
+
path: string;
|
|
45
|
+
/** Epoch milliseconds when it was installed. */
|
|
46
|
+
installedAt: number;
|
|
47
|
+
/** Epoch milliseconds of the last launch. */
|
|
48
|
+
lastUsedAt?: number;
|
|
49
|
+
}
|
|
50
|
+
/** A registry entry payload accepted by plugin.registry.report (matches the host installed.json entry shape). */
|
|
51
|
+
export interface PluginRegistryEntry {
|
|
52
|
+
id: string;
|
|
53
|
+
name: string;
|
|
54
|
+
version: string;
|
|
55
|
+
type: PluginType;
|
|
56
|
+
source: PluginSource;
|
|
57
|
+
system?: boolean;
|
|
58
|
+
icon?: string;
|
|
59
|
+
/** dist subdirectory relative to the plugin root (defaults to 'dist'). */
|
|
60
|
+
dist?: string;
|
|
61
|
+
/** Plugin root directory (absolute). */
|
|
62
|
+
path: string;
|
|
63
|
+
/** Epoch milliseconds when the entry was added. */
|
|
64
|
+
addedAt: number;
|
|
65
|
+
}
|
|
66
|
+
/** A dev-plugin entry reported through plugin.dev.sync (dev runtime → host; source is always 'dev'). */
|
|
67
|
+
export interface PluginDevEntry {
|
|
68
|
+
id: string;
|
|
69
|
+
name: string;
|
|
70
|
+
/** Plugin root directory (absolute; contains package.json — dist is not copied). */
|
|
71
|
+
path: string;
|
|
72
|
+
/** dist subdirectory relative to the plugin root (manifest.dist ?? 'dist'). */
|
|
73
|
+
dist: string;
|
|
74
|
+
version?: string;
|
|
75
|
+
type?: PluginType;
|
|
76
|
+
system?: boolean;
|
|
77
|
+
icon?: string;
|
|
78
|
+
/** Epoch milliseconds when the entry was added to the dev list. */
|
|
79
|
+
addedAt: number;
|
|
80
|
+
}
|
|
81
|
+
/** Result of plugin.dev.getDirInfo: where the dev plugin actually lives. */
|
|
82
|
+
export interface PluginDevDirInfo {
|
|
83
|
+
/** Plugin root directory (absolute). */
|
|
84
|
+
dir: string;
|
|
85
|
+
/** dist subdirectory relative to the plugin root. */
|
|
86
|
+
dist: string;
|
|
87
|
+
/** Packaging mode: 'asar' when dist is packed into plugin.asar; 'plain' otherwise. */
|
|
88
|
+
packaging: 'plain' | 'asar';
|
|
89
|
+
}
|
|
90
|
+
/** Result of plugin.dev.startWatcher / plugin.dev.stopWatcher. */
|
|
91
|
+
export interface PluginDevWatcherResult {
|
|
92
|
+
ok: boolean;
|
|
93
|
+
/** startWatcher only: failure reason (localized object for UI display, plain string fallback). */
|
|
94
|
+
error?: string | {
|
|
95
|
+
enUS: string;
|
|
96
|
+
zhCN: string;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/** Options accepted by plugin.dev.readLogs (incremental tail read of the target plugin's main.log). */
|
|
100
|
+
export interface PluginLogReadOptions {
|
|
101
|
+
/** Byte offset to continue reading from (use the previous result's offset). */
|
|
102
|
+
offset?: number;
|
|
103
|
+
/** Maximum bytes to read in one call (defaults to 512 KiB). */
|
|
104
|
+
maxBytes?: number;
|
|
105
|
+
}
|
|
106
|
+
/** Result of plugin.dev.readLogs. */
|
|
107
|
+
export interface PluginLogReadResult {
|
|
108
|
+
/** Complete log lines read. */
|
|
109
|
+
lines: string[];
|
|
110
|
+
/** Next byte offset to continue from. */
|
|
111
|
+
offset: number;
|
|
112
|
+
/** True when reading restarted from the log tail (rotation or an oversized gap). */
|
|
113
|
+
reset: boolean;
|
|
114
|
+
/** True when output was cut at the read limit. */
|
|
115
|
+
truncated: boolean;
|
|
116
|
+
}
|
|
117
|
+
/** Result of plugin.logs.subscribe. */
|
|
118
|
+
export interface PluginLogSubscribeResult {
|
|
119
|
+
/** Subscription id (pass to plugin.logs.unsubscribe). */
|
|
120
|
+
subId: string;
|
|
121
|
+
}
|
|
122
|
+
/** Result of plugin.installLocal. */
|
|
123
|
+
export interface PluginInstallLocalResult {
|
|
124
|
+
ok: boolean;
|
|
125
|
+
/** Installed plugin id (from the manifest dlient.id). */
|
|
126
|
+
id: string;
|
|
127
|
+
/** Target install directory (absolute). */
|
|
128
|
+
path: string;
|
|
129
|
+
}
|
|
130
|
+
/** Flat signature map for the plugin module. */
|
|
131
|
+
export type PluginModuleApi = {
|
|
132
|
+
/** Lists the full host api-table metadata (keys + scope/level/localized descriptions). System plugins only. */
|
|
133
|
+
'plugin.capabilities'(): Promise<PluginCapability[]>;
|
|
134
|
+
/** Reports the complete installed registry from the market worker; the host refreshes its cache from it. System plugins only. */
|
|
135
|
+
'plugin.registry.report'(entries: PluginRegistryEntry[]): Promise<{
|
|
136
|
+
ok: boolean;
|
|
137
|
+
}>;
|
|
138
|
+
/** Starts a plugin worker (already running → no-op). System plugins only. */
|
|
139
|
+
'plugin.start'(pluginId: string): Promise<void>;
|
|
140
|
+
/** Stops a plugin worker (also cleans up its owned WebContentsView). System plugins only. */
|
|
141
|
+
'plugin.stop'(pluginId: string): Promise<void>;
|
|
142
|
+
/** Lists the installed system plugins. */
|
|
143
|
+
'plugin.system'(): Promise<PluginInstalledEntry[]>;
|
|
144
|
+
/** Scans the installed plugins (registry + directory fallback) into a unified list. Worker-scope primitive for dev-tools/market. */
|
|
145
|
+
'plugin.scanInstalled'(): Promise<PluginInstalledEntry[]>;
|
|
146
|
+
/** Lists all running-instance runtime states (formal + dev records). Shape is host-internal; consumed by dev-tools. */
|
|
147
|
+
'plugin.runtimeList'(): Promise<unknown[]>;
|
|
148
|
+
/** Imports a local plugin (copy artifacts + patch manifest + register + report + start). Worker-scope primitive for dev-tools. */
|
|
149
|
+
'plugin.installLocal'(dir: string): Promise<PluginInstallLocalResult>;
|
|
150
|
+
/** Whether a plugin worker is currently running. */
|
|
151
|
+
'plugin.isRunning'(pluginId: string): Promise<boolean>;
|
|
152
|
+
/** Post-uninstall cleanup of a plugin (grants + change broadcast). System plugins only. */
|
|
153
|
+
'plugin.cleanupUninstall'(pluginId: string): Promise<void>;
|
|
154
|
+
/** Opens a directory picker for selecting a dev plugin dir; resolves null when cancelled. */
|
|
155
|
+
'plugin.dev.selectDirectory'(): Promise<string | null>;
|
|
156
|
+
/** Resolves the dev directory info (dir/dist/packaging) of a dev plugin id; null when unknown. */
|
|
157
|
+
'plugin.dev.getDirInfo'(pluginId: string): Promise<PluginDevDirInfo | null>;
|
|
158
|
+
/** Dev runtime reports its full dev-plugin list to the host (cache update; no fs grants implied). */
|
|
159
|
+
'plugin.dev.sync'(entries: PluginDevEntry[]): Promise<void>;
|
|
160
|
+
/** Starts the hot-reload watcher for a dev plugin (call after a build completes). */
|
|
161
|
+
'plugin.dev.startWatcher'(pluginId: string): Promise<PluginDevWatcherResult>;
|
|
162
|
+
/** Stops the hot-reload watcher of a dev plugin (during build/refresh). */
|
|
163
|
+
'plugin.dev.stopWatcher'(pluginId: string): Promise<PluginDevWatcherResult>;
|
|
164
|
+
/** Re-forks the dev-instance worker of a dev plugin (last step of the refresh flow). */
|
|
165
|
+
'plugin.dev.startDevWorker'(pluginId: string): Promise<void>;
|
|
166
|
+
/** Stops the dev-instance worker of a dev plugin (first step of the refresh flow). */
|
|
167
|
+
'plugin.dev.stopDevWorker'(pluginId: string): Promise<void>;
|
|
168
|
+
/** Whether the dev instance worker's direct port is ready (running may precede port-ready). */
|
|
169
|
+
'plugin.dev.isPortReady'(pluginId: string): Promise<boolean>;
|
|
170
|
+
/** Reads the buffered tail of a target plugin's log (incremental byte-offset reads). */
|
|
171
|
+
'plugin.dev.readLogs'(pluginId: string, options?: PluginLogReadOptions): Promise<PluginLogReadResult>;
|
|
172
|
+
/** Clears the target plugin's runtime log file (also resets the incremental half-line cache). */
|
|
173
|
+
'plugin.dev.clearLogs'(pluginId: string): Promise<void>;
|
|
174
|
+
/** Compatibility with legacy hosts: lists dev plugins (hosts without the dev runtime reject at runtime). */
|
|
175
|
+
'plugin.dev.list'(): Promise<unknown>;
|
|
176
|
+
/** Compatibility with legacy hosts: removes a dev plugin by id (hosts without the dev runtime reject at runtime). */
|
|
177
|
+
'plugin.dev.remove'(pluginId: string): Promise<unknown>;
|
|
178
|
+
/** Subscribes the caller to a target plugin's log lines (host pushes each line to the caller as `dev-tools.__onPluginLog`). */
|
|
179
|
+
'plugin.logs.subscribe'(pluginId: string): Promise<PluginLogSubscribeResult>;
|
|
180
|
+
/** Unsubscribes a log subscription (subId from plugin.logs.subscribe). */
|
|
181
|
+
'plugin.logs.unsubscribe'(pluginId: string, subId: string): Promise<boolean>;
|
|
182
|
+
/** Sets the active content-area plugin (was webview.setActivePlugin); null clears it. */
|
|
183
|
+
'plugin.setActive'(pluginId: string | null): Promise<void>;
|
|
184
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* powerSaveBlocker host-api — typed single source.
|
|
3
|
+
* Real source of truth: app/src/main/api/power-save.ts (handler reads these fields).
|
|
4
|
+
* All docs are English; keep in sync with the main-process api table.
|
|
5
|
+
*/
|
|
6
|
+
/** Blocker types accepted by powerSaveBlocker.start. */
|
|
7
|
+
export type PowerSaveBlockerType = 'prevent-app-suspension' | 'prevent-display-sleep';
|
|
8
|
+
/** Flat signature map for the powerSaveBlocker module. */
|
|
9
|
+
export type PowerSaveModuleApi = {
|
|
10
|
+
/** Starts blocking the system from entering low-power mode; resolves with the blocker id. Worker scope. */
|
|
11
|
+
'powerSaveBlocker.start'(type: PowerSaveBlockerType): Promise<number>;
|
|
12
|
+
/** Stops the blocker with the given id. Worker scope. */
|
|
13
|
+
'powerSaveBlocker.stop'(id: number): Promise<void>;
|
|
14
|
+
/** Whether the blocker with the given id is still active. Worker scope. */
|
|
15
|
+
'powerSaveBlocker.isStarted'(id: number): Promise<boolean>;
|
|
16
|
+
};
|