@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
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# @dlient/api-types — host-api 共享单源类型
|
|
2
|
+
|
|
3
|
+
目的:把 host-api 的**方法签名 + 参数/返回类型 + 英文说明**收敛为单一来源,worker(`@dlient/plugin-sdk`)与 UI(`@dlient/api-bridge`)两端引用同一套类型,避免双份漂移。
|
|
4
|
+
|
|
5
|
+
## 真源
|
|
6
|
+
主进程 api 目录 `app/src/main/api/*.ts`(方法 key、handler 实际读取的参数字段、英文 description)。新增/修改 host-api 时先改 api 目录,再同步本包。
|
|
7
|
+
|
|
8
|
+
## 文件布局
|
|
9
|
+
- `src/index.ts`:汇总导出(主会话维护,勿动)。
|
|
10
|
+
- `src/modules/<module>.ts`:每个 host-api 模块一个文件。
|
|
11
|
+
|
|
12
|
+
## 每个模块文件导出约定(样板见 `src/modules/notification.ts`)
|
|
13
|
+
1. 该模块的方法**输入 Options 接口**(字段逐一加英文注释;字段语义以主进程 handler 实际读取为准)。
|
|
14
|
+
2. 返回值类型(从 handler 返回结构提取)。
|
|
15
|
+
3. 扁平签名类型:key = 完整点路径(如 `'fs.read'`),值为方法函数类型。
|
|
16
|
+
命名:模块类型名 `<Cap>ModuleApi`,值形如:
|
|
17
|
+
```ts
|
|
18
|
+
export type FsModuleApi = {
|
|
19
|
+
'fs.read'(options: FsReadOptions): Promise<FsReadResult>
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
4. 每个方法一条英文 JSDoc 注释(一句话,说明用途/注意点),放在签名成员上。
|
|
23
|
+
|
|
24
|
+
## 通用约束
|
|
25
|
+
- 全部注释用英文。
|
|
26
|
+
- 参数用**具名 options 对象**(与 handler 一致),不出现 `any` 参数。
|
|
27
|
+
- 方法若无参/基本类型,直接签名(如 `'app.getVersion'(): Promise<string>`)。
|
|
28
|
+
- 不导入任何运行时依赖;文件内只含 type/interface 声明(type-only)。
|
|
29
|
+
- 保留 `@dlient/plugin-sdk/src/host-api.ts` 顶部模块列表的既有已文档化字段(如 NotificationSendOptions)作参考。
|
|
30
|
+
|
|
31
|
+
## 修改 host-api 的同步流程(重要)
|
|
32
|
+
1. 改主进程 `app/src/main/api/*.ts`(真源:方法行为/description)。
|
|
33
|
+
2. 同步本包 `src/modules/<module>.ts`:方法签名/options/返回类型/英文注释(改 method key 时同步改)。
|
|
34
|
+
3. 两端类型**自动跟随**:`@dlient/plugin-sdk` host-api.ts 与 `@dlient/api-bridge` 均以 `HostApiMap['<path>']` 引用本包,无需再手写双份。
|
|
35
|
+
4. 运行时 path 表保持:plugin-sdk `HOST_API_PATHS` / api-bridge `UI_HOST_API_PATHS` 增删 key 时与本包同步(防路径漂移)。
|
|
36
|
+
5. 改完执行:`npm --prefix app/packages/api-types run build`,再 rebuild plugin-sdk / api-bridge / ui,并把 dist 同步到 app 与插件 node_modules(发布时按 registry 依赖传递,无需手工同步)。
|
|
37
|
+
|
|
38
|
+
## 发布顺序
|
|
39
|
+
`@dlient/api-types` 先发 → `@dlient/plugin-sdk`、`@dlient/api-bridge`、`@dlient/ui` 依序发新版本(它们已声明对 api-types 的依赖)。
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @dlient/api-types — host-api 共享单源类型(docs/README 见本目录)。
|
|
3
|
+
*
|
|
4
|
+
* worker(@dlient/plugin-sdk rpc.xx)与 UI(@dlient/api-bridge api.xx)两端引用同一套
|
|
5
|
+
* 方法签名 / options / 返回类型与英文说明,避免双份漂移。真源:app/src/main/api/*.ts。
|
|
6
|
+
* 本文件仅做汇总:新增 host-api 方法时在 modules/<module>.ts 增补,并确认模块已在此 re-export。
|
|
7
|
+
*/
|
|
8
|
+
import type { AppModuleApi } from './modules/app';
|
|
9
|
+
import type { I18nModuleApi } from './modules/i18n';
|
|
10
|
+
import type { OsModuleApi } from './modules/os';
|
|
11
|
+
import type { SystemModuleApi } from './modules/system';
|
|
12
|
+
import type { PowerSaveModuleApi } from './modules/powerSave';
|
|
13
|
+
import type { ScreenModuleApi } from './modules/screen';
|
|
14
|
+
import type { FsModuleApi } from './modules/fs';
|
|
15
|
+
import type { DialogModuleApi } from './modules/dialog';
|
|
16
|
+
import type { ClipboardModuleApi } from './modules/clipboard';
|
|
17
|
+
import type { NetModuleApi } from './modules/net';
|
|
18
|
+
import type { NotificationModuleApi } from './modules/notification';
|
|
19
|
+
import type { ChildModuleApi } from './modules/child';
|
|
20
|
+
import type { PermissionModuleApi } from './modules/permission';
|
|
21
|
+
import type { PluginModuleApi } from './modules/plugin';
|
|
22
|
+
import type { WebviewModuleApi } from './modules/webview';
|
|
23
|
+
import type { LogModuleApi } from './modules/log';
|
|
24
|
+
export type * from './modules/app';
|
|
25
|
+
export type * from './modules/i18n';
|
|
26
|
+
export type * from './modules/os';
|
|
27
|
+
export type * from './modules/system';
|
|
28
|
+
export type * from './modules/powerSave';
|
|
29
|
+
export type * from './modules/screen';
|
|
30
|
+
export type * from './modules/fs';
|
|
31
|
+
export type * from './modules/dialog';
|
|
32
|
+
export type * from './modules/clipboard';
|
|
33
|
+
export type * from './modules/net';
|
|
34
|
+
export type * from './modules/notification';
|
|
35
|
+
export type * from './modules/child';
|
|
36
|
+
export type * from './modules/permission';
|
|
37
|
+
export type * from './modules/plugin';
|
|
38
|
+
export type * from './modules/webview';
|
|
39
|
+
/**
|
|
40
|
+
* 全部 host-api 方法的统一签名表(扁平,key = 点路径)。
|
|
41
|
+
* worker 端以它为 rpc 模块树的类型基础;UI 端引用其中开放子集。
|
|
42
|
+
*/
|
|
43
|
+
export type HostApiMap = AppModuleApi & I18nModuleApi & OsModuleApi & SystemModuleApi & PowerSaveModuleApi & ScreenModuleApi & FsModuleApi & DialogModuleApi & ClipboardModuleApi & NetModuleApi & NotificationModuleApi & ChildModuleApi & PermissionModuleApi & PluginModuleApi & WebviewModuleApi & LogModuleApi;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* app host-api — typed single source.
|
|
3
|
+
* Real source of truth: app/src/main/api/app.ts (handler reads these fields).
|
|
4
|
+
* All docs are English; keep in sync with the main-process api table.
|
|
5
|
+
*/
|
|
6
|
+
/** Whitelisted names accepted by app.getPath. 'userData' resolves to the plugin-isolated dir, 'plugins' to the host plugins dir. */
|
|
7
|
+
export type AppPathName = 'userData' | 'plugins' | 'home' | 'temp' | 'documents' | 'downloads' | 'music' | 'pictures' | 'videos' | 'recent';
|
|
8
|
+
/** Options accepted by app.notify (worker scope; a '__render' receiver is stripped with a security warning). */
|
|
9
|
+
export interface AppNotifyOptions {
|
|
10
|
+
/** Event name delivered to matching listeners. Required. */
|
|
11
|
+
event: string;
|
|
12
|
+
/** Target receiver role/plugin ids; 'all' broadcasts to every listener. Defaults to []. */
|
|
13
|
+
receiver?: string[];
|
|
14
|
+
/** Arbitrary serializable payload attached to the event. */
|
|
15
|
+
data?: unknown;
|
|
16
|
+
/** Deduplication/sequence id. Defaults to `${event}-${Date.now()}`. */
|
|
17
|
+
event_id?: string;
|
|
18
|
+
}
|
|
19
|
+
/** Result of app.notify: constant success marker. */
|
|
20
|
+
export interface AppNotifyResult {
|
|
21
|
+
ok: true;
|
|
22
|
+
}
|
|
23
|
+
/** Options accepted by app.shortcut.register. */
|
|
24
|
+
export interface AppShortcutRegisterOptions {
|
|
25
|
+
/** Local shortcut id reported back to the plugin when the accelerator fires. Required. */
|
|
26
|
+
id: string;
|
|
27
|
+
/** Global accelerator in Electron Accelerator syntax. Required; registration throws when the key is busy. */
|
|
28
|
+
accelerator: string;
|
|
29
|
+
/** Reserved action hint carried by the registration. */
|
|
30
|
+
action?: string;
|
|
31
|
+
}
|
|
32
|
+
/** One native context-menu item template (only safe display fields are honored; click callbacks are injected by the host). */
|
|
33
|
+
export interface AppMenuItemSpec {
|
|
34
|
+
/** Identifier returned when the item is clicked; optional for separators. */
|
|
35
|
+
id?: string;
|
|
36
|
+
/** Display label. */
|
|
37
|
+
label?: string;
|
|
38
|
+
/** Item kind. Defaults to 'normal'; 'separator' ignores all other fields. */
|
|
39
|
+
type?: 'normal' | 'separator' | 'checkbox';
|
|
40
|
+
/** Whether the item is enabled. Defaults to true. */
|
|
41
|
+
enabled?: boolean;
|
|
42
|
+
/** Initial checked state for 'checkbox' items. Defaults to false. */
|
|
43
|
+
checked?: boolean;
|
|
44
|
+
}
|
|
45
|
+
/** Options accepted by app.menu.popup. */
|
|
46
|
+
export interface AppMenuPopupOptions {
|
|
47
|
+
/** Menu item templates. Must be a non-empty array. */
|
|
48
|
+
items: AppMenuItemSpec[];
|
|
49
|
+
/** Optional popup x position (screen DIP). */
|
|
50
|
+
x?: number;
|
|
51
|
+
/** Optional popup y position (screen DIP). */
|
|
52
|
+
y?: number;
|
|
53
|
+
}
|
|
54
|
+
/** Result of app.menu.popup: the clicked item id, or null when dismissed (blank area / ESC). */
|
|
55
|
+
export type AppMenuPopupResult = string | null;
|
|
56
|
+
/** Options accepted by app.createNativeHost (usually called internally by the SDK's createNativeHost helper). */
|
|
57
|
+
export interface CreateNativeHostOptions {
|
|
58
|
+
/** Entry file name located inside the plugin dist dir; path traversal is rejected. Required. */
|
|
59
|
+
fileName: string;
|
|
60
|
+
/** Absolute path to the Node executable used to run the entry. Required. */
|
|
61
|
+
node: string;
|
|
62
|
+
}
|
|
63
|
+
/** Options accepted by app.createNativeClient (same shape as hosted child spawn options). */
|
|
64
|
+
export interface CreateNativeClientOptions {
|
|
65
|
+
/** Command to spawn. Required (missing cmd fails the call). */
|
|
66
|
+
cmd: string;
|
|
67
|
+
/** Command-line arguments. Defaults to []. */
|
|
68
|
+
args?: string[];
|
|
69
|
+
/** Working directory of the child process. */
|
|
70
|
+
cwd?: string;
|
|
71
|
+
/** Extra environment variables (merged over a stripped base env). */
|
|
72
|
+
env?: Record<string, string>;
|
|
73
|
+
/** Detach the child process. A platform default is applied when omitted. */
|
|
74
|
+
detached?: boolean;
|
|
75
|
+
/** Human-readable purpose shown on the spawn authorization prompt. */
|
|
76
|
+
description?: string;
|
|
77
|
+
}
|
|
78
|
+
/** Cross-process reference to a host-managed child process (returned by createNativeHost / createNativeClient). */
|
|
79
|
+
export interface NativeSpawnRef {
|
|
80
|
+
/** Host-side handle id (used by disposeNativeClient and the SDK child handles). */
|
|
81
|
+
handleId: string;
|
|
82
|
+
/** Process id (diagnostics/display). */
|
|
83
|
+
pid: number;
|
|
84
|
+
}
|
|
85
|
+
/** Kill/dispose outcome of app.disposeNativeClient (idempotent; already-exited handles report reason). */
|
|
86
|
+
export interface NativeDisposeResult {
|
|
87
|
+
ok: boolean;
|
|
88
|
+
reason?: string;
|
|
89
|
+
}
|
|
90
|
+
/** Flat signature map for the app module. */
|
|
91
|
+
export type AppModuleApi = {
|
|
92
|
+
/** Host app version. */
|
|
93
|
+
'app.getVersion'(): Promise<string>;
|
|
94
|
+
/** Resolves a whitelisted path; 'userData' returns the plugin-isolated data dir, 'plugins' the host plugins dir. */
|
|
95
|
+
'app.getPath'(name: AppPathName): Promise<string>;
|
|
96
|
+
/** Whether the host currently has a focused window. */
|
|
97
|
+
'app.isActive'(): Promise<boolean>;
|
|
98
|
+
/** Whether all host windows are hidden. */
|
|
99
|
+
'app.isHidden'(): Promise<boolean>;
|
|
100
|
+
/** Host app name. */
|
|
101
|
+
'app.getName'(): Promise<string>;
|
|
102
|
+
/** Host app locale. */
|
|
103
|
+
'app.getLocale'(): Promise<string>;
|
|
104
|
+
/** Host app locale country code. */
|
|
105
|
+
'app.getLocaleCountryCode'(): Promise<string>;
|
|
106
|
+
/** Host system locale. */
|
|
107
|
+
'app.getSystemLocale'(): Promise<string>;
|
|
108
|
+
/** Host preferred system languages (most to least preferred). */
|
|
109
|
+
'app.getPreferredSystemLanguages'(): Promise<string[]>;
|
|
110
|
+
/** Broadcasts an event to renderer receivers; a '__render' receiver is stripped and warned. Worker scope. */
|
|
111
|
+
'app.notify'(options: AppNotifyOptions): Promise<AppNotifyResult>;
|
|
112
|
+
/** Registers or removes the OS auto-launch entry for the host. Worker scope; dangerous. */
|
|
113
|
+
'app.setAutoLaunch'(enabled: boolean): Promise<void>;
|
|
114
|
+
/** Forwards a global setting change ('theme' | 'language') to all host windows. Worker scope. */
|
|
115
|
+
'app.event'(channel: 'theme' | 'language', value: string): Promise<void>;
|
|
116
|
+
/** Starts a host-managed native Node process running an entry inside the plugin dist. Worker scope; dangerous. */
|
|
117
|
+
'app.createNativeHost'(options: CreateNativeHostOptions): Promise<NativeSpawnRef>;
|
|
118
|
+
/** Spawns a host-managed child process and returns its cross-process handle. Worker scope; dangerous. */
|
|
119
|
+
'app.createNativeClient'(options: CreateNativeClientOptions): Promise<NativeSpawnRef>;
|
|
120
|
+
/** Kills and disposes a hosted child by handle id (idempotent). Worker scope; dangerous. */
|
|
121
|
+
'app.disposeNativeClient'(handleId: string): Promise<NativeDisposeResult>;
|
|
122
|
+
/** Closes the main window (frameless title-bar control). Worker scope. */
|
|
123
|
+
'app.window.close'(): Promise<void>;
|
|
124
|
+
/** Focuses the main window. Worker scope. */
|
|
125
|
+
'app.window.focus'(): Promise<void>;
|
|
126
|
+
/** Blurs the main window. Worker scope. */
|
|
127
|
+
'app.window.blur'(): Promise<void>;
|
|
128
|
+
/** Shows the main window. Worker scope. */
|
|
129
|
+
'app.window.show'(): Promise<void>;
|
|
130
|
+
/** Hides the main window. Worker scope. */
|
|
131
|
+
'app.window.hide'(): Promise<void>;
|
|
132
|
+
/** Maximizes the main window. Worker scope. */
|
|
133
|
+
'app.window.maximize'(): Promise<void>;
|
|
134
|
+
/** Restores the main window from maximized. Worker scope. */
|
|
135
|
+
'app.window.unmaximize'(): Promise<void>;
|
|
136
|
+
/** Minimizes the main window. Worker scope. */
|
|
137
|
+
'app.window.minimize'(): Promise<void>;
|
|
138
|
+
/** Restores the main window from minimized. Worker scope. */
|
|
139
|
+
'app.window.restore'(): Promise<void>;
|
|
140
|
+
/** Whether the main window is maximized. Worker scope. */
|
|
141
|
+
'app.window.isMaximized'(): Promise<boolean>;
|
|
142
|
+
/** Sets the main window full screen. Worker scope. */
|
|
143
|
+
'app.window.setFullScreen'(flag: boolean): Promise<void>;
|
|
144
|
+
/** Reads a JSON data file from the plugin-isolated data dir; resolves null when missing or invalid. */
|
|
145
|
+
'app.data.read'(file: string): Promise<unknown>;
|
|
146
|
+
/** Atomically writes a JSON data file under the plugin-isolated data dir (file-locked). */
|
|
147
|
+
'app.data.write'(file: string, json: unknown): Promise<void>;
|
|
148
|
+
/** Encrypts a string with a plugin-scoped key (AES-256-GCM). */
|
|
149
|
+
'app.crypt.encrypt'(plain: string): Promise<string>;
|
|
150
|
+
/** Decrypts a plugin-scoped ciphertext (base64 input). */
|
|
151
|
+
'app.crypt.decrypt'(value: string): Promise<string>;
|
|
152
|
+
/** Registers a global shortcut bound to a plugin action id; a busy accelerator throws INVALID. Worker scope; dangerous. */
|
|
153
|
+
'app.shortcut.register'(options: AppShortcutRegisterOptions): Promise<void>;
|
|
154
|
+
/** Unregisters a global shortcut by its accelerator. Worker scope; dangerous. */
|
|
155
|
+
'app.shortcut.unregister'(accelerator: string): Promise<void>;
|
|
156
|
+
/** Pops up a native context menu at the cursor (or given x/y); resolves with the clicked item id or null. Worker scope. */
|
|
157
|
+
'app.menu.popup'(options: AppMenuPopupOptions): Promise<AppMenuPopupResult>;
|
|
158
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* child host-api — typed single source.
|
|
3
|
+
* Real source of truth: app/src/main/api/child.ts (handler reads these fields).
|
|
4
|
+
* All docs are English; keep in sync with the main-process api table.
|
|
5
|
+
*/
|
|
6
|
+
/** Options accepted by child.execFile (one-shot capture of a single command; shares the spawn option shape). */
|
|
7
|
+
export interface ChildExecFileOptions extends SpawnHostedOptions {
|
|
8
|
+
/** Kill the command if it does not finish within this many milliseconds. */
|
|
9
|
+
timeout?: number;
|
|
10
|
+
}
|
|
11
|
+
/** Streamed child-process event callbacks delivered by the host over the child-event channel. */
|
|
12
|
+
export interface ChildEventHandlers {
|
|
13
|
+
/** Streamed stdout chunk (one callback at a time). */
|
|
14
|
+
onStdout?: (data: string) => void;
|
|
15
|
+
/** Streamed stderr chunk (one callback at a time). */
|
|
16
|
+
onStderr?: (data: string) => void;
|
|
17
|
+
/** Exit notification: natural exit or killed. */
|
|
18
|
+
onExit?: (info: {
|
|
19
|
+
code: number | null;
|
|
20
|
+
signal?: string;
|
|
21
|
+
reason: 'exited' | 'killed';
|
|
22
|
+
}) => void;
|
|
23
|
+
/** Spawn failure (e.g. command not found). */
|
|
24
|
+
onError?: (err: Error) => void;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Handle returned by child.spawn (SDK shape — identical on the worker `rpc.child.spawn`
|
|
28
|
+
* surface). The host stores the underlying process as an opaque handle ref; the SDK performs
|
|
29
|
+
* the child-subscribe handshake so stdout/stderr/exit stream back to these callbacks, and
|
|
30
|
+
* kill/stdin go through the child-control message channel.
|
|
31
|
+
*/
|
|
32
|
+
export interface ChildHandle {
|
|
33
|
+
/** Host-side handle id. */
|
|
34
|
+
handleId: string;
|
|
35
|
+
/** Read-only process id (diagnostics / display). */
|
|
36
|
+
pid: number;
|
|
37
|
+
/** Idempotent: kills the process tree and unregisters; no-op once exited. */
|
|
38
|
+
kill(): Promise<void>;
|
|
39
|
+
/** Streamed stdout (child-event push). One callback at a time. */
|
|
40
|
+
onStdout(cb: (data: string) => void): void;
|
|
41
|
+
/** Streamed stderr (child-event push). One callback at a time. */
|
|
42
|
+
onStderr(cb: (data: string) => void): void;
|
|
43
|
+
/** Exit event (child-event push; natural exit or killed). */
|
|
44
|
+
onExit(cb: (info: {
|
|
45
|
+
code: number | null;
|
|
46
|
+
signal?: string;
|
|
47
|
+
reason: 'exited' | 'killed';
|
|
48
|
+
}) => void): void;
|
|
49
|
+
/** Spawn failure event (child-event push; e.g. command not found). */
|
|
50
|
+
onError(cb: (err: Error) => void): void;
|
|
51
|
+
/** Writes stdin (child-control write; used by the native-host RPC bridge). */
|
|
52
|
+
write(chunk: string): Promise<void>;
|
|
53
|
+
/** Ends stdin (child-control end; graceful close signal). */
|
|
54
|
+
end(): Promise<void>;
|
|
55
|
+
}
|
|
56
|
+
/** Options accepted by child.spawn as exposed by the SDK (same shape as ChildSpawnOptions). */
|
|
57
|
+
export interface SpawnHostedOptions {
|
|
58
|
+
/** Command to run: absolute path, or executable name resolved through a stripped PATH. Required. */
|
|
59
|
+
cmd: string;
|
|
60
|
+
/** Command-line arguments. Defaults to []. */
|
|
61
|
+
args?: string[];
|
|
62
|
+
/** Working directory of the child process. */
|
|
63
|
+
cwd?: string;
|
|
64
|
+
/** Extra environment variables merged over the stripped base env (PATH/HOME). */
|
|
65
|
+
env?: Record<string, string>;
|
|
66
|
+
/** Whether to spawn detached. Defaults to true except on Windows. */
|
|
67
|
+
detached?: boolean;
|
|
68
|
+
/** Human-readable purpose shown in the spawn-confirmation dialog when the command is not pre-authorized. */
|
|
69
|
+
description?: string;
|
|
70
|
+
}
|
|
71
|
+
/** Result of child.execFile: captured stdout/stderr and the numeric exit code. */
|
|
72
|
+
export interface ChildExecFileResult {
|
|
73
|
+
stdout: string;
|
|
74
|
+
stderr: string;
|
|
75
|
+
/** 0 on success; the error code on failure; -1 when no numeric code was reported. */
|
|
76
|
+
code: number;
|
|
77
|
+
}
|
|
78
|
+
/** Flat signature map for the child module. */
|
|
79
|
+
export type ChildModuleApi = {
|
|
80
|
+
/**
|
|
81
|
+
* Spawns a subprocess through the host (command whitelist + spawn-confirm authorization)
|
|
82
|
+
* and returns a ChildHandle — kill/stdin and streamed stdout/stderr/exit/error events are
|
|
83
|
+
* delivered over message channels via the SDK subscription handshake.
|
|
84
|
+
* (Internally the host keeps an opaque ref of shape { handleId, pid }.)
|
|
85
|
+
*/
|
|
86
|
+
'child.spawn'(options: SpawnHostedOptions): Promise<ChildHandle>;
|
|
87
|
+
/** Runs a command once and captures its output (probe-style usage, e.g. `node --version`). Authorization is the same as child.spawn. */
|
|
88
|
+
'child.execFile'(options: ChildExecFileOptions): Promise<ChildExecFileResult>;
|
|
89
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* clipboard host-api — typed single source.
|
|
3
|
+
* Real source of truth: app/src/main/api/clipboard.ts (handler reads these fields).
|
|
4
|
+
* All docs are English; keep in sync with the main-process api table.
|
|
5
|
+
* Reading methods need the 'clipboard.read' permission, writing/clearing 'clipboard.write'.
|
|
6
|
+
*/
|
|
7
|
+
/** Clipboard type: 'clipboard' (default) or Linux-only 'selection'. */
|
|
8
|
+
export type ClipboardType = 'selection' | 'clipboard';
|
|
9
|
+
/** Bookmark data read from / written to the clipboard (macOS / Windows). */
|
|
10
|
+
export interface ClipboardBookmark {
|
|
11
|
+
/** Bookmark title. */
|
|
12
|
+
title: string;
|
|
13
|
+
/** Bookmark URL. */
|
|
14
|
+
url: string;
|
|
15
|
+
}
|
|
16
|
+
/** Image source accepted by clipboard.writeImage (one of dataUrl/path/buffer). */
|
|
17
|
+
export interface ClipboardImageInput {
|
|
18
|
+
/** Image content as a data URL. */
|
|
19
|
+
dataUrl?: string;
|
|
20
|
+
/** Path to an image file on disk. */
|
|
21
|
+
path?: string;
|
|
22
|
+
/** Raw encoded image bytes (PNG/JPEG; size hint used when the format needs it). */
|
|
23
|
+
buffer?: ArrayBuffer;
|
|
24
|
+
/** Width hint for the raw buffer (used only with buffer). */
|
|
25
|
+
width?: number;
|
|
26
|
+
/** Height hint for the raw buffer (used only with buffer). */
|
|
27
|
+
height?: number;
|
|
28
|
+
}
|
|
29
|
+
/** Result of clipboard.readImage: an empty image yields an empty dataUrl. */
|
|
30
|
+
export interface ClipboardReadImageResult {
|
|
31
|
+
/** dataUrl of the image ('' when the clipboard holds no image). */
|
|
32
|
+
dataUrl: string;
|
|
33
|
+
/** Image size in DIP. */
|
|
34
|
+
size: {
|
|
35
|
+
width: number;
|
|
36
|
+
height: number;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** Composite payload accepted by clipboard.write. */
|
|
40
|
+
export interface ClipboardWriteData {
|
|
41
|
+
/** Plain text content. */
|
|
42
|
+
text?: string;
|
|
43
|
+
/** HTML content. */
|
|
44
|
+
html?: string;
|
|
45
|
+
/** Image content (dataUrl or file path). */
|
|
46
|
+
image?: {
|
|
47
|
+
dataUrl?: string;
|
|
48
|
+
path?: string;
|
|
49
|
+
};
|
|
50
|
+
/** RTF content. */
|
|
51
|
+
rtf?: string;
|
|
52
|
+
/** Bookmark content (macOS / Windows). */
|
|
53
|
+
bookmark?: ClipboardBookmark;
|
|
54
|
+
}
|
|
55
|
+
/** Flat signature map for the clipboard module. */
|
|
56
|
+
export type ClipboardModuleApi = {
|
|
57
|
+
/** Reads plain text from the clipboard. */
|
|
58
|
+
'clipboard.readText'(): Promise<string>;
|
|
59
|
+
/** Reads HTML content from the clipboard. */
|
|
60
|
+
'clipboard.readHTML'(type?: ClipboardType): Promise<string>;
|
|
61
|
+
/** Reads RTF content from the clipboard. */
|
|
62
|
+
'clipboard.readRTF'(type?: ClipboardType): Promise<string>;
|
|
63
|
+
/** Reads a bookmark ({ title, url }) from the clipboard (macOS / Windows). */
|
|
64
|
+
'clipboard.readBookmark'(): Promise<ClipboardBookmark>;
|
|
65
|
+
/** Reads the find text (macOS find pasteboard). */
|
|
66
|
+
'clipboard.readFindText'(): Promise<string>;
|
|
67
|
+
/** Reads the clipboard image as { dataUrl, size } (dataUrl is '' when empty). */
|
|
68
|
+
'clipboard.readImage'(type?: ClipboardType): Promise<ClipboardReadImageResult>;
|
|
69
|
+
/** Reads raw bytes stored under a format (experimental; delivered as a typed array). */
|
|
70
|
+
'clipboard.readBuffer'(format: string): Promise<Uint8Array>;
|
|
71
|
+
/** Reads clipboard content by format (experimental). */
|
|
72
|
+
'clipboard.read'(format: string): Promise<string>;
|
|
73
|
+
/** Lists the formats currently available on the clipboard. */
|
|
74
|
+
'clipboard.availableFormats'(type?: ClipboardType): Promise<string[]>;
|
|
75
|
+
/** Checks whether the clipboard holds the given format (experimental). */
|
|
76
|
+
'clipboard.has'(format: string, type?: ClipboardType): Promise<boolean>;
|
|
77
|
+
/** Writes plain text to the clipboard. */
|
|
78
|
+
'clipboard.writeText'(text: string): Promise<void>;
|
|
79
|
+
/** Writes HTML content to the clipboard. */
|
|
80
|
+
'clipboard.writeHTML'(markup: string, type?: ClipboardType): Promise<void>;
|
|
81
|
+
/** Writes RTF content to the clipboard. */
|
|
82
|
+
'clipboard.writeRTF'(text: string, type?: ClipboardType): Promise<void>;
|
|
83
|
+
/** Writes a bookmark to the clipboard (macOS / Windows). */
|
|
84
|
+
'clipboard.writeBookmark'(title: string, url: string, type?: ClipboardType): Promise<void>;
|
|
85
|
+
/** Writes the find text (macOS find pasteboard). */
|
|
86
|
+
'clipboard.writeFindText'(text: string): Promise<void>;
|
|
87
|
+
/** Writes an image (dataUrl/path/buffer) to the clipboard. */
|
|
88
|
+
'clipboard.writeImage'(image: ClipboardImageInput, type?: ClipboardType): Promise<void>;
|
|
89
|
+
/** Writes raw bytes under a format (experimental). */
|
|
90
|
+
'clipboard.writeBuffer'(format: string, buffer: ArrayBuffer, type?: ClipboardType): Promise<void>;
|
|
91
|
+
/** Writes several representations at once ({ text, html, image, rtf, bookmark }). */
|
|
92
|
+
'clipboard.write'(data: ClipboardWriteData, type?: ClipboardType): Promise<void>;
|
|
93
|
+
/** Clears the clipboard content. */
|
|
94
|
+
'clipboard.clear'(type?: ClipboardType): Promise<void>;
|
|
95
|
+
};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dialog host-api — typed single source.
|
|
3
|
+
* Real source of truth: app/src/main/api/dialog.ts (handler reads these fields).
|
|
4
|
+
* All docs are English; keep in sync with the main-process api table.
|
|
5
|
+
* All methods are async (the *Sync Electron variants are intentionally not exposed);
|
|
6
|
+
* the window argument is not serializable and is omitted — only options are passed.
|
|
7
|
+
*/
|
|
8
|
+
/** Permission tokens accepted by fs.showOpenDialog to auto-grant file access for selected paths. */
|
|
9
|
+
export type DialogFsPermission = 'fs.read' | 'fs.write';
|
|
10
|
+
/** Options accepted by dialog.showMessageBox (serializable subset of Electron MessageBoxOptions). */
|
|
11
|
+
export interface DialogShowMessageBoxOptions {
|
|
12
|
+
/** Dialog title. */
|
|
13
|
+
title?: string;
|
|
14
|
+
/** Message box type controlling the icon and default sound. */
|
|
15
|
+
type?: 'none' | 'info' | 'error' | 'question' | 'warning';
|
|
16
|
+
/** Main message text. Required. */
|
|
17
|
+
message: string;
|
|
18
|
+
/** Extra detail text shown under the message. */
|
|
19
|
+
detail?: string;
|
|
20
|
+
/** Labels of the buttons, in order. Defaults to a single "OK" button. */
|
|
21
|
+
buttons?: string[];
|
|
22
|
+
/** Index of the button activated when Enter is pressed. Defaults to 0. */
|
|
23
|
+
defaultId?: number;
|
|
24
|
+
/** Index of the button activated when Esc is pressed. */
|
|
25
|
+
cancelId?: number;
|
|
26
|
+
/** Label of the confirmation checkbox. */
|
|
27
|
+
checkboxLabel?: string;
|
|
28
|
+
/** Initial checked state of the confirmation checkbox. Defaults to false. */
|
|
29
|
+
checkboxChecked?: boolean;
|
|
30
|
+
/** Whether to apply the Windows button ordering heuristic. Defaults to false. */
|
|
31
|
+
noLink?: boolean;
|
|
32
|
+
}
|
|
33
|
+
/** Result of a successful dialog.showMessageBox call. */
|
|
34
|
+
export interface DialogShowMessageBoxResult {
|
|
35
|
+
/** Index of the clicked button (matches options.buttons order). */
|
|
36
|
+
response: number;
|
|
37
|
+
/** Whether the confirmation checkbox was checked (false when no checkboxLabel is set). */
|
|
38
|
+
checkboxChecked: boolean;
|
|
39
|
+
}
|
|
40
|
+
/** Options accepted by dialog.showOpenDialog (serializable subset of Electron OpenDialogOptions). */
|
|
41
|
+
export interface DialogShowOpenOptions {
|
|
42
|
+
/** Dialog title. */
|
|
43
|
+
title?: string;
|
|
44
|
+
/** Initial path shown by the dialog. */
|
|
45
|
+
defaultPath?: string;
|
|
46
|
+
/** Custom label for the confirm button. */
|
|
47
|
+
buttonLabel?: string;
|
|
48
|
+
/** File-type filters shown in the dialog. */
|
|
49
|
+
filters?: {
|
|
50
|
+
name: string;
|
|
51
|
+
extensions: string[];
|
|
52
|
+
}[];
|
|
53
|
+
/** Dialog behaviour flags. */
|
|
54
|
+
properties?: ('openFile' | 'openDirectory' | 'multiSelections' | 'showHiddenFiles' | 'createDirectory' | 'promptToCreate' | 'noResolveAliases' | 'treatPackageAsDirectory' | 'dontAddToRecent')[];
|
|
55
|
+
/** Informational text shown above the file list. */
|
|
56
|
+
message?: string;
|
|
57
|
+
}
|
|
58
|
+
/** File access granted for the paths picked in dialog.showOpenDialog. */
|
|
59
|
+
export interface DialogFsGrant {
|
|
60
|
+
/** Paths granted for fs.read (mirrors permissions containing 'fs.read'). */
|
|
61
|
+
read: string[];
|
|
62
|
+
/** Paths granted for fs.write (mirrors permissions containing 'fs.write'). */
|
|
63
|
+
write: string[];
|
|
64
|
+
}
|
|
65
|
+
/** Result of a successful dialog.showOpenDialog call (cancel/denial throw instead). */
|
|
66
|
+
export interface DialogShowOpenResult {
|
|
67
|
+
/** Selected paths, realpath-resolved so they match later fs.* whitelist checks. */
|
|
68
|
+
filePaths: string[];
|
|
69
|
+
/** Granted file access per permission requested (empty arrays for pure-select calls). */
|
|
70
|
+
granted: DialogFsGrant;
|
|
71
|
+
}
|
|
72
|
+
/** Options accepted by dialog.showSaveDialog (serializable subset of Electron SaveDialogOptions). */
|
|
73
|
+
export interface DialogShowSaveOptions {
|
|
74
|
+
/** Dialog title. */
|
|
75
|
+
title?: string;
|
|
76
|
+
/** Initial path shown by the dialog. */
|
|
77
|
+
defaultPath?: string;
|
|
78
|
+
/** Custom label for the confirm button. */
|
|
79
|
+
buttonLabel?: string;
|
|
80
|
+
/** File-type filters shown in the dialog. */
|
|
81
|
+
filters?: {
|
|
82
|
+
name: string;
|
|
83
|
+
extensions: string[];
|
|
84
|
+
}[];
|
|
85
|
+
/** Custom label for the filename text field. */
|
|
86
|
+
nameFieldLabel?: string;
|
|
87
|
+
/** Dialog behaviour flags. */
|
|
88
|
+
properties?: ('showHiddenFiles' | 'createDirectory' | 'treatPackageAsDirectory' | 'dontAddToRecent' | 'showOverwriteConfirmation')[];
|
|
89
|
+
/** Informational text shown above the file list. */
|
|
90
|
+
message?: string;
|
|
91
|
+
}
|
|
92
|
+
/** Result of a successful dialog.showSaveDialog call (cancel throws DIALOG_CANCELED instead). */
|
|
93
|
+
export interface DialogShowSaveResult {
|
|
94
|
+
/** The chosen path, realpath-resolved; a temp write grant is registered for it. */
|
|
95
|
+
filePath: string;
|
|
96
|
+
}
|
|
97
|
+
/** Flat signature map for the dialog module. */
|
|
98
|
+
export type DialogModuleApi = {
|
|
99
|
+
/** Shows a native message box and resolves with the clicked button index. */
|
|
100
|
+
'dialog.showMessageBox'(options: DialogShowMessageBoxOptions): Promise<DialogShowMessageBoxResult>;
|
|
101
|
+
/**
|
|
102
|
+
* Shows an open/file-picker dialog. permissions requests fs access for the selected paths
|
|
103
|
+
* (authorization prompt + grant); when omitted (legacy options-only call) it is a pure
|
|
104
|
+
* selection without granting. Cancel or user denial throws DIALOG_CANCELED / USER_DENIED.
|
|
105
|
+
* The `description` argument (optional) is the authorization request copy shown in the
|
|
106
|
+
* fs-access permission dialog when the picked paths are not yet authorized.
|
|
107
|
+
*/
|
|
108
|
+
'dialog.showOpenDialog'(permissions: DialogFsPermission[], options: DialogShowOpenOptions, description?: string): Promise<DialogShowOpenResult>;
|
|
109
|
+
/**
|
|
110
|
+
* Shows a save dialog. The chosen path is written a temp write grant (intent is explicit,
|
|
111
|
+
* so no confirmation prompt is shown). Cancel throws DIALOG_CANCELED.
|
|
112
|
+
*/
|
|
113
|
+
'dialog.showSaveDialog'(options: DialogShowSaveOptions): Promise<DialogShowSaveResult>;
|
|
114
|
+
};
|