Browse Source
Current Status: - SQLite plugin successfully initializes in main process - Preload script and context bridge working correctly - IPC handlers for SQLite operations not registered - Type definitions out of sync with implementation Changes Made: - Added comprehensive debug logging in preload script - Implemented retry logic for SQLite operations (3 attempts, 1s delay) - Added proper type definitions for SQLite connection options - Defined strict channel validation for IPC communication - Enhanced error handling and logging throughout Type Definitions Updates: - Aligned ElectronAPI interface with actual implementation - Added proper typing for SQLite operations - Structured IPC renderer interface with correct method signatures Next Steps: - Register missing IPC handlers in main process - Update type definitions to match implementation - Add proper error recovery for SQLite operations - Address Content Security Policy warnings Affected Files: - electron/src/preload.ts - src/types/electron.d.ts - src/utils/debug-electron.ts - src/services/platforms/ElectronPlatformService.ts Note: This is a transitional commit. While the structure is improved, database operations are not yet functional due to missing IPC handlers.sql-absurd-sql-further
3 changed files with 198 additions and 36 deletions
@ -0,0 +1,123 @@ |
|||||
|
/** |
||||
|
* Debug utilities for Electron integration |
||||
|
* Helps verify the context bridge and SQLite functionality |
||||
|
*/ |
||||
|
|
||||
|
const debugLogger = { |
||||
|
log: (...args: unknown[]) => console.log('[Debug]', ...args), |
||||
|
error: (...args: unknown[]) => console.error('[Debug]', ...args), |
||||
|
info: (...args: unknown[]) => console.info('[Debug]', ...args), |
||||
|
warn: (...args: unknown[]) => console.warn('[Debug]', ...args), |
||||
|
debug: (...args: unknown[]) => console.debug('[Debug]', ...args) |
||||
|
}; |
||||
|
|
||||
|
export async function verifyElectronAPI(): Promise<void> { |
||||
|
debugLogger.info('Verifying Electron API exposure...'); |
||||
|
|
||||
|
// Check if window.electron exists
|
||||
|
if (!window.electron) { |
||||
|
throw new Error('window.electron is not defined'); |
||||
|
} |
||||
|
debugLogger.info('window.electron is available'); |
||||
|
|
||||
|
// Verify IPC renderer
|
||||
|
if (!window.electron.ipcRenderer) { |
||||
|
throw new Error('IPC renderer is not available'); |
||||
|
} |
||||
|
debugLogger.info('IPC renderer is available with methods:', { |
||||
|
hasOn: typeof window.electron.ipcRenderer.on === 'function', |
||||
|
hasOnce: typeof window.electron.ipcRenderer.once === 'function', |
||||
|
hasSend: typeof window.electron.ipcRenderer.send === 'function', |
||||
|
hasInvoke: typeof window.electron.ipcRenderer.invoke === 'function' |
||||
|
}); |
||||
|
|
||||
|
// Verify SQLite API
|
||||
|
if (!window.electron.sqlite) { |
||||
|
throw new Error('SQLite API is not available'); |
||||
|
} |
||||
|
debugLogger.info('SQLite API is available with methods:', { |
||||
|
hasIsAvailable: typeof window.electron.sqlite.isAvailable === 'function', |
||||
|
hasEcho: typeof window.electron.sqlite.echo === 'function', |
||||
|
hasCreateConnection: typeof window.electron.sqlite.createConnection === 'function', |
||||
|
hasCloseConnection: typeof window.electron.sqlite.closeConnection === 'function', |
||||
|
hasQuery: typeof window.electron.sqlite.query === 'function', |
||||
|
hasRun: typeof window.electron.sqlite.run === 'function', |
||||
|
hasExecute: typeof window.electron.sqlite.execute === 'function', |
||||
|
hasGetPlatform: typeof window.electron.sqlite.getPlatform === 'function' |
||||
|
}); |
||||
|
|
||||
|
// Test SQLite availability
|
||||
|
try { |
||||
|
const isAvailable = await window.electron.sqlite.isAvailable(); |
||||
|
debugLogger.info('SQLite availability check:', { isAvailable }); |
||||
|
} catch (error) { |
||||
|
debugLogger.error('SQLite availability check failed:', error); |
||||
|
} |
||||
|
|
||||
|
// Test echo functionality
|
||||
|
try { |
||||
|
const echoResult = await window.electron.sqlite.echo('test'); |
||||
|
debugLogger.info('SQLite echo test:', echoResult); |
||||
|
} catch (error) { |
||||
|
debugLogger.error('SQLite echo test failed:', error); |
||||
|
} |
||||
|
|
||||
|
// Verify environment
|
||||
|
debugLogger.info('Environment:', { |
||||
|
platform: window.electron.env.platform, |
||||
|
isDev: window.electron.env.isDev |
||||
|
}); |
||||
|
|
||||
|
debugLogger.info('Electron API verification complete'); |
||||
|
} |
||||
|
|
||||
|
// Export a function to test SQLite operations
|
||||
|
export async function testSQLiteOperations(): Promise<void> { |
||||
|
debugLogger.info('Testing SQLite operations...'); |
||||
|
|
||||
|
try { |
||||
|
// Test connection creation
|
||||
|
debugLogger.info('Creating test connection...'); |
||||
|
await window.electron.sqlite.createConnection({ |
||||
|
database: 'test', |
||||
|
version: 1, |
||||
|
readOnly: false |
||||
|
}); |
||||
|
debugLogger.info('Test connection created successfully'); |
||||
|
|
||||
|
// Test query
|
||||
|
debugLogger.info('Testing query operation...'); |
||||
|
const queryResult = await window.electron.sqlite.query({ |
||||
|
statement: 'SELECT 1 as test' |
||||
|
}); |
||||
|
debugLogger.info('Query test result:', queryResult); |
||||
|
|
||||
|
// Test run
|
||||
|
debugLogger.info('Testing run operation...'); |
||||
|
const runResult = await window.electron.sqlite.run({ |
||||
|
statement: 'CREATE TABLE IF NOT EXISTS test_table (id INTEGER PRIMARY KEY)' |
||||
|
}); |
||||
|
debugLogger.info('Run test result:', runResult); |
||||
|
|
||||
|
// Test execute
|
||||
|
debugLogger.info('Testing execute operation...'); |
||||
|
const executeResult = await window.electron.sqlite.execute({ |
||||
|
statements: [ |
||||
|
{ statement: 'INSERT INTO test_table (id) VALUES (1)' }, |
||||
|
{ statement: 'SELECT * FROM test_table' } |
||||
|
] |
||||
|
}); |
||||
|
debugLogger.info('Execute test result:', executeResult); |
||||
|
|
||||
|
// Clean up
|
||||
|
debugLogger.info('Closing test connection...'); |
||||
|
await window.electron.sqlite.closeConnection({ database: 'test' }); |
||||
|
debugLogger.info('Test connection closed'); |
||||
|
|
||||
|
} catch (error) { |
||||
|
debugLogger.error('SQLite operation test failed:', error); |
||||
|
throw error; |
||||
|
} |
||||
|
|
||||
|
debugLogger.info('SQLite operations test complete'); |
||||
|
} |
Loading…
Reference in new issue