(event, options = {})
| 5221 | return true; |
| 5222 | } catch (error) { |
| 5223 | console.error('Backup error:', error); |
| 5224 | // Make sure we reopen the database even if there's an error |
| 5225 | try { |
| 5226 | const dbPath = getDatabasePath(); |
| 5227 | db = new Database(dbPath, { |
| 5228 | verbose: DEBUG ? console.log : null |
| 5229 | }); |
| 5230 | } catch (reopenError) { |
| 5231 | console.error('Error reopening database:', reopenError); |
| 5232 | } |
| 5233 | throw error; |
| 5234 | } |
| 5235 | } |
| 5236 | return false; |
| 5237 | }); |
| 5238 | |
| 5239 | // Update the restore-database handler |
| 5240 | ipcMain.handle('restore-database', async (event, payload = null) => { |
| 5241 | if (isServerMode && payload && payload.base64) { |
| 5242 | try { |
| 5243 | const dbPath = getDatabasePath(); |
| 5244 | const buffer = Buffer.from(payload.base64, 'base64'); |
| 5245 | |
| 5246 | if (db.open) { |
| 5247 | db.close(); |
| 5248 | } |
| 5249 | |
| 5250 | await fs.promises.writeFile(dbPath, buffer); |
| 5251 | |
| 5252 | db = new Database(dbPath, { |
| 5253 | verbose: DEBUG ? console.log : null |
| 5254 | }); |
| 5255 | |
| 5256 | if (mainWindow && !mainWindow.isDestroyed()) { |
| 5257 | mainWindow.webContents.send('refresh-grid'); |
| 5258 | } |
| 5259 | |
| 5260 | return { success: true }; |
| 5261 | } catch (error) { |
| 5262 | console.error('Restore error:', error); |
| 5263 | try { |
| 5264 | const dbPath = getDatabasePath(); |
| 5265 | db = new Database(dbPath, { |
| 5266 | verbose: DEBUG ? console.log : null |
| 5267 | }); |
| 5268 | } catch (reopenError) { |
| 5269 | console.error('Error reopening database:', reopenError); |
| 5270 | } |
| 5271 | return { success: false, message: error.message }; |
| 5272 | } |
| 5273 | } |
| 5274 | |
| 5275 | const result = await dialog.showOpenDialog(mainWindow, { |
| 5276 | title: 'Restore Database from Backup', |
| 5277 | filters: [ |
nothing calls this directly
no test coverage detected