Tauri commands reject with a {kind, message} object, not a native Error,
so `e instanceof Error ? e.message : String(e)` always fell through to
String(e) -> "[object Object]", hiding the actual readpst failure reason.
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
// Imported calendar events (Phase 6, FR-CAL-*). Svelte 5 runes store, same
|
|
// shape as settings.svelte.ts/meetings.svelte.ts.
|
|
|
|
import { api, errorMessage, events, type CalendarEvent } from "../api";
|
|
|
|
class CalendarStore {
|
|
events = $state<CalendarEvent[]>([]);
|
|
loaded = $state(false);
|
|
importing = $state(false);
|
|
importProgress = $state<{ processed: number; total: number } | null>(null);
|
|
importError = $state<string | null>(null);
|
|
|
|
async load() {
|
|
try {
|
|
this.events = await api.listCalendarEvents();
|
|
} catch {
|
|
this.events = []; // no .pst imported yet, or command unreachable
|
|
}
|
|
if (!this.loaded) {
|
|
await events.onPstProgress((p) => (this.importProgress = p));
|
|
this.loaded = true;
|
|
}
|
|
}
|
|
|
|
async importPst(path: string, password?: string) {
|
|
this.importing = true;
|
|
this.importError = null;
|
|
this.importProgress = null;
|
|
try {
|
|
await api.importPst(path, password);
|
|
await this.load();
|
|
} catch (e) {
|
|
this.importError = errorMessage(e);
|
|
} finally {
|
|
this.importing = false;
|
|
this.importProgress = null;
|
|
}
|
|
}
|
|
}
|
|
|
|
export const calendar = new CalendarStore();
|