Repository navigation
Expand file tree
/
Copy pathpreload.js
More file actions
71 lines (63 loc) · 2.13 KB
/
Copy pathpreload.js
File metadata and controls
71 lines (63 loc) · 2.13 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
/**
* ==============================================================================
* PRELOAD SCRIPT
* ==============================================================================
*
* This script runs BEFORE the web page loads. It acts as a secure bridge
* between the "Backend" (Node.js/Electron) and the "Frontend" (React).
*
* Security Note: We do NOT expose the full Node.js API to the frontend.
* We only expose specific functions via 'window.lazyfish'.
*/
const { contextBridge, ipcRenderer } = require("electron")
contextBridge.exposeInMainWorld('lazyfish', {
/**
* Listen for new clipboard text from the backend.
*/
onClipboard: (callback) => {
// We wrap the callback to ensure we strip the 'event' object from Electron
// and only pass the data.
ipcRenderer.on("clipboard-update", (event, text) => callback(text))
},
/**
* Listen for AI suggestions from the backend.
*/
onAIResponse: (callback) => {
ipcRenderer.on("ai-response", (event, analysis) => callback(analysis))
},
/**
* Listen for tray bounds from the backend.
*/
onTrayBounds: (callback) => {
ipcRenderer.on("tray-bounds", (event, bounds) => callback(bounds))
},
/**
* Tell the backend to quit the app.
*/
quit: () => {
ipcRenderer.send("quit-app")
},
/**
* Tell the backend if the mouse should click *through* the window.
* @param {boolean} shouldPassThrough - true = clicks go to desktop; false = clicks hit the app.
*/
setPassthrough: (shouldPassThrough) => {
ipcRenderer.send('set-mouse-passthrough', shouldPassThrough)
},
/**
* Open a URL in the system's default browser.
* @param {string} url - The URL to open.
*/
openExternal: (url) => {
ipcRenderer.send('open-external', url)
},
/**
* Open an ICS calendar event directly in Apple Calendar.
* @param {string} icsContent - The ICS file content.
* @param {string} filename - The filename for the temp file.
* @returns {Promise<boolean>} - Whether the file was opened successfully.
*/
openICSFile: (icsContent, filename) => {
return ipcRenderer.invoke('open-ics-file', icsContent, filename)
}
})