Files
ERitors-Scribe-Desktop/electron/ipc/character.ipc.ts
natreex 23f1592c22 Add offline mode logic for book, story, and world operations
- Integrate `OfflineContext` into book, story settings, and related components.
- Add conditional logic to toggle between server API requests and offline IPC handlers (`db:book:delete`, `db:book:story:get`, `db:location:all`, etc.).
- Refactor and update IPC handlers to accept structured data arguments for improved consistency (`data: object`).
- Ensure stricter typings in IPC handlers and frontend functions.
- Improve error handling and user feedback in both online and offline modes.
2025-11-26 22:52:34 -05:00

75 lines
2.7 KiB
TypeScript

import { ipcMain } from 'electron';
import { createHandler } from '../database/LocalSystem.js';
import Character from '../database/models/Character.js';
import type { CharacterProps, CharacterPropsPost, CharacterAttribute } from '../database/models/Character.js';
interface AddCharacterData {
character: CharacterPropsPost;
bookId: string;
}
interface AddAttributeData {
characterId: string;
type: string;
name: string;
}
// GET /character/list - Get character list
interface GetCharacterListData {
bookid: string;
}
ipcMain.handle('db:character:list', createHandler<GetCharacterListData, CharacterProps[]>(
function(userId: string, data: GetCharacterListData, lang: 'fr' | 'en'): CharacterProps[] {
return Character.getCharacterList(userId, data.bookid, lang);
}
)
);
// GET /character/attribute - Get character attributes
interface GetCharacterAttributesData {
characterId: string;
}
ipcMain.handle('db:character:attributes', createHandler<GetCharacterAttributesData, CharacterAttribute[]>(
function(userId: string, data: GetCharacterAttributesData, lang: 'fr' | 'en'): CharacterAttribute[] {
return Character.getAttributes(data.characterId, userId, lang);
}
)
);
// POST /character/add - Add new character
ipcMain.handle('db:character:create', createHandler<AddCharacterData, string>(
function(userId: string, data: AddCharacterData, lang: 'fr' | 'en'): string {
return Character.addNewCharacter(userId, data.character, data.bookId, lang);
}
)
);
// POST /character/attribute/add - Add attribute to character
ipcMain.handle('db:character:attribute:add', createHandler<AddAttributeData, string>(
function(userId: string, data: AddAttributeData, lang: 'fr' | 'en'): string {
return Character.addNewAttribute(data.characterId, userId, data.type, data.name, lang);
}
)
);
// DELETE /character/attribute/delete - Delete character attribute
interface DeleteAttributeData {
attributeId: string;
}
ipcMain.handle('db:character:attribute:delete', createHandler<DeleteAttributeData, boolean>(
function(userId: string, data: DeleteAttributeData, lang: 'fr' | 'en'): boolean {
return Character.deleteAttribute(userId, data.attributeId, lang);
}
)
);
// POST /character/update - Update character
interface UpdateCharacterData {
character: CharacterPropsPost;
}
ipcMain.handle('db:character:update', createHandler<UpdateCharacterData, boolean>(
function(userId: string, data: UpdateCharacterData, lang: 'fr' | 'en'): boolean {
return Character.updateCharacter(userId, data.character, lang);
}
)
);