Add enable/disable management for book tools (characters, worlds, and locations)

- Introduced toggling functionality for managing `characters`, `worlds`, and `locations` tool availability per book.
- Updated `CharacterComponent`, `WorldSetting`, and `LocationComponent` with toggle switches for tool enablement.
- Added `book_tools` database table and related schema migration for storing tool settings.
- Extended API calls, models, and IPC handlers to support tool enablement states.
- Localized new strings for English with supporting descriptions and messages.
- Adjusted conditional rendering logic across components to respect tool enablement.
This commit is contained in:
natreex
2026-01-14 17:42:59 -05:00
parent 7215ac5c4f
commit e45a15225b
19 changed files with 782 additions and 341 deletions

View File

@@ -1,7 +1,7 @@
import { getUserEncryptionKey } from "../keyManager.js";
import System from "../System.js";
import { BookSyncCompare, CompleteBook, SyncedBook } from "./Book.js";
import BookRepo, { EritBooksTable, SyncedBookResult } from "../repositories/book.repository.js";
import { BookSyncCompare, CompleteBook, SyncedBook, SyncedBookTools } from "./Book.js";
import BookRepo, { EritBooksTable, SyncedBookResult, BookToolsTable } from "../repositories/book.repository.js";
import ChapterRepo, {
BookChapterInfosTable,
BookChaptersTable,
@@ -350,6 +350,9 @@ export default class Sync {
});
}
const bookToolsResult: BookToolsTable | null = BookRepo.fetchBookTools(userId, syncCompareData.id, lang);
const bookTools: BookToolsTable[] = bookToolsResult ? [bookToolsResult] : [];
return {
eritBooks: decryptedBooks,
chapters: decryptedChapters,
@@ -367,7 +370,8 @@ export default class Sync {
actSummaries: decryptedActSummaries,
guideLine: decryptedGuideLines,
aiGuideLine: decryptedAIGuideLines,
issues: decryptedIssues
issues: decryptedIssues,
bookTools: bookTools
};
}
@@ -724,6 +728,23 @@ export default class Sync {
}
}
const serverBookTools: BookToolsTable[] = completeBook.bookTools;
if (serverBookTools && serverBookTools.length > 0) {
for (const serverBookTool of serverBookTools) {
const bookToolsExists: BookToolsTable | null = BookRepo.fetchBookTools(userId, bookId, lang);
if (bookToolsExists) {
BookRepo.updateBookToolSetting(userId, bookId, 'characters_enabled', serverBookTool.characters_enabled === 1, lang);
BookRepo.updateBookToolSetting(userId, bookId, 'worlds_enabled', serverBookTool.worlds_enabled === 1, lang);
BookRepo.updateBookToolSetting(userId, bookId, 'locations_enabled', serverBookTool.locations_enabled === 1, lang);
} else {
const insertSuccessful: boolean = BookRepo.insertSyncBookTools(bookId, userId, serverBookTool.characters_enabled, serverBookTool.worlds_enabled, serverBookTool.locations_enabled, lang);
if (!insertSuccessful) {
return false;
}
}
}
}
return true;
}
@@ -940,6 +961,13 @@ export default class Sync {
lastUpdate: aiGuidelineRecord.last_update
} : null;
const bookToolsRecord: BookToolsTable | null = BookRepo.fetchBookTools(userId, currentBookId, lang);
const bookTools: SyncedBookTools | null = bookToolsRecord ? {
charactersEnabled: bookToolsRecord.characters_enabled === 1,
worldsEnabled: bookToolsRecord.worlds_enabled === 1,
locationsEnabled: bookToolsRecord.locations_enabled === 1
} : null;
return {
id: currentBookId,
type: bookRecord.type,
@@ -955,7 +983,8 @@ export default class Sync {
issues: bookIssues,
actSummaries: bookActSummaries,
guideLine: bookGuideLine,
aiGuideLine: bookAIGuideLine
aiGuideLine: bookAIGuideLine,
bookTools: bookTools
};
});
}