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:
@@ -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);
|
||||
|
||||
@@ -36,6 +36,7 @@ import OfflineContext, {OfflineContextType} from "@/context/OfflineContext";
|
||||
import {LocalSyncQueueContext, LocalSyncQueueContextProps} from "@/context/SyncQueueContext";
|
||||
import {BooksSyncContext, BooksSyncContextProps} from "@/context/BooksSyncContext";
|
||||
import {SyncedBook} from "@/lib/models/SyncedBook";
|
||||
import * as tauri from '@/lib/tauri';
|
||||
|
||||
interface ToolbarButton {
|
||||
action: () => void;
|
||||
@@ -302,12 +303,18 @@ export default function TextEditor() {
|
||||
currentTime: mainTimer
|
||||
};
|
||||
if (isCurrentlyOffline() || book?.localBook){
|
||||
response = await window.electron.invoke<boolean>('db:chapter:content:save', saveData);
|
||||
response = await tauri.saveChapterContent({
|
||||
chapterId: saveData.chapterId,
|
||||
version: saveData.version,
|
||||
content: saveData.content,
|
||||
totalWordCount: saveData.totalWordCount,
|
||||
contentId: saveData.chapterId,
|
||||
});
|
||||
} else {
|
||||
response = await System.authPostToServer<boolean>(`chapter/content`, saveData, session?.accessToken, lang);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === book?.bookId)) {
|
||||
addToQueue('db:chapter:content:save', saveData);
|
||||
addToQueue('save_chapter_content', {data: saveData});
|
||||
}
|
||||
}
|
||||
if (!response) {
|
||||
|
||||
Reference in New Issue
Block a user