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:
@@ -24,6 +24,7 @@ import ToggleSwitch from "@/components/form/ToggleSwitch";
|
||||
import {SeriesWorldProps, SeriesWorldListItem} from "@/lib/models/Series";
|
||||
import SeriesImportSelector from "@/components/form/SeriesImportSelector";
|
||||
import SyncFieldWrapper from "@/components/form/SyncFieldWrapper";
|
||||
import * as tauri from '@/lib/tauri';
|
||||
|
||||
export interface ElementSection {
|
||||
title: string;
|
||||
@@ -99,11 +100,7 @@ export function WorldSetting(props: WorldSettingProps, ref: React.Ref<{ handleSa
|
||||
try {
|
||||
let response: boolean;
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await window.electron.invoke<boolean>('db:book:tool:update', {
|
||||
bookId: currentEntityId,
|
||||
toolName: 'worlds',
|
||||
enabled: enabled
|
||||
});
|
||||
response = await tauri.updateBookToolSetting(currentEntityId, 'worlds', enabled);
|
||||
} else {
|
||||
response = await System.authPatchToServer<boolean>('book/tool-setting', {
|
||||
bookId: currentEntityId,
|
||||
@@ -111,11 +108,11 @@ export function WorldSetting(props: WorldSettingProps, ref: React.Ref<{ handleSa
|
||||
enabled: enabled
|
||||
}, session.accessToken, lang);
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === currentEntityId)) {
|
||||
addToQueue('db:book:tool:update', {
|
||||
addToQueue('update_book_tool_setting', {data: {
|
||||
bookId: currentEntityId,
|
||||
toolName: 'worlds',
|
||||
enabled: enabled
|
||||
});
|
||||
}});
|
||||
}
|
||||
}
|
||||
if (response && setBook && book) {
|
||||
@@ -176,7 +173,7 @@ export function WorldSetting(props: WorldSettingProps, ref: React.Ref<{ handleSa
|
||||
// Book mode: dual offline/online logic
|
||||
let response: WorldListResponse;
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await window.electron.invoke<WorldListResponse>('db:book:worlds:get', {bookid: currentEntityId});
|
||||
response = await tauri.getWorlds(currentEntityId, true);
|
||||
} else {
|
||||
response = await System.authGetQueryToServer<WorldListResponse>('book/worlds', session.accessToken, lang, {
|
||||
bookid: currentEntityId,
|
||||
@@ -237,10 +234,7 @@ export function WorldSetting(props: WorldSettingProps, ref: React.Ref<{ handleSa
|
||||
}
|
||||
} else if (isCurrentlyOffline() || book?.localBook) {
|
||||
// Book mode: offline/local
|
||||
newWorldId = await window.electron.invoke<string>('db:book:world:add', {
|
||||
worldName: newWorldName,
|
||||
bookId: currentEntityId,
|
||||
});
|
||||
newWorldId = await tauri.addWorld(currentEntityId, newWorldName);
|
||||
if (!newWorldId) {
|
||||
errorMessage(t("worldSetting.addWorldError"));
|
||||
return;
|
||||
@@ -256,11 +250,11 @@ export function WorldSetting(props: WorldSettingProps, ref: React.Ref<{ handleSa
|
||||
return;
|
||||
}
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === currentEntityId)) {
|
||||
addToQueue('db:book:world:add', {
|
||||
addToQueue('add_world', {data: {
|
||||
worldName: newWorldName,
|
||||
worldId: newWorldId,
|
||||
bookId: currentEntityId,
|
||||
});
|
||||
}});
|
||||
}
|
||||
}
|
||||
const newWorld: WorldProps = {
|
||||
@@ -319,10 +313,7 @@ export function WorldSetting(props: WorldSettingProps, ref: React.Ref<{ handleSa
|
||||
}, session.accessToken, lang);
|
||||
} else if (isCurrentlyOffline() || book?.localBook) {
|
||||
// Book mode: offline/local
|
||||
response = await window.electron.invoke<boolean>('db:book:world:update', {
|
||||
world: currentWorld,
|
||||
bookId: currentEntityId,
|
||||
});
|
||||
response = await tauri.updateWorld(currentWorld);
|
||||
} else {
|
||||
// Book mode: online
|
||||
response = await System.authPatchToServer<boolean>('book/world/update', {
|
||||
@@ -330,10 +321,10 @@ export function WorldSetting(props: WorldSettingProps, ref: React.Ref<{ handleSa
|
||||
bookId: currentEntityId,
|
||||
}, session.accessToken, lang);
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === currentEntityId)) {
|
||||
addToQueue('db:book:world:update', {
|
||||
addToQueue('update_world', {data: {
|
||||
world: currentWorld,
|
||||
bookId: currentEntityId,
|
||||
});
|
||||
}});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -424,11 +415,11 @@ export function WorldSetting(props: WorldSettingProps, ref: React.Ref<{ handleSa
|
||||
|
||||
// Sync to local if book is synced
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === currentEntityId)) {
|
||||
addToQueue('db:book:world:add', {
|
||||
addToQueue('add_world', {data: {
|
||||
worldName: seriesWorld.name,
|
||||
worldId: worldId,
|
||||
bookId: currentEntityId,
|
||||
});
|
||||
}});
|
||||
}
|
||||
|
||||
const newWorld: WorldProps = {
|
||||
|
||||
Reference in New Issue
Block a user