Integrate local database management and IPC handlers into Electron
- Add comprehensive IPC handlers for database operations like books, chapters, characters, and conversations. - Implement local database initialization and user data encryption. - Update preload script paths for consistent environment handling. - Modify `page.tsx` to initialize local database within Electron environment. - Add new dependencies including `node-sqlite3-wasm` and `electron-rebuild`.
This commit is contained in:
24
app/page.tsx
24
app/page.tsx
@@ -31,6 +31,8 @@ import enMessages from '@/lib/locales/en.json';
|
||||
import {NextIntlClientProvider, useTranslations} from "next-intl";
|
||||
import {LangContext} from "@/context/LangContext";
|
||||
import {AIUsageContext} from "@/context/AIUsageContext";
|
||||
import OfflineProvider from "@/context/OfflineProvider";
|
||||
import OfflineContext from "@/context/OfflineContext";
|
||||
|
||||
const messagesMap = {
|
||||
fr: frMessages,
|
||||
@@ -41,6 +43,7 @@ function ScribeContent() {
|
||||
const t = useTranslations();
|
||||
const {lang: locale} = useContext(LangContext);
|
||||
const {errorMessage} = useContext(AlertContext);
|
||||
const {initializeDatabase} = useContext(OfflineContext);
|
||||
const editor: Editor | null = useEditor({
|
||||
extensions: [
|
||||
StarterKit,
|
||||
@@ -216,6 +219,19 @@ function ScribeContent() {
|
||||
});
|
||||
setCurrentCredits(user.creditsBalance)
|
||||
setAmountSpent(user.aiUsage)
|
||||
|
||||
// Initialiser la DB locale en Electron
|
||||
if (window.electron && user.id) {
|
||||
try {
|
||||
const dbInitialized = await initializeDatabase(user.id);
|
||||
if (dbInitialized) {
|
||||
console.log('Database initialized successfully');
|
||||
// TODO: Sync initial des données du serveur vers la DB locale
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to initialize database:', error);
|
||||
}
|
||||
}
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof Error) {
|
||||
errorMessage(e.message);
|
||||
@@ -359,9 +375,11 @@ export default function Scribe() {
|
||||
return (
|
||||
<LangContext.Provider value={{lang: locale, setLang: setLocale}}>
|
||||
<NextIntlClientProvider locale={locale} messages={messages}>
|
||||
<AlertProvider>
|
||||
<ScribeContent/>
|
||||
</AlertProvider>
|
||||
<OfflineProvider>
|
||||
<AlertProvider>
|
||||
<ScribeContent/>
|
||||
</AlertProvider>
|
||||
</OfflineProvider>
|
||||
</NextIntlClientProvider>
|
||||
</LangContext.Provider>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user