Migrate from window.electron to tauri IPC functions across components

- Replaced `window.electron.invoke` calls with equivalent `tauri` function calls for all IPC interactions.
- Removed `electron.d.ts` TypeScript definitions as they are no longer needed.
- Updated related logic for offline/online state synchronization.
- Added `types.rs` and `shared/mod.rs` modules to support Tauri IPC integration with Rust enums and shared logic.
- Refactored IPC request queues to use updated handler names for consistency with Tauri.
This commit is contained in:
natreex
2026-03-21 09:34:13 -04:00
parent 1a15692e40
commit ee4438834c
144 changed files with 21258 additions and 876 deletions

View File

@@ -34,6 +34,7 @@ import {AIUsageContext, AIUsageContextProps} from "@/context/AIUsageContext";
import {configs} from "@/lib/configs";
import OfflineContext, {OfflineContextType} from "@/context/OfflineContext";
import AdvancedGenerationOptions from "@/components/form/AdvancedGenerationOptions";
import * as tauri from '@/lib/tauri';
interface CompanionContent {
version: number;
@@ -113,26 +114,17 @@ export default function DraftCompanion() {
async function getDraftContent(): Promise<void> {
try {
let response: CompanionContent | null;
if (isCurrentlyOffline()) {
response = await window.electron.invoke<CompanionContent>('db:chapter:content:companion', {
if (isCurrentlyOffline() || book?.localBook) {
response = await tauri.getCompanionContent(
chapter?.chapterId ?? '',
chapter?.chapterContent.version ?? 0,
) as CompanionContent | null;
} else {
response = await System.authGetQueryToServer<CompanionContent>(`chapter/content/companion`, session.accessToken, lang, {
bookid: book?.bookId,
chapterid: chapter?.chapterId,
version: chapter?.chapterContent.version,
});
} else {
if (book?.localBook) {
response = await window.electron.invoke<CompanionContent>('db:chapter:content:companion', {
bookid: book?.bookId,
chapterid: chapter?.chapterId,
version: chapter?.chapterContent.version,
});
} else {
response = await System.authGetQueryToServer<CompanionContent>(`chapter/content/companion`, session.accessToken, lang, {
bookid: book?.bookId,
chapterid: chapter?.chapterId,
version: chapter?.chapterContent.version,
});
}
}
if (response && mainEditor) {
mainEditor.commands.setContent(JSON.parse(response.content));
@@ -169,16 +161,12 @@ export default function DraftCompanion() {
async function fetchTags(): Promise<void> {
try {
let responseTags: BookTags | null;
if (isCurrentlyOffline()) {
responseTags = await window.electron.invoke<BookTags>('db:book:tags', book?.bookId);
if (isCurrentlyOffline() || book?.localBook) {
responseTags = await tauri.getBookTags(book?.bookId ?? '') as BookTags | null;
} else {
if (book?.localBook) {
responseTags = await window.electron.invoke<BookTags>('db:book:tags', book?.bookId);
} else {
responseTags = await System.authGetQueryToServer<BookTags>(`book/tags`, session.accessToken, lang, {
bookId: book?.bookId
});
}
responseTags = await System.authGetQueryToServer<BookTags>(`book/tags`, session.accessToken, lang, {
bookId: book?.bookId
});
}
if (responseTags) {
setCharacters(responseTags.characters);