-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreload.js
More file actions
47 lines (41 loc) · 1.3 KB
/
preload.js
File metadata and controls
47 lines (41 loc) · 1.3 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
const { contextBridge, ipcRenderer } = require('electron');
/**
* Preload Script
*
* This script runs in the renderer process before the web content loads.
* It provides a secure bridge between the main process and renderer process.
*
* The contextBridge API allows us to expose specific functions to the renderer
* without giving it full access to Node.js APIs (security best practice).
*/
// Expose protected methods that allow the renderer process to use
// the ipcRenderer without exposing the entire object
contextBridge.exposeInMainWorld('electronAPI', {
/**
* Toggle always-on-top window behavior
* @returns {Promise<boolean>} New always-on-top state
*/
toggleAlwaysOnTop: () => ipcRenderer.invoke('toggle-always-on-top'),
/**
* Get current always-on-top state
* @returns {Promise<boolean>} Current always-on-top state
*/
getAlwaysOnTop: () => ipcRenderer.invoke('get-always-on-top'),
/**
* Platform information
*/
platform: process.platform,
/**
* Check if running in Electron
*/
isElectron: true
});
/**
* Optional: Add keyboard shortcuts listener
* This allows the React app to listen for global shortcuts
*/
contextBridge.exposeInMainWorld('shortcuts', {
onGlobalShortcut: (callback) => {
ipcRenderer.on('global-shortcut', callback);
}
});