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:
@@ -1,4 +1,5 @@
|
||||
'use client'
|
||||
import * as tauri from '@/lib/tauri';
|
||||
import {ChangeEvent, forwardRef, useContext, useEffect, useImperativeHandle, useState} from 'react';
|
||||
import System from '@/lib/models/System';
|
||||
import {AlertContext} from "@/context/AlertContext";
|
||||
@@ -83,14 +84,10 @@ function GuideLineSetting(props: any, ref: any) {
|
||||
async function getAIGuideLine(): Promise<void> {
|
||||
try {
|
||||
let response: GuideLineAI;
|
||||
if (isCurrentlyOffline()) {
|
||||
response = await window.electron.invoke<GuideLineAI>('db:book:guideline:ai:get', {id: bookId});
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await tauri.getAIGuideLine(bookId);
|
||||
} else {
|
||||
if (book?.localBook) {
|
||||
response = await window.electron.invoke<GuideLineAI>('db:book:guideline:ai:get', {id: bookId});
|
||||
} else {
|
||||
response = await System.authGetQueryToServer<GuideLineAI>(`book/ai/guideline`, userToken, lang, {id: bookId});
|
||||
}
|
||||
response = await System.authGetQueryToServer<GuideLineAI>(`book/ai/guideline`, userToken, lang, {id: bookId});
|
||||
}
|
||||
if (response) {
|
||||
setPlotSummary(response.globalResume || '');
|
||||
@@ -113,19 +110,15 @@ function GuideLineSetting(props: any, ref: any) {
|
||||
async function getGuideLine(): Promise<void> {
|
||||
try {
|
||||
let response: GuideLine;
|
||||
if (isCurrentlyOffline()) {
|
||||
response = await window.electron.invoke<GuideLine>('db:book:guideline:get', {id: bookId});
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await tauri.getGuideLine(bookId);
|
||||
} else {
|
||||
if (book?.localBook) {
|
||||
response = await window.electron.invoke<GuideLine>('db:book:guideline:get', {id: bookId});
|
||||
} else {
|
||||
response = await System.authGetQueryToServer<GuideLine>(
|
||||
`book/guide-line`,
|
||||
userToken,
|
||||
lang,
|
||||
{id: bookId},
|
||||
);
|
||||
}
|
||||
response = await System.authGetQueryToServer<GuideLine>(
|
||||
`book/guide-line`,
|
||||
userToken,
|
||||
lang,
|
||||
{id: bookId},
|
||||
);
|
||||
}
|
||||
if (response) {
|
||||
setTone(response.tone);
|
||||
@@ -165,7 +158,7 @@ function GuideLineSetting(props: any, ref: any) {
|
||||
keyMessages: keyMessages,
|
||||
};
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await window.electron.invoke<boolean>('db:book:guideline:update', guidelineData);
|
||||
response = await tauri.updateGuideLine(guidelineData);
|
||||
} else {
|
||||
response = await System.authPostToServer<boolean>(
|
||||
'book/guide-line',
|
||||
@@ -175,7 +168,7 @@ function GuideLineSetting(props: any, ref: any) {
|
||||
);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === bookId)) {
|
||||
addToQueue('db:book:guideline:update', guidelineData);
|
||||
addToQueue('update_guideline', {data: guidelineData});
|
||||
}
|
||||
}
|
||||
if (!response) {
|
||||
@@ -206,7 +199,7 @@ function GuideLineSetting(props: any, ref: any) {
|
||||
themes: themes,
|
||||
};
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await window.electron.invoke<boolean>('db:book:guideline:ai:update', aiGuidelineData);
|
||||
response = await tauri.updateAIGuideLine(aiGuidelineData);
|
||||
} else {
|
||||
response = await System.authPostToServer<boolean>(
|
||||
'quillsense/book/guide-line',
|
||||
@@ -216,7 +209,7 @@ function GuideLineSetting(props: any, ref: any) {
|
||||
);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === bookId)) {
|
||||
addToQueue('db:book:guideline:ai:update', aiGuidelineData);
|
||||
addToQueue('update_ai_guideline', {data: aiGuidelineData});
|
||||
}
|
||||
}
|
||||
if (response) {
|
||||
|
||||
Reference in New Issue
Block a user