82 lines
2.1 KiB
TypeScript

const { contextBridge, ipcRenderer } = require('electron');
// Expose protected methods that allow the renderer process to use
// the ipcRenderer without exposing the entire object
contextBridge.exposeInMainWorld('electronAPI', {
// Sync control
invoke: (channel: string, ...args: any[]) => {
const validChannels = [
'sync:start',
'sync:stop',
'sync:force-full',
'sync:trigger-immediate',
'sync:get-status',
'config:get',
'config:update-s3',
'config:update-sync',
'config:update-ui',
'config:test-s3',
'config:export-env',
'dialog:select-folder'
];
if (validChannels.includes(channel)) {
return ipcRenderer.invoke(channel, ...args);
}
throw new Error(`Invalid channel: ${channel}`);
},
// Event listeners for sync updates
on: (channel: string, func: (...args: any[]) => void) => {
const validChannels = [
'sync-status-changed',
'sync-operation-started',
'sync-operation-completed',
'sync-operation-failed',
'sync-started',
'sync-completed',
'sync-error',
'sync-engine-started',
'sync-engine-stopped',
'file-changed',
'aws-output',
'show-settings'
];
if (validChannels.includes(channel)) {
ipcRenderer.on(channel, (event: any, ...args: any[]) => func(...args));
}
},
// Remove event listeners
removeAllListeners: (channel: string) => {
const validChannels = [
'sync-status-changed',
'sync-operation-started',
'sync-operation-completed',
'sync-operation-failed',
'sync-started',
'sync-completed',
'sync-error',
'sync-engine-started',
'sync-engine-stopped',
'file-changed',
'aws-output',
'show-settings'
];
if (validChannels.includes(channel)) {
ipcRenderer.removeAllListeners(channel);
}
},
// Export environment variables
exportEnv: async (exportPath?: string) => {
return await ipcRenderer.invoke('config:export-env', exportPath);
}
});
// Note: Type definitions are handled in a separate .d.ts file