Add error handling, enhance syncing, and refactor deletion logic

- Introduce new error messages for syncing and book deletion in `en.json`.
- Update `DeleteBook` to support local-only deletion and synced book management.
- Refine offline/online behavior with `deleteLocalToo` checkbox and update related state handling.
- Extend repository and IPC methods to handle optional IDs for updates.
- Add `SyncQueueContext` for queueing offline changes and improving synchronization workflows.
- Enhance refined text generation logic in `DraftCompanion` and `GhostWriter` components.
- Replace PUT with PATCH for world updates to align with API expectations.
- Streamline `AlertBox` by integrating dynamic translation keys for deletion prompts.
This commit is contained in:
natreex
2026-01-10 15:50:03 -05:00
parent 060693f152
commit 7f34421212
26 changed files with 506 additions and 100 deletions

View File

@@ -1,4 +1,4 @@
import {app, BrowserWindow, ipcMain, IpcMainInvokeEvent, Menu, nativeImage, protocol, safeStorage, shell} from 'electron';
import {app, BrowserWindow, dialog, ipcMain, IpcMainInvokeEvent, Menu, nativeImage, protocol, safeStorage, shell} from 'electron';
import * as path from 'path';
import {fileURLToPath} from 'url';
import * as fs from 'fs';
@@ -519,6 +519,73 @@ ipcMain.handle('db-initialize', (_event, userId: string, encryptionKey: string)
}
});
/**
* Emergency restore - Clean up ALL local data
*/
function performEmergencyRestore(): void {
try {
// Close database connection
const db: DatabaseService = getDatabaseService();
db.close();
// Get storage and userId before clearing
const storage: SecureStorage = getSecureStorage();
const userId = storage.get<string>('userId');
const lastUserId = storage.get<string>('lastUserId');
// Delete user-specific data
if (userId) {
storage.delete(`pin-${userId}`);
storage.delete(`encryptionKey-${userId}`);
}
if (lastUserId && lastUserId !== userId) {
storage.delete(`pin-${lastUserId}`);
storage.delete(`encryptionKey-${lastUserId}`);
}
// Delete all general data
storage.delete('authToken');
storage.delete('userId');
storage.delete('lastUserId');
storage.delete('userLang');
storage.delete('offlineMode');
storage.delete('syncInterval');
// Save cleared storage
storage.save();
// Delete database file
const userDataPath: string = app.getPath('userData');
const dbPath: string = path.join(userDataPath, 'eritors-local.db');
if (fs.existsSync(dbPath)) {
fs.unlinkSync(dbPath);
}
// Delete secure config file to ensure complete reset
const secureConfigPath: string = path.join(userDataPath, 'secure-config.json');
if (fs.existsSync(secureConfigPath)) {
fs.unlinkSync(secureConfigPath);
}
console.log('[Emergency Restore] All local data cleared successfully');
} catch (error) {
console.error('[Emergency Restore] Error:', error);
}
// Restart app
if (mainWindow) {
mainWindow.close();
mainWindow = null;
}
if (loginWindow) {
loginWindow.close();
loginWindow = null;
}
app.relaunch();
app.exit(0);
}
app.whenReady().then(():void => {
// Security: Disable web cache in production
if (!isDev) {
@@ -558,6 +625,29 @@ app.whenReady().then(():void => {
submenu: [
{ role: 'toggleDevTools' }
]
},
{
label: 'Help',
submenu: [
{
label: 'Restore App',
click: () => {
dialog.showMessageBox({
type: 'warning',
buttons: ['Cancel', 'Restore'],
defaultId: 0,
cancelId: 0,
title: 'Restore App',
message: 'Are you sure you want to restore the app?',
detail: 'This will delete all local data including: PIN codes, encryption keys, local database, and authentication tokens. The app will restart after restoration.'
}).then((result) => {
if (result.response === 1) {
performEmergencyRestore();
}
});
}
}
]
}
];