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 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 ActProps {
|
||||
acts: ActType[];
|
||||
@@ -80,10 +81,7 @@ export default function Act({acts, setActs, mainChapters}: ActProps) {
|
||||
try {
|
||||
let incidentId: string;
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
incidentId = await window.electron.invoke<string>('db:book:incident:add', {
|
||||
bookId,
|
||||
name: newIncidentTitle,
|
||||
});
|
||||
incidentId = await tauri.addIncident(bookId!, newIncidentTitle);
|
||||
} else {
|
||||
incidentId = await System.authPostToServer<string>('book/incident/new', {
|
||||
bookId,
|
||||
@@ -91,11 +89,11 @@ export default function Act({acts, setActs, mainChapters}: ActProps) {
|
||||
}, token, lang);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === bookId)) {
|
||||
addToQueue('db:book:incident:add', {
|
||||
addToQueue('add_incident', {data: {
|
||||
bookId,
|
||||
incidentId,
|
||||
name: newIncidentTitle,
|
||||
});
|
||||
}});
|
||||
}
|
||||
}
|
||||
if (!incidentId) {
|
||||
@@ -134,12 +132,12 @@ export default function Act({acts, setActs, mainChapters}: ActProps) {
|
||||
let response: boolean;
|
||||
const deleteData = { bookId, incidentId, deletedAt: System.timeStampInSeconds() };
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await window.electron.invoke<boolean>('db:book:incident:remove', deleteData);
|
||||
response = await tauri.removeIncident(deleteData.bookId!, deleteData.incidentId, deleteData.deletedAt);
|
||||
} else {
|
||||
response = await System.authDeleteToServer<boolean>('book/incident/remove', deleteData, token, lang);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === bookId)) {
|
||||
addToQueue('db:book:incident:remove', deleteData);
|
||||
addToQueue('remove_incident', {data: deleteData});
|
||||
}
|
||||
}
|
||||
if (!response) {
|
||||
@@ -177,15 +175,15 @@ export default function Act({acts, setActs, mainChapters}: ActProps) {
|
||||
incidentId: selectedIncidentId,
|
||||
};
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
plotId = await window.electron.invoke<string>('db:book:plot:add', plotData);
|
||||
plotId = await tauri.addPlotPoint(plotData.bookId!, plotData.name, plotData.incidentId);
|
||||
} else {
|
||||
plotId = await System.authPostToServer<string>('book/plot/new', plotData, token, lang);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === bookId)) {
|
||||
addToQueue('db:book:plot:add', {
|
||||
addToQueue('add_plot_point', {data: {
|
||||
...plotData,
|
||||
plotId,
|
||||
});
|
||||
}});
|
||||
}
|
||||
}
|
||||
if (!plotId) {
|
||||
@@ -225,12 +223,12 @@ export default function Act({acts, setActs, mainChapters}: ActProps) {
|
||||
let response: boolean;
|
||||
const deleteData = { plotId: plotPointId, bookId, deletedAt: System.timeStampInSeconds() };
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await window.electron.invoke<boolean>('db:book:plot:remove', deleteData);
|
||||
response = await tauri.removePlotPoint(deleteData.plotId, deleteData.bookId!, deleteData.deletedAt);
|
||||
} else {
|
||||
response = await System.authDeleteToServer<boolean>('book/plot/remove', deleteData, token, lang);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === bookId)) {
|
||||
addToQueue('db:book:plot:remove', deleteData);
|
||||
addToQueue('remove_plot_point', {data: deleteData});
|
||||
}
|
||||
}
|
||||
if (!response) {
|
||||
@@ -279,15 +277,15 @@ export default function Act({acts, setActs, mainChapters}: ActProps) {
|
||||
incidentId: destination === 'incident' ? itemId : null,
|
||||
};
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
linkId = await window.electron.invoke<string>('db:chapter:information:add', linkData);
|
||||
linkId = await tauri.addChapterInformation(linkData as any);
|
||||
} else {
|
||||
linkId = await System.authPostToServer<string>('chapter/resume/add', linkData, token, lang);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === bookId)) {
|
||||
addToQueue('db:chapter:information:add', {
|
||||
addToQueue('add_chapter_information', {data: {
|
||||
...linkData,
|
||||
chapterInfoId: linkId,
|
||||
});
|
||||
}});
|
||||
}
|
||||
}
|
||||
if (!linkId) {
|
||||
@@ -367,12 +365,12 @@ export default function Act({acts, setActs, mainChapters}: ActProps) {
|
||||
let response: boolean;
|
||||
const unlinkData = { chapterInfoId, bookId, deletedAt: System.timeStampInSeconds() };
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await window.electron.invoke<boolean>('db:chapter:information:remove', unlinkData);
|
||||
response = await tauri.removeChapterInformation(unlinkData.chapterInfoId, unlinkData.bookId!, unlinkData.deletedAt);
|
||||
} else {
|
||||
response = await System.authDeleteToServer<boolean>('chapter/resume/remove', unlinkData, token, lang);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === bookId)) {
|
||||
addToQueue('db:chapter:information:remove', unlinkData);
|
||||
addToQueue('remove_chapter_information', {data: unlinkData});
|
||||
}
|
||||
}
|
||||
if (!response) {
|
||||
|
||||
@@ -13,6 +13,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 IssuesProps {
|
||||
issues: Issue[];
|
||||
@@ -42,10 +43,7 @@ export default function Issues({issues, setIssues}: IssuesProps) {
|
||||
try {
|
||||
let issueId: string;
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
issueId = await window.electron.invoke<string>('db:book:issue:add', {
|
||||
bookId,
|
||||
name: newIssueName,
|
||||
});
|
||||
issueId = await tauri.addIssue(bookId!, newIssueName);
|
||||
} else {
|
||||
issueId = await System.authPostToServer<string>('book/issue/add', {
|
||||
bookId,
|
||||
@@ -53,11 +51,11 @@ export default function Issues({issues, setIssues}: IssuesProps) {
|
||||
}, token, lang);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === bookId)) {
|
||||
addToQueue('db:book:issue:add', {
|
||||
addToQueue('add_issue', {data: {
|
||||
bookId,
|
||||
issueId,
|
||||
name: newIssueName,
|
||||
});
|
||||
}});
|
||||
}
|
||||
}
|
||||
if (!issueId) {
|
||||
@@ -90,11 +88,7 @@ export default function Issues({issues, setIssues}: IssuesProps) {
|
||||
let response: boolean;
|
||||
const deletedAt: number = System.timeStampInSeconds();
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await window.electron.invoke<boolean>('db:book:issue:remove', {
|
||||
bookId,
|
||||
issueId,
|
||||
deletedAt,
|
||||
});
|
||||
response = await tauri.removeIssue(bookId!, issueId, deletedAt);
|
||||
} else {
|
||||
response = await System.authDeleteToServer<boolean>(
|
||||
'book/issue/remove',
|
||||
@@ -108,11 +102,11 @@ export default function Issues({issues, setIssues}: IssuesProps) {
|
||||
);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === bookId)) {
|
||||
addToQueue('db:book:issue:remove', {
|
||||
addToQueue('remove_issue', {data: {
|
||||
bookId,
|
||||
issueId,
|
||||
deletedAt,
|
||||
});
|
||||
}});
|
||||
}
|
||||
}
|
||||
if (response) {
|
||||
|
||||
@@ -16,6 +16,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 MainChapterProps {
|
||||
chapters: ChapterListProps[];
|
||||
@@ -93,12 +94,12 @@ export default function MainChapter({chapters, setChapters}: MainChapterProps) {
|
||||
deletedAt,
|
||||
};
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await window.electron.invoke<boolean>('db:chapter:remove', deleteData);
|
||||
response = await tauri.removeChapter(deleteData.chapterId, deleteData.bookId!, deleteData.deletedAt);
|
||||
} else {
|
||||
response = await System.authDeleteToServer<boolean>('chapter/remove', deleteData, token, lang);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === bookId)) {
|
||||
addToQueue('db:chapter:remove', deleteData);
|
||||
addToQueue('remove_chapter', {data: deleteData});
|
||||
}
|
||||
}
|
||||
if (!response) {
|
||||
@@ -129,15 +130,15 @@ export default function MainChapter({chapters, setChapters}: MainChapterProps) {
|
||||
title: newChapterTitle,
|
||||
};
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
responseId = await window.electron.invoke<string>('db:chapter:add', chapterData);
|
||||
responseId = await tauri.addChapter(chapterData);
|
||||
} else {
|
||||
responseId = await System.authPostToServer<string>('chapter/add', chapterData, token);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === bookId)) {
|
||||
addToQueue('db:chapter:add', {
|
||||
addToQueue('add_chapter', {data: {
|
||||
...chapterData,
|
||||
chapterId: responseId,
|
||||
});
|
||||
}});
|
||||
}
|
||||
}
|
||||
if (!responseId) {
|
||||
|
||||
@@ -16,6 +16,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';
|
||||
|
||||
export const StoryContext = createContext<{
|
||||
acts: ActType[];
|
||||
@@ -76,16 +77,12 @@ export function Story(props: any, ref: any) {
|
||||
async function getStoryData(): Promise<void> {
|
||||
try {
|
||||
let response: StoryFetchData;
|
||||
if (isCurrentlyOffline()) {
|
||||
response = await window.electron.invoke<StoryFetchData>('db:book:story:get', {bookid: bookId});
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await tauri.getBookStory(bookId) as StoryFetchData;
|
||||
} else {
|
||||
if (book?.localBook) {
|
||||
response = await window.electron.invoke<StoryFetchData>('db:book:story:get', {bookid: bookId});
|
||||
} else {
|
||||
response = await System.authGetQueryToServer<StoryFetchData>(`book/story`, userToken, lang, {
|
||||
bookid: bookId,
|
||||
});
|
||||
}
|
||||
response = await System.authGetQueryToServer<StoryFetchData>(`book/story`, userToken, lang, {
|
||||
bookid: bookId,
|
||||
});
|
||||
}
|
||||
if (response) {
|
||||
setActs(response.acts);
|
||||
@@ -143,12 +140,12 @@ export function Story(props: any, ref: any) {
|
||||
issues,
|
||||
};
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await window.electron.invoke<boolean>('db:book:story:update', storyData);
|
||||
response = await tauri.updateBookStory(storyData);
|
||||
} else {
|
||||
response = await System.authPostToServer<boolean>('book/story', storyData, userToken, lang);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === bookId)) {
|
||||
addToQueue('db:book:story:update', storyData);
|
||||
addToQueue('update_book_story', {data: storyData});
|
||||
}
|
||||
}
|
||||
if (!response) {
|
||||
|
||||
Reference in New Issue
Block a user