Files
ERitors-Scribe-Desktop/electron/preload.ts
natreex f85c2d2269 Add offline mode support with PIN configuration and management
- Introduce `OfflinePinSetup` component for users to configure secure offline access.
- Add new `AIUsageContext` and extend `OfflineProvider` for offline-related state management.
- Implement offline login functionality in `electron/main.ts` with PIN verification and fallback support.
- Enhance IPC handlers to manage offline mode data, PIN setup, and synchronization.
- Update localization files (`en.json`, `fr.json`) with offline mode and PIN-related strings.
- Add `bcrypt` and `@types/bcrypt` dependencies for secure PIN hashing and validation.
- Refactor login and session management to handle offline mode scenarios with improved error handling and flow.
2025-11-19 19:58:55 -05:00

46 lines
2.1 KiB
TypeScript

const { contextBridge, ipcRenderer } = require('electron');
/**
* Exposer des APIs sécurisées au renderer process
* Utilise invoke() générique pour tous les appels IPC
*/
contextBridge.exposeInMainWorld('electron', {
// Platform info
platform: process.platform,
// Generic invoke method - use this for all IPC calls
invoke: (channel: string, ...args: any[]) => ipcRenderer.invoke(channel, ...args),
// Token management (shortcuts for convenience)
getToken: () => ipcRenderer.invoke('get-token'),
setToken: (token: string) => ipcRenderer.invoke('set-token', token),
removeToken: () => ipcRenderer.invoke('remove-token'),
// Language management (shortcuts for convenience)
getLang: () => ipcRenderer.invoke('get-lang'),
setLang: (lang: 'fr' | 'en') => ipcRenderer.invoke('set-lang', lang),
// Auth events (use send for one-way communication)
loginSuccess: (token: string) => ipcRenderer.send('login-success', token),
logout: () => ipcRenderer.send('logout'),
// User initialization (after getting user info from server)
initUser: (userId: string) => ipcRenderer.invoke('init-user', userId),
// Encryption key management (shortcuts for convenience)
generateEncryptionKey: (userId: string) => ipcRenderer.invoke('generate-encryption-key', userId),
getUserEncryptionKey: (userId: string) => ipcRenderer.invoke('get-user-encryption-key', userId),
setUserEncryptionKey: (userId: string, encryptionKey: string) => ipcRenderer.invoke('set-user-encryption-key', userId, encryptionKey),
// Database initialization (shortcut for convenience)
dbInitialize: (userId: string, encryptionKey: string) => ipcRenderer.invoke('db-initialize', userId, encryptionKey),
// Offline mode management
offlinePinSet: (pin: string) => ipcRenderer.invoke('offline:pin:set', { pin }),
offlinePinVerify: (pin: string) => ipcRenderer.invoke('offline:pin:verify', { pin }),
offlineModeSet: (enabled: boolean, syncInterval?: number) =>
ipcRenderer.invoke('offline:mode:set', { enabled, syncInterval }),
offlineModeGet: () => ipcRenderer.invoke('offline:mode:get'),
offlineSyncCheck: () => ipcRenderer.invoke('offline:sync:check'),
});