-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreload.cjs
More file actions
97 lines (86 loc) · 2.95 KB
/
preload.cjs
File metadata and controls
97 lines (86 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
const { contextBridge, ipcRenderer } = require('electron');
/**
* Subscribe to an IPC channel and return an unsubscribe function.
*
* @param {string} channel
* @param {(data:any) => void} handler
* @returns {() => void}
*/
function subscribe(channel, handler) {
const listener = (_evt, data) => handler(data);
ipcRenderer.on(channel, listener);
return () => ipcRenderer.removeListener(channel, listener);
}
/**
* TI: Rename Thermal Images API (window.ti)
*
* Channels used:
* - invoke: 'ti:run'
* - events: 'ti:log', 'ti:progress'
* - dialogs: 'choose:pdf', 'choose:dir'
*/
contextBridge.exposeInMainWorld('ti', {
/**
* Invoke the TI rename tool (dry-run or apply).
* @param {TiRunPayload} options
* @returns {Promise<{ok:boolean, code:number, error?:string}>}
*/
run: options => ipcRenderer.invoke('ti:run', options),
/**
* Subscribe to stdout/stderr log chunks from the child process.
* @param {(chunk:string) => void} handler
* @returns {() => void} unsubscribe
*/
onLog: handler => subscribe('ti:log', handler),
/**
* Subscribe to coarse progress updates (0–100).
* @param {(pct:number) => void} handler
* @returns {() => void} unsubscribe
*/
onProgress: handler => subscribe('ti:progress', handler),
/**
* Open native "choose PDF" dialog.
* @returns {Promise<string|null>} Absolute path or null if canceled.
*/
choosePdf: () => ipcRenderer.invoke('choose:pdf'),
/**
* Open native "choose directory" dialog.
* @returns {Promise<string|null>} Absolute path or null if canceled.
*/
chooseDir: () => ipcRenderer.invoke('choose:dir'),
});
/**
* Issues → Excel Extraction API (window.issues)
*
* Channels used:
* - invoke: 'issues:run'
* - events: 'issues:log', 'issues:progress'
* - (optional save dialog could be added as 'issues:chooseOut' if you wire it in main)
*/
contextBridge.exposeInMainWorld('issues', {
/**
* Run the Issues→Excel extractor (dry-run by default; pass apply:true to write).
* @param {IssuesRunPayload} options
* @returns {Promise<{ok:boolean, code:number, error?:string}>}
*/
run: options => ipcRenderer.invoke('issues:run', options),
/**
* Subscribe to stdout/stderr log chunks from the extractor.
* @param {(chunk:string) => void} handler
* @returns {() => void} unsubscribe
*/
onLog: handler => subscribe('issues:log', handler),
/**
* Subscribe to coarse progress updates (0–100).
* @param {(pct:number) => void} handler
* @returns {() => void} unsubscribe
*/
onProgress: handler => subscribe('issues:progress', handler),
/**
* Open native "choose directory" dialog.
* @returns {Promise<string|null>} Absolute path or null if canceled.
*/
choosePdf: () => ipcRenderer.invoke('choose:pdf'),
// If added a save dialog in main.js:
// chooseOut: () => ipcRenderer.invoke('issues:chooseOut'),
});