118 lines
4.2 KiB
TypeScript
118 lines
4.2 KiB
TypeScript
import electron from 'electron';
|
|
import type { BrowserWindow } from 'electron';
|
|
const { ipcMain, dialog } = electron;
|
|
import type { NoteRepository } from '../repository/NoteRepository.js';
|
|
import type { ContinuityService } from '../services/ContinuityService.js';
|
|
import type { CaptureService } from '../services/CaptureService.js';
|
|
import type { HealthChecker } from '../services/HealthChecker.js';
|
|
import type { IntentService } from '../services/IntentService.js';
|
|
import type { Note } from '@shared/types';
|
|
|
|
export interface InboxIpcDeps {
|
|
repo: NoteRepository;
|
|
continuity: ContinuityService;
|
|
capture: CaptureService;
|
|
health: HealthChecker;
|
|
intent: IntentService;
|
|
getInboxWindow: () => BrowserWindow | null;
|
|
}
|
|
|
|
export function registerInboxApi(deps: InboxIpcDeps): void {
|
|
ipcMain.handle('inbox:list', (_e, opts: { limit: number; cursor?: string }) =>
|
|
deps.repo.list(opts)
|
|
);
|
|
|
|
ipcMain.handle(
|
|
'inbox:updateAi',
|
|
(_e, arg: { noteId: string; fields: { title?: string; summary?: string; tags?: string[] } }) => {
|
|
deps.repo.updateUserAiFields(arg.noteId, arg.fields);
|
|
}
|
|
);
|
|
|
|
ipcMain.handle('inbox:setDueDate', (_e, arg: { noteId: string; date: string | null }) => {
|
|
deps.repo.setDueDate(arg.noteId, arg.date);
|
|
});
|
|
|
|
ipcMain.handle('inbox:delete', async (_e, noteId: string) => {
|
|
await deps.capture.deleteNote(noteId);
|
|
});
|
|
|
|
ipcMain.handle(
|
|
'inbox:setIntent',
|
|
(_e, arg: { noteId: string; text: string }) => {
|
|
deps.intent.setIntent(arg.noteId, arg.text);
|
|
}
|
|
);
|
|
|
|
ipcMain.handle('inbox:dismissIntent', (_e, noteId: string) => {
|
|
deps.intent.dismissIntent(noteId);
|
|
});
|
|
|
|
ipcMain.handle('inbox:continuity', () => deps.continuity.get());
|
|
ipcMain.handle('inbox:pendingCount', () => deps.repo.getPendingCount());
|
|
ipcMain.handle('inbox:ollamaStatus', () => deps.health.lastStatus());
|
|
ipcMain.handle('inbox:todayCount', () => deps.repo.countToday());
|
|
|
|
ipcMain.handle('inbox:restore', async (_e, noteId: string) => {
|
|
await deps.capture.restoreNote(noteId);
|
|
});
|
|
|
|
ipcMain.handle('inbox:permanentDelete', async (_e, noteId: string) => {
|
|
const win = deps.getInboxWindow();
|
|
const opts: Electron.MessageBoxOptions = {
|
|
type: 'question',
|
|
buttons: ['영구 삭제', '취소'],
|
|
defaultId: 1,
|
|
cancelId: 1,
|
|
title: 'Inkling',
|
|
message: '이 노트를 영구 삭제합니다',
|
|
detail: '이 작업은 되돌릴 수 없습니다. 첨부된 이미지도 함께 삭제됩니다.'
|
|
};
|
|
const r = win
|
|
? await dialog.showMessageBox(win, opts)
|
|
: await dialog.showMessageBox(opts);
|
|
if (r.response !== 0) return { confirmed: false };
|
|
await deps.capture.permanentDeleteNote(noteId);
|
|
return { confirmed: true };
|
|
});
|
|
|
|
ipcMain.handle('inbox:emptyTrash', async () => {
|
|
// limit 200 한 번 — UI 표시 cap. count > 200 시 dialog message 만 부정확하지만
|
|
// emptyTrash() 내부 SQL 은 LIMIT 없으므로 실제 삭제는 모든 trash 노트 적용.
|
|
// v0.2.4 에서 repo.countTrashed() 추가 시 둘 다 정확해짐.
|
|
const trashed = deps.repo.listTrashed({ limit: 200 });
|
|
if (trashed.length === 0) return { confirmed: true, count: 0 };
|
|
const fullCount = trashed.length;
|
|
const win = deps.getInboxWindow();
|
|
const opts: Electron.MessageBoxOptions = {
|
|
type: 'question',
|
|
buttons: ['휴지통 비우기', '취소'],
|
|
defaultId: 1,
|
|
cancelId: 1,
|
|
title: 'Inkling',
|
|
message: `휴지통의 노트 ${fullCount}개를 영구 삭제합니다`,
|
|
detail: '이 작업은 되돌릴 수 없습니다. 첨부된 이미지도 함께 삭제됩니다.'
|
|
};
|
|
const r = win
|
|
? await dialog.showMessageBox(win, opts)
|
|
: await dialog.showMessageBox(opts);
|
|
if (r.response !== 0) return { confirmed: false, count: 0 };
|
|
const result = await deps.capture.emptyTrash();
|
|
return { confirmed: true, count: result.count };
|
|
});
|
|
|
|
ipcMain.handle('inbox:listTrash', (_e, opts: { limit: number }) =>
|
|
deps.repo.listTrashed(opts)
|
|
);
|
|
|
|
ipcMain.handle('inbox:trashCount', () =>
|
|
deps.repo.listTrashed({ limit: 200 }).length
|
|
);
|
|
}
|
|
|
|
export function pushNoteUpdated(getWin: () => BrowserWindow | null, note: Note): void {
|
|
const w = getWin();
|
|
if (!w || w.isDestroyed()) return;
|
|
w.webContents.send('note:updated', note);
|
|
}
|