The state module provides built-in IPC handlers to allow the Electron Renderer process to interact with the main process state.
// In renderer process
import { ipcRenderer } from 'electron';
// Get state
const state = await ipcRenderer.invoke('getState');
// Update state
await ipcRenderer.invoke('updateState', {
userPreferences: {
recentFiles: ['file1.txt', 'file2.txt'],
},
});
// Listen to state changes
ipcRenderer.on('state', (_, state) => {
console.log('State updated:', state);
});
// Force immediate save from renderer
await ipcRenderer.invoke('flushState');