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:
@@ -17,6 +17,7 @@ import System from '@/lib/models/System';
|
||||
import {useTranslations} from 'next-intl';
|
||||
import {SelectBoxProps} from '@/shared/interface';
|
||||
import {ViewMode} from '@/shared/interface';
|
||||
import * as tauri from '@/lib/tauri';
|
||||
|
||||
const initialWorldState: WorldProps = {
|
||||
id: '',
|
||||
@@ -135,10 +136,7 @@ export function useWorlds(config: UseWorldsConfig): UseWorldsReturn {
|
||||
let response: SeriesWorldProps[];
|
||||
// Dual logic: offline ou livre local → IPC, sinon serveur
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await window.electron.invoke<SeriesWorldProps[]>(
|
||||
'db:series:world:list',
|
||||
{seriesId: bookSeriesId}
|
||||
);
|
||||
response = await tauri.getSeriesWorldList(bookSeriesId);
|
||||
} else {
|
||||
response = await System.authGetQueryToServer<SeriesWorldProps[]>(
|
||||
'series/world/list',
|
||||
@@ -164,10 +162,7 @@ export function useWorlds(config: UseWorldsConfig): UseWorldsReturn {
|
||||
// Series mode - dual logic
|
||||
let response: SeriesWorldProps[];
|
||||
if (isCurrentlyOffline() || localSeries) {
|
||||
response = await window.electron.invoke<SeriesWorldProps[]>(
|
||||
'db:series:world:list',
|
||||
{seriesId: entityId}
|
||||
);
|
||||
response = await tauri.getSeriesWorldList(entityId);
|
||||
} else {
|
||||
response = await System.authGetQueryToServer<SeriesWorldProps[]>(
|
||||
'series/world/list',
|
||||
@@ -212,9 +207,9 @@ export function useWorlds(config: UseWorldsConfig): UseWorldsReturn {
|
||||
} else {
|
||||
let response: WorldListResponse;
|
||||
if (isCurrentlyOffline()) {
|
||||
response = await window.electron.invoke<WorldListResponse>('db:book:worlds:get', {bookid: entityId});
|
||||
response = await tauri.getWorlds(entityId, true) as unknown as WorldListResponse;
|
||||
} else if (book?.localBook) {
|
||||
response = await window.electron.invoke<WorldListResponse>('db:book:worlds:get', {bookid: entityId});
|
||||
response = await tauri.getWorlds(entityId, true) as unknown as WorldListResponse;
|
||||
} else {
|
||||
response = await System.authGetQueryToServer<WorldListResponse>(
|
||||
'book/worlds',
|
||||
@@ -293,11 +288,11 @@ export function useWorlds(config: UseWorldsConfig): UseWorldsReturn {
|
||||
};
|
||||
let response: boolean;
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await window.electron.invoke<boolean>('db:book:tool:update', requestData);
|
||||
response = await tauri.updateBookToolSetting(requestData.bookId, requestData.toolName, requestData.enabled);
|
||||
} else {
|
||||
response = await System.authPatchToServer<boolean>('book/tool-setting', requestData, userToken, lang);
|
||||
if (localSyncedBooks.find((sb: SyncedBook): boolean => sb.id === book?.bookId)) {
|
||||
addToQueue('db:book:tool:update', requestData);
|
||||
addToQueue('update_book_tool_setting', {data: requestData});
|
||||
}
|
||||
}
|
||||
if (response && setBook && book) {
|
||||
@@ -333,7 +328,7 @@ export function useWorlds(config: UseWorldsConfig): UseWorldsReturn {
|
||||
name: newWorldName,
|
||||
};
|
||||
if (isCurrentlyOffline() || localSeries) {
|
||||
newWorldId = await window.electron.invoke<string>('db:series:world:add', addData);
|
||||
newWorldId = await tauri.addSeriesWorld(addData);
|
||||
} else {
|
||||
newWorldId = await System.authPostToServer<string>(
|
||||
'series/world/add',
|
||||
@@ -342,7 +337,7 @@ export function useWorlds(config: UseWorldsConfig): UseWorldsReturn {
|
||||
lang
|
||||
);
|
||||
if (localSyncedSeries.find((s: SyncedSeries): boolean => s.id === entityId)) {
|
||||
addToQueue('db:series:world:add', {...addData, id: newWorldId});
|
||||
addToQueue('add_series_world', {data: {...addData, id: newWorldId}});
|
||||
}
|
||||
}
|
||||
if (!newWorldId) {
|
||||
@@ -355,11 +350,11 @@ export function useWorlds(config: UseWorldsConfig): UseWorldsReturn {
|
||||
bookId: entityId,
|
||||
};
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
newWorldId = await window.electron.invoke<string>('db:book:world:add', requestData);
|
||||
newWorldId = await tauri.addWorld(requestData.bookId || entityId, requestData.worldName, requestData.id, requestData.seriesWorldId);
|
||||
} else {
|
||||
newWorldId = await System.authPostToServer<string>('book/world/add', requestData, userToken, lang);
|
||||
if (localSyncedBooks.find((sb: SyncedBook): boolean => sb.id === entityId)) {
|
||||
addToQueue('db:book:world:add', {...requestData, id: newWorldId});
|
||||
addToQueue('add_world', {data: {...requestData, id: newWorldId}});
|
||||
}
|
||||
}
|
||||
if (!newWorldId) {
|
||||
@@ -410,11 +405,11 @@ export function useWorlds(config: UseWorldsConfig): UseWorldsReturn {
|
||||
};
|
||||
let response: boolean;
|
||||
if (isCurrentlyOffline() || localSeries) {
|
||||
response = await window.electron.invoke<boolean>('db:series:world:update', updateData);
|
||||
response = await tauri.updateSeriesWorld(updateData);
|
||||
} else {
|
||||
response = await System.authPatchToServer<boolean>('series/world/update', updateData, userToken, lang);
|
||||
if (localSyncedSeries.find((s: SyncedSeries): boolean => s.id === entityId)) {
|
||||
addToQueue('db:series:world:update', updateData);
|
||||
addToQueue('update_series_world', {data: updateData});
|
||||
}
|
||||
}
|
||||
if (!response) {
|
||||
@@ -428,11 +423,11 @@ export function useWorlds(config: UseWorldsConfig): UseWorldsReturn {
|
||||
};
|
||||
let response: boolean;
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await window.electron.invoke<boolean>('db:book:world:update', requestData);
|
||||
response = await tauri.updateWorld(requestData.world || requestData);
|
||||
} else {
|
||||
response = await System.authPatchToServer<boolean>('book/world/update', requestData, userToken, lang);
|
||||
if (localSyncedBooks.find((sb: SyncedBook): boolean => sb.id === entityId)) {
|
||||
addToQueue('db:book:world:update', requestData);
|
||||
addToQueue('update_world', {data: requestData});
|
||||
}
|
||||
}
|
||||
if (!response) {
|
||||
@@ -469,8 +464,8 @@ export function useWorlds(config: UseWorldsConfig): UseWorldsReturn {
|
||||
|
||||
let seriesWorldId: string;
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
// Mode offline ou livre local → IPC
|
||||
seriesWorldId = await window.electron.invoke<string>('db:series:world:add', seriesWorldData);
|
||||
// Mode offline ou livre local → Tauri
|
||||
seriesWorldId = await tauri.addSeriesWorld(seriesWorldData);
|
||||
} else {
|
||||
// Mode online → Serveur
|
||||
seriesWorldId = await System.authPostToServer<string>('series/world/add', {
|
||||
@@ -486,7 +481,7 @@ export function useWorlds(config: UseWorldsConfig): UseWorldsReturn {
|
||||
}, userToken, lang);
|
||||
// Si la série a une copie locale → addToQueue
|
||||
if (localSyncedSeries.find((s: SyncedSeries): boolean => s.id === bookSeriesId)) {
|
||||
addToQueue('db:series:world:add', {...seriesWorldData, id: seriesWorldId});
|
||||
addToQueue('add_series_world', {data: {...seriesWorldData, id: seriesWorldId}});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -501,14 +496,14 @@ export function useWorlds(config: UseWorldsConfig): UseWorldsReturn {
|
||||
|
||||
let updateResponse: boolean;
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
// Mode offline ou livre local → IPC
|
||||
updateResponse = await window.electron.invoke<boolean>('db:book:world:update', updateData);
|
||||
// Mode offline ou livre local → Tauri
|
||||
updateResponse = await tauri.updateWorld(updateData.world || updateData);
|
||||
} else {
|
||||
// Mode online → Serveur
|
||||
updateResponse = await System.authPostToServer<boolean>('book/world/update', updateData, userToken, lang);
|
||||
// Si le livre a une copie locale → addToQueue
|
||||
if (localSyncedBooks.find((sb: SyncedBook): boolean => sb.id === entityId)) {
|
||||
addToQueue('db:book:world:update', updateData);
|
||||
addToQueue('update_world', {data: updateData});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -567,14 +562,14 @@ export function useWorlds(config: UseWorldsConfig): UseWorldsReturn {
|
||||
|
||||
let worldId: string;
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
// Mode offline ou livre local → IPC
|
||||
worldId = await window.electron.invoke<string>('db:book:world:add', requestData);
|
||||
// Mode offline ou livre local → Tauri
|
||||
worldId = await tauri.addWorld(requestData.bookId || entityId, requestData.worldName, requestData.id, requestData.seriesWorldId);
|
||||
} else {
|
||||
// Mode online → Serveur
|
||||
worldId = await System.authPostToServer<string>('book/world/add', requestData, userToken, lang);
|
||||
// Si le livre a une copie locale → addToQueue
|
||||
if (localSyncedBooks.find((sb: SyncedBook): boolean => sb.id === entityId)) {
|
||||
addToQueue('db:book:world:add', {...requestData, id: worldId});
|
||||
addToQueue('add_world', {data: {...requestData, id: worldId}});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user