1+
2+ import type { IpcMainInvokeEvent , IpcRendererEvent , MessageBoxOptions , MessageBoxReturnValue , PrinterInfo , WebContentsPrintOptions } from "electron"
3+ import { ProgressInfo } from "electron-updater" ;
4+
5+
6+ type IpcMainEventListener < Send = void , Receive = void > = {
7+ ipcMainHandle : ( event : IpcMainInvokeEvent , args : Send ) => Receive | Promise < Receive > ;
8+ ipcRendererInvoke : ( args : Send ) => Promise < Receive > ;
9+ }
10+
11+ type IpcRendererEventListener < Send = void > = {
12+ ipcRendererOn : ( event : IpcRendererEvent , args ?: Send ) => void ;
13+ webContentSend : ( args : Send ) => void ;
14+ }
15+
16+ export const enum IpcChannel {
17+
18+ /**
19+ * 是否使用无边框
20+ */
21+ IsUseSysTitle = "IsUseSysTitle" ,
22+
23+ /**
24+ * 窗口最小化
25+ */
26+ WindowMini = "windows-mini" ,
27+
28+ /**
29+ * 窗口最大化
30+ */
31+ WindowMax = "window-max" ,
32+
33+ /**
34+ * 窗口关闭
35+ */
36+ WindowClose = "window-close" ,
37+
38+ /**
39+ * 检查更新
40+ */
41+ CheckUpdate = "check-update" ,
42+
43+ /**
44+ * 确认更新
45+ */
46+ ConfirmUpdate = "confirm-update" ,
47+
48+ /**
49+ * app退出
50+ */
51+ AppClose = "app-close" ,
52+
53+ /**
54+ * 获取静态资源路径
55+ */
56+ GetStaticPath = "get-static-path" ,
57+
58+ /**
59+ * 打开系统弹窗信息
60+ */
61+ OpenMessagebox = "open-messagebox" ,
62+
63+ /**
64+ * 打开系统错误弹窗信息
65+ */
66+ OpenErrorbox = "open-errorbox" ,
67+
68+ /**
69+ * 开启http服务
70+ */
71+ StartServer = "start-server" ,
72+
73+ /**
74+ * 停止http服务
75+ */
76+ StopServer = "stop-server" ,
77+
78+ /**
79+ * 增量更新
80+ */
81+ HotUpdate = "hot-update" ,
82+
83+ /**
84+ * 增量更新2
85+ */
86+ HotUpdateTest = "hot-update-test" ,
87+
88+ /**
89+ * 下载东西
90+ */
91+ StartDownload = "start-download" ,
92+
93+ /**
94+ * 打开新的弹窗
95+ */
96+ OpenWin = "open-win" ,
97+
98+
99+ /**
100+ * 获取打印机信息
101+ */
102+ GetPrinters = "getPrinters" ,
103+
104+ /**
105+ * 打印
106+ */
107+ PrintHandlePrint = "printHandlePrint" ,
108+
109+ /**
110+ * 打开测试打印页面
111+ */
112+ OpenPrintDemoWindow = "openPrintDemoWindow" ,
113+
114+
115+
116+ /**
117+ * 下载进度回调
118+ */
119+ DownloadProgress = "download-progress" ,
120+
121+ /**
122+ * 下载错误回调
123+ */
124+ DownloadError = "download-error" ,
125+
126+ /**
127+ * 下载暂停回调
128+ */
129+ DownloadPaused = "download-paused" ,
130+
131+ /**
132+ * 下载完成回调
133+ */
134+ DownloadDone = "download-done" ,
135+
136+ UpdateMsg = "UpdateMsg" ,
137+
138+ /**
139+ * 热更新状态回调
140+ */
141+ HotUpdateStatus = "hot-update-status" ,
142+
143+ /**
144+ * 数据测试回调
145+ */
146+ SendDataTest = "send-data-test" ,
147+
148+ }
149+
150+
151+
152+
153+
154+ type IpcMainEvent = {
155+ [ IpcChannel . AppClose ] : IpcMainEventListener
156+ [ IpcChannel . CheckUpdate ] : IpcMainEventListener
157+ [ IpcChannel . ConfirmUpdate ] : IpcMainEventListener
158+ [ IpcChannel . GetStaticPath ] : IpcMainEventListener < void , string >
159+ [ IpcChannel . HotUpdate ] : IpcMainEventListener
160+ [ IpcChannel . HotUpdateTest ] : IpcMainEventListener
161+ [ IpcChannel . IsUseSysTitle ] : IpcMainEventListener < void , boolean >
162+ [ IpcChannel . OpenErrorbox ] : IpcMainEventListener < { title : string , message : string } , void >
163+ [ IpcChannel . OpenMessagebox ] : IpcMainEventListener < MessageBoxOptions , MessageBoxReturnValue >
164+ [ IpcChannel . OpenWin ] : IpcMainEventListener < {
165+
166+ /**
167+ * 新的窗口地址
168+ *
169+ * @type {string }
170+ */
171+ url : string ,
172+
173+ /**
174+ * 是否是支付页
175+ *
176+ * @type {boolean }
177+ */
178+ IsPay ?: boolean ,
179+
180+ /**
181+ * 支付参数
182+ *
183+ * @type {string }
184+ */
185+ PayUrl ?: string ,
186+
187+ /**
188+ * 发送的新页面数据
189+ *
190+ * @type {unknown }
191+ */
192+ sendData ?: unknown
193+ } , void >
194+ [ IpcChannel . StartDownload ] : IpcMainEventListener < string , void >
195+ [ IpcChannel . StartServer ] : IpcMainEventListener < void , string >
196+ [ IpcChannel . StopServer ] : IpcMainEventListener < void , string >
197+ [ IpcChannel . WindowClose ] : IpcMainEventListener
198+ [ IpcChannel . WindowMax ] : IpcMainEventListener < void , { status : boolean } >
199+ [ IpcChannel . WindowMini ] : IpcMainEventListener
200+ [ IpcChannel . GetPrinters ] : IpcMainEventListener < void , PrinterInfo [ ] >
201+ [ IpcChannel . PrintHandlePrint ] : IpcMainEventListener < WebContentsPrintOptions , { success : boolean , failureReason : string } >
202+ [ IpcChannel . OpenPrintDemoWindow ] : IpcMainEventListener
203+ }
204+ type IpcRenderderEvent = {
205+ [ IpcChannel . DownloadProgress ] : IpcRendererEventListener < number >
206+ [ IpcChannel . DownloadError ] : IpcRendererEventListener < boolean >
207+ [ IpcChannel . DownloadPaused ] : IpcRendererEventListener < boolean >
208+ [ IpcChannel . DownloadDone ] : IpcRendererEventListener < {
209+
210+ /**
211+ * 下载的文件路径
212+ *
213+ * @type {string }
214+ */
215+ filePath : string
216+ }
217+ >
218+ [ IpcChannel . UpdateMsg ] : IpcRendererEventListener < {
219+ state : number ;
220+ msg : string | ProgressInfo ;
221+ } >
222+ [ IpcChannel . HotUpdateStatus ] : IpcRendererEventListener < {
223+ status : "init" | "downloading" | "moving" | "finished" | "failed" | "download" ,
224+ message : string
225+ } >
226+
227+ [ IpcChannel . SendDataTest ] : IpcRendererEventListener < unknown >
228+
229+ }
230+
231+
232+
233+
234+ export type IpcMainHandle = {
235+ [ Key in keyof IpcMainEvent ] : IpcMainEvent [ Key ] [ "ipcMainHandle" ]
236+ }
237+
238+ export type IpcRendererInvoke = {
239+ [ Key in keyof IpcMainEvent ] : IpcMainEvent [ Key ] [ "ipcRendererInvoke" ]
240+ }
241+
242+ export type IpcRendererOn = {
243+ [ Key in keyof IpcRenderderEvent ] : IpcRenderderEvent [ Key ] [ "ipcRendererOn" ]
244+ }
245+
246+ export type WebContentSend = {
247+ [ Key in keyof IpcRenderderEvent ] : IpcRenderderEvent [ Key ] [ "webContentSend" ]
248+ }
0 commit comments