@morlay/zephyr-desktop-shell 0.0.0-stage → 0.2.0-alpha.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.
@@ -0,0 +1,396 @@
1
+ import { CliModeValues, ZephyrDesktopConfig } from "@morlay/zephyr-cli";
2
+ /** 窗口矩形(Electron `Rectangle` 的子集)。 */
3
+ interface WindowBounds {
4
+ readonly x: number;
5
+ readonly y: number;
6
+ readonly width: number;
7
+ readonly height: number;
8
+ }
9
+ /** 显示器可用区域(Electron 的 `workArea`:已扣掉菜单栏 / 任务栏)。 */
10
+ type WorkArea = WindowBounds;
11
+ /** 一次启动要恢复的状态。 */
12
+ interface WindowState {
13
+ readonly bounds: WindowBounds;
14
+ readonly maximized: boolean;
15
+ }
16
+ /** 状态文件名(在 `userData` 下)。 */
17
+ export declare const WINDOW_STATE_FILE = "window-state.json";
18
+ /**
19
+ * 从存档与当前显示器算出这次要用的窗口状态。
20
+ *
21
+ * 存档是**外部输入**(上一个版本的进程写的文件),形状不可信:坏掉就当没有存档。
22
+ * @param saved - 存档内容(`loadWindowState` 的原样返回,或 `undefined`)。
23
+ * @param workArea - 主显示器的可用区域。
24
+ * @param fallback - 配置给的初始尺寸(第一次启动用)。
25
+ * @returns 已夹进工作区的状态。
26
+ */
27
+ export declare function windowStateOf(saved: unknown, workArea: WorkArea, fallback: {
28
+ readonly width: number;
29
+ readonly height: number;
30
+ }): WindowState;
31
+ /**
32
+ * 读 `userData` 里的存档(原样返回:形状由 {@link windowStateOf} 判)。
33
+ * @param userData - `userData` 目录。
34
+ * @returns 解析后的 JSON,或 `undefined`(没有文件 / 不是 JSON)。
35
+ */
36
+ export declare function loadWindowState(userData: string): Promise<unknown>;
37
+ /**
38
+ * 写回存档(写不了就算了:下次启动回到配置尺寸,不是功能故障)。
39
+ * @param userData - `userData` 目录。
40
+ * @param state - 关窗时的状态。
41
+ * @returns 写完成。
42
+ */
43
+ export declare function saveWindowState(userData: string, state: WindowState): Promise<void>;
44
+ /** 窗口外观(与平台相关的那几项)。 */
45
+ interface WindowFrame {
46
+ /** macOS:无标题栏但保留红绿灯按钮。 */
47
+ readonly titleBarStyle?: "hidden" | "hiddenInset" | "default";
48
+ readonly trafficLightPosition?: {
49
+ readonly x: number;
50
+ readonly y: number;
51
+ };
52
+ readonly vibrancy?: "sidebar" | "under-window";
53
+ readonly visualEffectState?: "active" | "followWindow";
54
+ /** Windows / Linux:去掉系统边框,用 overlay 留出系统按钮的位置。 */
55
+ readonly frame?: boolean;
56
+ readonly titleBarOverlay?: {
57
+ readonly color: string;
58
+ readonly symbolColor: string;
59
+ readonly height: number;
60
+ };
61
+ readonly backgroundColor: string;
62
+ }
63
+ /** 窗口选项(Electron `BrowserWindow` 用的那个子集)。 */
64
+ interface WindowOptions extends WindowFrame {
65
+ /** 位置只在「上次关窗的位置」存在时给(否则让 Electron 自己居中)。 */
66
+ readonly x?: number;
67
+ readonly y?: number;
68
+ readonly width: number;
69
+ readonly height: number;
70
+ readonly minWidth: number;
71
+ readonly minHeight: number;
72
+ readonly show: boolean;
73
+ readonly webPreferences: {
74
+ readonly contextIsolation: boolean;
75
+ readonly nodeIntegration: boolean;
76
+ readonly sandbox: boolean;
77
+ /** 只有桌面形态才有的桥(目录选择器、平台标记)。 */
78
+ readonly preload?: string;
79
+ };
80
+ }
81
+ /** 缺省尺寸:够放下侧栏与一栏对话(也是第一次启动的尺寸)。 */
82
+ export declare const DEFAULT_WINDOW_SIZE: {
83
+ readonly width: 1280;
84
+ readonly height: 800;
85
+ };
86
+ /** 开窗时传进来的那两样(都不是配置:一个来自构建产物,一个来自上次关窗)。 */
87
+ interface WindowSizing {
88
+ /** preload 脚本绝对路径(桌面桥)。 */
89
+ readonly preload?: string;
90
+ /** 上次关窗时的状态(位置、尺寸、最大化)。 */
91
+ readonly state?: WindowState;
92
+ }
93
+ /**
94
+ * 按平台给窗口外观:**无标题栏**,窗口内容顶到顶边。
95
+ *
96
+ * macOS 保留红绿灯(`hiddenInset` + 指定内缩),左侧栏因此要给顶部留白(页面侧按
97
+ * `document.documentElement.dataset.titlebar` 折叠);Windows 用 `titleBarOverlay`。
98
+ * @param platform - 平台(注入以便测三个平台)。
99
+ * @returns 外观选项。
100
+ */
101
+ export declare function windowFrameOf(platform: NodeJS.Platform): WindowFrame;
102
+ /**
103
+ * 从配置与上次关窗的状态推导窗口选项。
104
+ *
105
+ * `nodeIntegration: false` + `contextIsolation: true` 不是保守,是**必须**:页面来自 dev server
106
+ * (打包形态也走它),内容里跑的是客户端的整棵 React 树,给渲染进程 node 权限等于把宿主的文件系统交出去。
107
+ * @param desktop - 配置里的 `desktop` 段(可能没有 `window`)。
108
+ * @param platform - 平台(注入以便测三个平台)。
109
+ * @param sizing - preload 路径与上次关窗的状态。
110
+ * @returns 窗口选项。
111
+ */
112
+ export declare function windowOptionsOf(desktop: ZephyrDesktopConfig | undefined, platform?: NodeJS.Platform, sizing?: WindowSizing): WindowOptions;
113
+ /** 菜单项(Electron `MenuItemConstructorOptions` 的子集)。 */
114
+ interface MenuItemSpec {
115
+ readonly role?: string;
116
+ /** 顶层菜单的标题(与 macOS 的应用菜单名)。 */
117
+ readonly label?: string;
118
+ readonly type?: "separator" | "checkbox";
119
+ /** 勾选(`type: "checkbox"` 才有意义)。 */
120
+ readonly checked?: boolean;
121
+ /** 能不能点(打不开的 Inspector 项标灰,不弹窗)。 */
122
+ readonly enabled?: boolean;
123
+ /** 快捷键(Electron 的写法:`CmdOrCtrl` 在 mac 是 ⌘、其它平台是 Ctrl)。 */
124
+ readonly accelerator?: string;
125
+ readonly click?: () => void;
126
+ readonly submenu?: readonly MenuItemSpec[];
127
+ }
128
+ /** 主进程 Inspector 在菜单里的样子(由 `InspectorPort` 的读数给出)。 */
129
+ interface InspectorMenuState {
130
+ /** 开着没有(决定勾选)。 */
131
+ readonly opened: boolean;
132
+ /** 地址(开着时才有:复制项要用它)。 */
133
+ readonly address?: string;
134
+ /** 曾经打不开(端口全占):两项标灰,等下一次切换再试。 */
135
+ readonly failed?: boolean;
136
+ }
137
+ /** 自造项的点击回调(纯函数只画菜单,动作由装配方注入)。 */
138
+ interface MenuActions {
139
+ /** 「开发者模式」:切一次并持久化。 */
140
+ readonly toggleDevMode: () => void;
141
+ /** 「打开主进程 Inspector」:开或关。 */
142
+ readonly toggleInspector: () => void;
143
+ /** 「复制 Inspector 地址」:把地址放进剪贴板。 */
144
+ readonly copyInspectorAddress: () => void;
145
+ }
146
+ /** 造菜单要的部署值。 */
147
+ interface MenuTemplateInput {
148
+ /** 平台(注入以便测三个平台)。 */
149
+ readonly platform: NodeJS.Platform;
150
+ /** 应用名(macOS 应用菜单的标题)。 */
151
+ readonly appName: string;
152
+ /** 开发者模式:关着时视图菜单只有「开发者模式」一项(无 Reload / DevTools / Inspector)。 */
153
+ readonly debug: boolean;
154
+ /** 主进程 Inspector 的状态(缺省当作关着:没接适配器时也画得出菜单)。 */
155
+ readonly inspector?: InspectorMenuState;
156
+ /** 点击回调(缺省时这些项仍在,只是不挂动作——便于测试断言)。 */
157
+ readonly on?: MenuActions;
158
+ }
159
+ /**
160
+ * 按平台、开发者模式与 Inspector 状态给出菜单模板。
161
+ * @param input - 平台、应用名、开发者模式、Inspector 状态与点击回调。
162
+ * @returns 顶层菜单项(可直接交给 `Menu.buildFromTemplate`)。
163
+ */
164
+ export declare function menuTemplateOf(input: MenuTemplateInput): readonly MenuItemSpec[];
165
+ /** 一次导航该怎么做。 */
166
+ type NavigationPlan = {
167
+ readonly kind: "allow";
168
+ } | {
169
+ readonly kind: "external";
170
+ readonly url: string;
171
+ } | {
172
+ readonly kind: "deny";
173
+ };
174
+ /**
175
+ * 判一次跳转。
176
+ * @param target - 目标 URL(可以是相对路径)。
177
+ * @param origin - 页面自己的源(`http://127.0.0.1:<port>`)。
178
+ * @returns 处理方式。
179
+ */
180
+ export declare function navigationPlanOf(target: string, origin: string): NavigationPlan;
181
+ /** 能被聚焦的窗口(Electron `BrowserWindow` 的子集)。 */
182
+ interface FocusTarget {
183
+ isDestroyed(): boolean;
184
+ isMinimized(): boolean;
185
+ restore(): void;
186
+ show(): void;
187
+ focus(): void;
188
+ }
189
+ /** 聚焦结果:`none` 表示没有可用窗口(第二个实例照样退出)。 */
190
+ type FocusOutcome = "focused" | "none";
191
+ /**
192
+ * 把已有窗口抬到前台(最小化时先恢复——`focus()` 对最小化窗口无效)。
193
+ * @param target - 当前窗口。
194
+ * @returns 是否聚焦到了一个活着的窗口。
195
+ */
196
+ export declare function focusWindowOf(target: FocusTarget | undefined): FocusOutcome;
197
+ /** 调试面的来源:只读 `enabled`(`DevMode` 结构上就是它,这里不引入依赖方向)。 */
198
+ interface ShellDebugSource {
199
+ /** 此刻要不要吵。 */
200
+ readonly enabled: boolean;
201
+ }
202
+ /** 壳的调试面。 */
203
+ interface ShellDebug {
204
+ /** 是否打开调试面:渲染进程 console 转发 + DevTools + 生命周期日志。 */
205
+ readonly enabled: boolean;
206
+ /**
207
+ * 打一条壳自己的日志(`[shell]` 前缀,stderr)。
208
+ * @param message - 文本。
209
+ */
210
+ log(message: string): void;
211
+ /**
212
+ * 打一条**始终可见**的错误(不受 `enabled` 控制:错误不该被开关吞掉)。
213
+ * @param message - 文本。
214
+ */
215
+ fail(message: string): void;
216
+ /**
217
+ * 转发一条渲染进程的 console。
218
+ * @param message - 文本。
219
+ */
220
+ renderer(message: string): void;
221
+ }
222
+ /**
223
+ * 造调试面:只读投影,不持有状态。
224
+ * @param source - 开发者模式(读它的 `enabled`)。
225
+ * @returns 调试面。
226
+ */
227
+ export declare function shellDebugOf(source: ShellDebugSource): ShellDebug;
228
+ /** 一行的输入。 */
229
+ interface DeploymentLineInput {
230
+ /** 壳的形态(`ZEPHYR_DESKTOP_MODE` 的判定结果)。 */
231
+ readonly form: "dev" | "packaged";
232
+ /** 交给应用的部署值(`shellMode()` 的结果)。 */
233
+ readonly mode: CliModeValues;
234
+ /** Electron 的 `app.getPath("userData")`;拿不到就是 `undefined`。 */
235
+ readonly userData: string | undefined;
236
+ /** 是否 `ZEPHYR_DESKTOP_PACKAGED=1`(同进程的宿主据此清空 `dev.include`)。 */
237
+ readonly packaged: boolean;
238
+ }
239
+ /**
240
+ * 拼启动那一行(字段顺序固定:mode / workspace / profileDir / dataDir / dataDirSpec / userData / packaged)。
241
+ * @param input - 形态、部署值与 userData。
242
+ * @returns 一行的文本(含 `[desktop-shell]` 前缀,不换行)。
243
+ */
244
+ export declare function deploymentLineOf(input: DeploymentLineInput): string;
245
+ /** 面板在窗口坐标系里占的矩形(页面侧算,主进程只照着摆)。 */
246
+ interface PaneRect {
247
+ readonly x: number;
248
+ readonly y: number;
249
+ readonly width: number;
250
+ readonly height: number;
251
+ }
252
+ /** 面板 view 的 `webPreferences`(壳只给这几项,且**没有** preload)。 */
253
+ interface BrowserPaneWebPreferences {
254
+ readonly partition: string;
255
+ readonly sandbox: boolean;
256
+ readonly contextIsolation: boolean;
257
+ readonly nodeIntegration: boolean;
258
+ }
259
+ /** 面板 view 的 webContents(壳只用到这些成员)。 */
260
+ interface BrowserPaneWebContentsLike {
261
+ loadURL(url: string): Promise<void>;
262
+ close(): void;
263
+ isDestroyed(): boolean;
264
+ getURL(): string;
265
+ getTitle(): string;
266
+ canGoBack(): boolean;
267
+ canGoForward(): boolean;
268
+ isLoading(): boolean;
269
+ on(event: string, listener: (...args: never[]) => void): void;
270
+ setWindowOpenHandler(handler: (details: {
271
+ readonly url: string;
272
+ }) => {
273
+ readonly action: string;
274
+ }): void;
275
+ }
276
+ /** 一个面板 view(Electron `WebContentsView` 的子集)。 */
277
+ interface BrowserPaneViewLike {
278
+ readonly webContents: BrowserPaneWebContentsLike;
279
+ setBounds(bounds: PaneRect): void;
280
+ }
281
+ /** 分区上的两个权限钩子(下载另走 `will-download`)。 */
282
+ interface BrowserPaneSessionLike {
283
+ setPermissionRequestHandler(handler: (contents: unknown, permission: string, callback: (granted: boolean) => void) => void): void;
284
+ setPermissionCheckHandler(handler: (contents: unknown, permission: string, origin: string) => boolean): void;
285
+ on(event: string, listener: (...args: never[]) => void): void;
286
+ }
287
+ /** 一个窗口(`BrowserWindow` 的子集)。 */
288
+ interface ElectronWindow {
289
+ loadURL(url: string): Promise<void>;
290
+ once(event: string, listener: () => void): void;
291
+ on(event: string, listener: (...args: never[]) => void): void;
292
+ show(): void;
293
+ close(): void;
294
+ focus(): void;
295
+ restore(): void;
296
+ maximize(): void;
297
+ isDestroyed(): boolean;
298
+ isMinimized(): boolean;
299
+ isMaximized(): boolean;
300
+ isFocused(): boolean;
301
+ isEnabled(): boolean;
302
+ /** 最大化之前的矩形(关窗时存它,下次才能回到用户拖动出来的尺寸)。 */
303
+ getNormalBounds(): WindowBounds;
304
+ /** 这个 webContents id 是不是本窗口的(IPC 的准入判据)。 */
305
+ owns(senderId: number): boolean;
306
+ /** 窗口的内容层:内嵌浏览器面板的 view 挂在这里(子 view 列表)。 */
307
+ readonly contentView: {
308
+ addChildView(view: unknown): void;
309
+ removeChildView(view: unknown): void;
310
+ };
311
+ readonly webContents: ElectronWebContents;
312
+ }
313
+ /** `ipcMain.handle` 的事件面:`IpcMainInvokeEvent` 的子集(发起方是 `sender`,不是 `senderId`)。 */
314
+ interface ElectronInvokeEvent {
315
+ readonly sender: {
316
+ readonly id: number;
317
+ };
318
+ }
319
+ /** 窗口里的渲染进程(壳只用到这几处)。 */
320
+ interface ElectronWebContents {
321
+ readonly id: number;
322
+ on(event: string, listener: (...args: never[]) => void): void;
323
+ openDevTools(options?: {
324
+ mode?: string;
325
+ }): void;
326
+ send(channel: string, ...args: unknown[]): void;
327
+ /** 录制快捷键时把菜单快捷键让给页面。 */
328
+ setIgnoreMenuShortcuts(ignore: boolean): void;
329
+ /** 页面要开新窗口时的裁决(壳一律拒:桌面形态只有一扇窗)。 */
330
+ setWindowOpenHandler(handler: (details: {
331
+ readonly url: string;
332
+ }) => {
333
+ readonly action: string;
334
+ }): void;
335
+ }
336
+ /** Electron 模块的最小面。 */
337
+ interface ElectronLike {
338
+ readonly app: {
339
+ whenReady(): Promise<void>;
340
+ on(event: string, listener: (...args: never[]) => void): void;
341
+ quit(): void;
342
+ /** 单实例锁:拿不到就说明已经有同名 userData 的实例在跑。 */
343
+ requestSingleInstanceLock(): boolean;
344
+ commandLine: {
345
+ appendSwitch(name: string, value?: string): void;
346
+ };
347
+ setPath(name: string, path: string): void;
348
+ getPath(name: string): string;
349
+ /** 应用名(`package.json` 的 `name`):没有 `desktop.id` 时用它当数据目录名。 */
350
+ getName(): string;
351
+ disableHardwareAcceleration(): void;
352
+ };
353
+ readonly BrowserWindow: new (options: unknown) => ElectronWindow;
354
+ /** 内嵌浏览器面板:主进程创建的网页容器(适配器在 `browser-pane-view.ts`)。 */
355
+ readonly WebContentsView: new (options: {
356
+ readonly webPreferences: BrowserPaneWebPreferences;
357
+ }) => BrowserPaneViewLike;
358
+ /** session 分区:面板与主页面不同分区(cookie / storage 互不可见)。 */
359
+ readonly session: {
360
+ fromPartition(partition: string): BrowserPaneSessionLike;
361
+ };
362
+ readonly dialog: {
363
+ showOpenDialog(window: unknown, options: unknown): Promise<{
364
+ readonly canceled: boolean;
365
+ readonly filePaths: readonly string[];
366
+ }>;
367
+ };
368
+ readonly ipcMain: {
369
+ /**
370
+ * 渲染进程的 invoke:发起方在 `event.sender`(`WebContents`)上,**没有 `senderId`**
371
+ * (`IpcMainInvokeEvent` 的字段是 `frameId` / `processId` / `sender` / `senderFrame`),
372
+ * 所以准入判据读 `event.sender.id`。
373
+ */
374
+ handle(channel: string, listener: (event: ElectronInvokeEvent, ...args: unknown[]) => Promise<unknown>): void;
375
+ };
376
+ /** 显示器:只用主屏的可用区域(窗口状态要在启动时夹回可见范围)。 */
377
+ readonly screen: {
378
+ getPrimaryDisplay(): {
379
+ readonly workArea: WorkArea;
380
+ };
381
+ };
382
+ /** 应用菜单(产品菜单模板在 `menu.ts`)。 */
383
+ readonly Menu: {
384
+ buildFromTemplate(template: readonly unknown[]): unknown;
385
+ setApplicationMenu(menu: unknown): void;
386
+ };
387
+ /** 剪贴板:菜单里「复制 Inspector 地址」用(地址要能粘进 Chrome DevTools)。 */
388
+ readonly clipboard: {
389
+ writeText(text: string): void;
390
+ };
391
+ /** 系统外壳:外部链接交给系统浏览器,不在应用内开无策略的窗口。 */
392
+ readonly shell: {
393
+ openExternal(url: string): Promise<void>;
394
+ };
395
+ }
396
+ export type { DeploymentLineInput, ElectronLike, ElectronWebContents, ElectronWindow, FocusOutcome, FocusTarget, MenuItemSpec, MenuTemplateInput, NavigationPlan, ShellDebug, WindowBounds, WindowFrame, WindowOptions, WindowSizing, WindowState, WorkArea };
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ export { u as DEFAULT_WINDOW_SIZE, o as WINDOW_STATE_FILE, t as deploymentLineOf, r as focusWindowOf, s as loadWindowState, a as menuTemplateOf, i as navigationPlanOf, c as saveWindowState, n as shellDebugOf, d as windowFrameOf, f as windowOptionsOf, l as windowStateOf } from "./deployment-line-Dd1AIkCI.mjs";
@@ -0,0 +1,27 @@
1
+ // src/ipc.ts
2
+ const DESKTOP_IPC = {
3
+ /** 渲染进程请求一个原生目录选择框;返回绝对路径或 `null`。 */
4
+ directoryPick: "dsh-desktop:directory-pick",
5
+ /** 快捷键配置的读写(渲染进程 → 主进程)。 */
6
+ shortcutsGet: "dsh-desktop:shortcuts-get",
7
+ shortcutsEdit: "dsh-desktop:shortcuts-edit",
8
+ shortcutsRecording: "dsh-desktop:shortcuts-recording",
9
+ /** 配置快照变化(主进程 → 渲染进程)。 */
10
+ shortcutsChanged: "dsh-desktop:shortcuts-changed",
11
+ /** 命中的原生按键手势(主进程 → 渲染进程)。 */
12
+ shortcutsInput: "dsh-desktop:shortcuts-input",
13
+ /** 按当前配置关窗(渲染进程 → 主进程)。 */
14
+ shortcutsCloseWindow: "dsh-desktop:shortcuts-close-window",
15
+ /** 内嵌浏览器面板(渲染进程 → 主进程):开 / 摆位置 / 导航 / 关 / 读状态。 */
16
+ browserOpen: "dsh-desktop:browser-open",
17
+ browserBounds: "dsh-desktop:browser-bounds",
18
+ browserNavigate: "dsh-desktop:browser-navigate",
19
+ browserClose: "dsh-desktop:browser-close",
20
+ browserState: "dsh-desktop:browser-state",
21
+ /** 面板状态(主进程 → 渲染进程):url / title / canGoBack / loading 只有这一条来源。 */
22
+ browserChanged: "dsh-desktop:browser-changed",
23
+ /** 存储代理的全量读 / 单条写(渲染进程 → 主进程):真源在主进程,见 `storage.ts`。 */
24
+ storageRead: "dsh-desktop:storage-read",
25
+ storageWrite: "dsh-desktop:storage-write"
26
+ };
27
+ export { DESKTOP_IPC as t };
@@ -0,0 +1 @@
1
+ export {}
package/dist/main.mjs ADDED
@@ -0,0 +1,14 @@
1
+ import { n as reportFailure } from "./failure-Dapchl7c.mjs";
2
+ // src/main.ts
3
+ const loaderPackage = "@morlay/dsh-oxc-node";
4
+ await import(loaderPackage).catch(async (error) => {
5
+ await reportFailure("引导(挂 TS 运行时)", error);
6
+ throw error;
7
+ });
8
+ process.env.DSH_SOURCE_LOADER ??= import.meta.resolve(loaderPackage);
9
+ process.env.DSH_PTC_ELECTRON_RUN_AS_NODE ??= "1";
10
+ await import("./app-BCTAe0Ae.mjs").catch(async (error) => {
11
+ await reportFailure("加载入口", error);
12
+ throw error;
13
+ });
14
+ export {};
@@ -0,0 +1 @@
1
+ export {}
@@ -0,0 +1,94 @@
1
+ import { contextBridge, ipcRenderer } from "electron";
2
+ import { t as DESKTOP_IPC } from "./ipc-9pZ8Xo6_.mjs";
3
+ // src/browser-pane-bridge.ts
4
+ /**
5
+ * 造桥。
6
+ * @param ipc - `ipcRenderer`(`invoke` / `on` / `off`)。
7
+ * @returns 只转发的桥。
8
+ */
9
+ function browserPaneBridgeOf(ipc) {
10
+ return {
11
+ open: async (input) => ipc.invoke(DESKTOP_IPC.browserOpen, input),
12
+ bounds: async (id, bounds) => ipc.invoke(DESKTOP_IPC.browserBounds, id, bounds),
13
+ navigate: async (id, url) => ipc.invoke(DESKTOP_IPC.browserNavigate, id, url),
14
+ close: async (id) => ipc.invoke(DESKTOP_IPC.browserClose, id),
15
+ state: async (id) => ipc.invoke(DESKTOP_IPC.browserState, id),
16
+ subscribe: (listener) => {
17
+ const handler = (...args) => listener(args[1]);
18
+ ipc.on(DESKTOP_IPC.browserChanged, handler);
19
+ return () => {
20
+ ipc.off(DESKTOP_IPC.browserChanged, handler);
21
+ };
22
+ }
23
+ };
24
+ }
25
+ // src/document-marks.ts
26
+ /**
27
+ * 把平台与标题栏形态标到 `<html data-*>` 上。
28
+ * @param target - 文档(测试可注入)。
29
+ * @param platform - 平台。
30
+ * @param titlebar - 标题栏形态(缺省 `hidden`:桌面窗口都是无标题栏的)。
31
+ */
32
+ function markDocument(target, platform, titlebar = "hidden") {
33
+ const root = target?.documentElement;
34
+ if (root === void 0) return;
35
+ root.dataset["platform"] = platform;
36
+ root.dataset["titlebar"] = titlebar;
37
+ }
38
+ // src/storage-bridge.ts
39
+ /**
40
+ * 造桥。
41
+ * @param ipc - `ipcRenderer`(只用 `invoke`)。
42
+ * @returns 只转发的桥。
43
+ */
44
+ function storageBridgeOf(ipc) {
45
+ return {
46
+ read: async (store) => stringEntriesOf(await ipc.invoke(DESKTOP_IPC.storageRead, store)),
47
+ write: async (store, key, value) => {
48
+ await ipc.invoke(DESKTOP_IPC.storageWrite, store, key, value);
49
+ }
50
+ };
51
+ }
52
+ /**
53
+ * 过桥的东西不可信:不是字符串表就当空(读不到 = 空表,与 `StorageBackend.read` 的契约一致)。
54
+ * @param value - `invoke` 的返回。
55
+ * @returns 键值表。
56
+ */
57
+ function stringEntriesOf(value) {
58
+ if (typeof value !== "object" || value === null) return {};
59
+ return Object.fromEntries(Object.entries(value).filter(([, entry]) => typeof entry === "string"));
60
+ }
61
+ // src/preload.ts
62
+ contextBridge.exposeInMainWorld("__DSH_DIRECTORY_PICKER__", { pick: () => ipcRenderer.invoke(DESKTOP_IPC.directoryPick) });
63
+ contextBridge.exposeInMainWorld("__DSH_BROWSER_PANE__", browserPaneBridgeOf(ipcRenderer));
64
+ contextBridge.exposeInMainWorld("__DSH_STORAGE__", storageBridgeOf(ipcRenderer));
65
+ contextBridge.exposeInMainWorld("dshDesktop", {
66
+ protocolVersion: 1,
67
+ shortcuts: {
68
+ get: (definitions) => ipcRenderer.invoke(DESKTOP_IPC.shortcutsGet, definitions),
69
+ edit: (edit, revision) => ipcRenderer.invoke(DESKTOP_IPC.shortcutsEdit, edit, revision),
70
+ recording: (active) => ipcRenderer.invoke(DESKTOP_IPC.shortcutsRecording, active),
71
+ subscribe: (listener) => {
72
+ const handler = (_event, snapshot) => listener(snapshot);
73
+ ipcRenderer.on(DESKTOP_IPC.shortcutsChanged, handler);
74
+ return () => {
75
+ ipcRenderer.off(DESKTOP_IPC.shortcutsChanged, handler);
76
+ };
77
+ }
78
+ },
79
+ keyboard: {
80
+ subscribe: (listener) => {
81
+ const handler = (_event, input) => listener(input);
82
+ ipcRenderer.on(DESKTOP_IPC.shortcutsInput, handler);
83
+ return () => {
84
+ ipcRenderer.off(DESKTOP_IPC.shortcutsInput, handler);
85
+ };
86
+ },
87
+ closeWindow: (revision) => ipcRenderer.invoke(DESKTOP_IPC.shortcutsCloseWindow, revision)
88
+ }
89
+ });
90
+ if (typeof document !== "undefined") {
91
+ if (document.documentElement !== null) markDocument(document, process.platform);
92
+ else document.addEventListener("DOMContentLoaded", () => markDocument(document, process.platform));
93
+ }
94
+ export {};
@@ -0,0 +1,38 @@
1
+ /**
2
+ * 两个 store 的名字(`local` / `session` 语义)。
3
+ *
4
+ * 住在通道名旁边:它是**过桥的词汇**,主进程、preload 桥与页面侧后端三处都按这一份认。
5
+ * 与 `@morlay/zephyr-app` 的 `StorageStore` 同形——那边是消费方(壳不进浏览器框架的模块图),
6
+ * 两边一旦漂了,装配处的赋值检查会红。
7
+ */
8
+ type StorageStore = "local" | "session";
9
+ /** 暴露成 `window.__DSH_STORAGE__` 的那张面。 */
10
+ interface StorageBridge {
11
+ /**
12
+ * 全量读一个 store。
13
+ * @param store - store 名。
14
+ * @returns 键值表(普通对象过桥:与落盘文件同一形状)。
15
+ */
16
+ read(store: StorageStore): Promise<Record<string, string>>;
17
+ /**
18
+ * 写一条(`null` 为删除)。主进程收到就改内存、落盘去抖,所以**调用方不必等它**。
19
+ * @param store - store 名。
20
+ * @param key - 键。
21
+ * @param value - 值;`null` 为删除。
22
+ */
23
+ write(store: StorageStore, key: string, value: string | null): Promise<void>;
24
+ }
25
+ /** 本文件只看宿主上的这一个属性(不引 DOM lib:壳的 tsconfig 只带 node 的类型面)。 */
26
+ export interface DesktopStorageHost {
27
+ readonly __DSH_STORAGE__?: StorageBridge;
28
+ }
29
+ /**
30
+ * 主进程后端(给 `installStorageShim()` 当参数)。
31
+ * @param host - 取桥的宿主;缺省 `globalThis`(preload 把它 expose 在页面上)。
32
+ * @returns 后端;**没有桥时 `read` 会拒**,`installStorageShim` 据此返回 `installed: false` 并回落原生。
33
+ */
34
+ export declare function desktopStorageBackend(host?: DesktopStorageHost): {
35
+ read(store: StorageStore): Promise<Map<string, string>>;
36
+ write(store: StorageStore, key: string, value: string | null): void;
37
+ };
38
+ export {};
@@ -0,0 +1,22 @@
1
+ // src/storage-backend.ts
2
+ /**
3
+ * 主进程后端(给 `installStorageShim()` 当参数)。
4
+ * @param host - 取桥的宿主;缺省 `globalThis`(preload 把它 expose 在页面上)。
5
+ * @returns 后端;**没有桥时 `read` 会拒**,`installStorageShim` 据此返回 `installed: false` 并回落原生。
6
+ */
7
+ function desktopStorageBackend(host = globalThis) {
8
+ const bridge = () => {
9
+ const found = host.__DSH_STORAGE__;
10
+ if (found === void 0) throw new Error("[dsh] 没有 __DSH_STORAGE__:这不是桌面壳的页面");
11
+ return found;
12
+ };
13
+ return {
14
+ read: async (store) => new Map(Object.entries(await bridge().read(store))),
15
+ write: (store, key, value) => {
16
+ bridge().write(store, key, value).catch((error) => {
17
+ console.error(`[dsh] storage 写入没送到主进程(${store}/${key}):`, error);
18
+ });
19
+ }
20
+ };
21
+ }
22
+ export { desktopStorageBackend };
package/package.json CHANGED
@@ -1,6 +1,66 @@
1
1
  {
2
2
  "name": "@morlay/zephyr-desktop-shell",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.0-alpha.0",
4
+ "description": "zephyr 桌面应用的 Electron 壳:窗口与状态、产品菜单、单实例、导航判据、preload 桥与生命周期都在一个进程里;由 @morlay/zephyr-desktop-bundle 打进应用目录。",
5
+ "keywords": [
6
+ "desktop",
7
+ "dsh",
8
+ "dsh-plugin",
9
+ "electron",
10
+ "zephyr"
11
+ ],
12
+ "license": "MIT",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/morlay/zephyr.git",
16
+ "directory": "packages/zephyr-desktop/zephyr-desktop-shell"
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "src",
21
+ "!**/__tests__"
22
+ ],
23
+ "type": "module",
24
+ "main": "./dist/main.mjs",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.mts",
28
+ "default": "./dist/index.mjs"
29
+ },
30
+ "./main": {
31
+ "types": "./dist/main.d.mts",
32
+ "default": "./dist/main.mjs"
33
+ },
34
+ "./preload": {
35
+ "types": "./dist/preload.d.mts",
36
+ "default": "./dist/preload.mjs"
37
+ },
38
+ "./storage-backend": {
39
+ "types": "./dist/storage-backend.d.mts",
40
+ "default": "./dist/storage-backend.mjs"
41
+ },
42
+ "./package.json": "./package.json"
43
+ },
44
+ "dependencies": {
45
+ "@morlay/dsh-oxc-node": "^0.2.14-alpha.0",
46
+ "@morlay/zephyr": "^0.2.0-alpha.0"
47
+ },
48
+ "devDependencies": {
49
+ "@morlay/zephyr-cli": "^0.2.0-alpha.0",
50
+ "@types/node": "^26.5.0"
51
+ },
52
+ "peerDependencies": {
53
+ "@deepseek-ai/dsh-client-shortcuts": "^0.2.3-alpha.3",
54
+ "electron": ">=45.5.0"
55
+ },
56
+ "peerDependenciesMeta": {
57
+ "electron": {
58
+ "optional": true
59
+ }
60
+ },
61
+ "engines": {
62
+ "dsh": ">= 0.2.3-alpha.3 < 0.2.4",
63
+ "node": ">=24.11.0"
64
+ },
65
+ "scripts": {}
6
66
  }