- Replace absolute import paths with relative paths for consistency across files. - Transition database operations in Electron main process to modular handlers in `ipc/book.ipc.ts` using the `createHandler` pattern. - Update database sync service to use `window.electron.invoke()` for improved reliability and structure. - Refactor `AddNewBookForm` to handle both online and offline book creation seamlessly.
53 lines
1.3 KiB
TypeScript
53 lines
1.3 KiB
TypeScript
/**
|
|
* Sync progress interface
|
|
*/
|
|
export interface SyncProgress {
|
|
isSyncing: boolean;
|
|
pendingChanges: number;
|
|
isOnline: boolean;
|
|
lastError?: string;
|
|
}
|
|
|
|
/**
|
|
* Get sync status from local database
|
|
*/
|
|
export async function getSyncStatus(): Promise<SyncProgress> {
|
|
if (!window.electron) {
|
|
return {
|
|
isSyncing: false,
|
|
pendingChanges: 0,
|
|
isOnline: navigator.onLine
|
|
};
|
|
}
|
|
|
|
try {
|
|
const result = await window.electron.invoke<SyncProgress>('db:sync:status');
|
|
return result;
|
|
} catch (error) {
|
|
console.error('Failed to get sync status:', error);
|
|
return {
|
|
isSyncing: false,
|
|
pendingChanges: 0,
|
|
isOnline: navigator.onLine,
|
|
lastError: error instanceof Error ? error.message : 'Unknown error'
|
|
};
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get pending changes to sync
|
|
*/
|
|
export async function getPendingChanges(limit: number = 100) {
|
|
if (!window.electron) {
|
|
return [];
|
|
}
|
|
|
|
try {
|
|
const result = await window.electron.invoke<any[]>('db:sync:pending-changes', limit);
|
|
return result || [];
|
|
} catch (error) {
|
|
console.error('Failed to get pending changes:', error);
|
|
return [];
|
|
}
|
|
}
|