Integrate offline support and improve error handling across app
- Add `OfflineContext` to manage offline state and interactions within components. - Refactor session logic in `ScribeControllerBar` and `page.tsx` to handle offline scenarios (e.g., check connectivity before enabling GPT features). - Enhance offline PIN setup and verification with better flow and error messaging. - Optimize database IPC handlers to initialize and sync data in offline mode. - Refactor code to clean up redundant logs and ensure stricter typings. - Improve consistency and structure in handling online and offline operations for smoother user experience.
This commit is contained in:
@@ -97,7 +97,7 @@ ipcMain.handle('db:book:books', createHandler<void, BookProps[]>(
|
||||
// GET /book/:id - Get single book
|
||||
ipcMain.handle('db:book:bookBasicInformation', createHandler<string, BookProps>(
|
||||
async function(userId: string, bookId: string, lang: 'fr' | 'en'):Promise<BookProps> {
|
||||
return await Book.getBook(bookId, userId);
|
||||
return await Book.getBook(userId, bookId);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
@@ -2,6 +2,7 @@ import { ipcMain } from 'electron';
|
||||
import { createHandler } from '../database/LocalSystem.js';
|
||||
import * as bcrypt from 'bcrypt';
|
||||
import { getSecureStorage } from '../storage/SecureStorage.js';
|
||||
import { getDatabaseService } from '../database/database.service.js';
|
||||
|
||||
interface SetPinData {
|
||||
pin: string;
|
||||
@@ -62,6 +63,17 @@ ipcMain.handle('offline:pin:verify', async (_event, data: VerifyPinData) => {
|
||||
if (isValid) {
|
||||
// Set userId for session
|
||||
storage.set('userId', lastUserId);
|
||||
|
||||
// Initialize database for offline use
|
||||
const encryptionKey = storage.get<string>(`encryptionKey-${lastUserId}`);
|
||||
if (encryptionKey) {
|
||||
const db = getDatabaseService();
|
||||
db.initialize(lastUserId, encryptionKey);
|
||||
} else {
|
||||
console.error('[Offline] No encryption key found for user');
|
||||
return { success: false, error: 'No encryption key found' };
|
||||
}
|
||||
|
||||
console.log('[Offline] PIN verified, user authenticated locally');
|
||||
return {
|
||||
success: true,
|
||||
|
||||
Reference in New Issue
Block a user