49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
import { contextBridge, ipcRenderer } from 'electron';
|
|
|
|
// Expose protected methods that allow the renderer process to use
|
|
// the ipcRenderer without exposing the entire object
|
|
contextBridge.exposeInMainWorld('electron', {
|
|
// App paths
|
|
getAppPath: () => ipcRenderer.invoke('get-app-path'),
|
|
getDownloadsPath: () => ipcRenderer.invoke('get-downloads-path'),
|
|
|
|
// File operations
|
|
showItemInFolder: (path: string) => ipcRenderer.invoke('show-item-in-folder', path),
|
|
openExternal: (url: string) => ipcRenderer.invoke('open-external', url),
|
|
|
|
// Window controls
|
|
minimizeWindow: () => ipcRenderer.invoke('window-minimize'),
|
|
maximizeWindow: () => ipcRenderer.invoke('window-maximize'),
|
|
closeWindow: () => ipcRenderer.invoke('window-close'),
|
|
isMaximized: () => ipcRenderer.invoke('window-is-maximized'),
|
|
|
|
// Navigation
|
|
onNavigate: (callback: (path: string) => void) => {
|
|
ipcRenderer.on('navigate', (_event, path) => callback(path));
|
|
},
|
|
|
|
// Platform info
|
|
platform: process.platform,
|
|
isElectron: true,
|
|
});
|
|
|
|
// Type definitions for TypeScript
|
|
declare global {
|
|
interface Window {
|
|
electron: {
|
|
getAppPath: () => Promise<string>;
|
|
getDownloadsPath: () => Promise<string>;
|
|
showItemInFolder: (path: string) => Promise<void>;
|
|
openExternal: (url: string) => Promise<void>;
|
|
minimizeWindow: () => Promise<void>;
|
|
maximizeWindow: () => Promise<void>;
|
|
closeWindow: () => Promise<void>;
|
|
isMaximized: () => Promise<boolean>;
|
|
onNavigate: (callback: (path: string) => void) => void;
|
|
platform: NodeJS.Platform;
|
|
isElectron: boolean;
|
|
};
|
|
}
|
|
}
|
|
|