2026-03-20 20:06:21 +02:00
|
|
|
import { app, ipcMain, shell } from 'electron';
|
|
|
|
|
import { IPC_CHANNELS } from './channels';
|
2026-04-02 13:26:32 +02:00
|
|
|
import {
|
|
|
|
|
getPermissionsStatus,
|
|
|
|
|
requestAccessibility,
|
2026-04-03 19:57:48 +02:00
|
|
|
requestScreenRecording,
|
2026-04-02 13:26:32 +02:00
|
|
|
restartApp,
|
|
|
|
|
} from '../modules/permissions';
|
2026-04-02 11:17:49 +05:30
|
|
|
import {
|
|
|
|
|
selectFolder,
|
|
|
|
|
addWatchedFolder,
|
|
|
|
|
removeWatchedFolder,
|
|
|
|
|
getWatchedFolders,
|
|
|
|
|
getWatcherStatus,
|
2026-04-03 00:40:49 +05:30
|
|
|
getPendingFileEvents,
|
|
|
|
|
acknowledgeFileEvents,
|
2026-04-02 11:17:49 +05:30
|
|
|
pauseWatcher,
|
|
|
|
|
resumeWatcher,
|
2026-04-02 22:20:11 +05:30
|
|
|
markRendererReady,
|
2026-04-03 02:56:24 +05:30
|
|
|
browseFiles,
|
2026-04-03 00:28:24 +05:30
|
|
|
readLocalFiles,
|
2026-04-08 15:46:52 +05:30
|
|
|
listFolderFiles,
|
2026-04-08 16:07:25 +05:30
|
|
|
seedFolderMtimes,
|
2026-04-08 15:46:52 +05:30
|
|
|
type WatchedFolderConfig,
|
2026-04-02 11:17:49 +05:30
|
|
|
} from '../modules/folder-watcher';
|
2026-04-07 00:43:40 -07:00
|
|
|
import { getShortcuts, setShortcuts, type ShortcutConfig } from '../modules/shortcuts';
|
2026-04-07 04:45:48 -07:00
|
|
|
import { getActiveSearchSpaceId, setActiveSearchSpaceId } from '../modules/active-search-space';
|
2026-04-07 00:43:40 -07:00
|
|
|
import { reregisterQuickAsk } from '../modules/quick-ask';
|
|
|
|
|
import { reregisterAutocomplete } from '../modules/autocomplete';
|
2026-04-07 03:42:46 -07:00
|
|
|
import { reregisterGeneralAssist } from '../modules/tray';
|
2026-03-20 20:06:21 +02:00
|
|
|
|
2026-04-06 23:02:25 -07:00
|
|
|
let authTokens: { bearer: string; refresh: string } | null = null;
|
|
|
|
|
|
2026-03-20 20:06:21 +02:00
|
|
|
export function registerIpcHandlers(): void {
|
|
|
|
|
ipcMain.on(IPC_CHANNELS.OPEN_EXTERNAL, (_event, url: string) => {
|
|
|
|
|
try {
|
|
|
|
|
const parsed = new URL(url);
|
|
|
|
|
if (parsed.protocol === 'http:' || parsed.protocol === 'https:') {
|
|
|
|
|
shell.openExternal(url);
|
|
|
|
|
}
|
|
|
|
|
} catch {
|
|
|
|
|
// invalid URL — ignore
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ipcMain.handle(IPC_CHANNELS.GET_APP_VERSION, () => {
|
|
|
|
|
return app.getVersion();
|
|
|
|
|
});
|
2026-04-02 13:26:32 +02:00
|
|
|
|
|
|
|
|
ipcMain.handle(IPC_CHANNELS.GET_PERMISSIONS_STATUS, () => {
|
|
|
|
|
return getPermissionsStatus();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ipcMain.handle(IPC_CHANNELS.REQUEST_ACCESSIBILITY, () => {
|
|
|
|
|
requestAccessibility();
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-03 19:57:48 +02:00
|
|
|
ipcMain.handle(IPC_CHANNELS.REQUEST_SCREEN_RECORDING, () => {
|
|
|
|
|
requestScreenRecording();
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-02 13:26:32 +02:00
|
|
|
ipcMain.handle(IPC_CHANNELS.RESTART_APP, () => {
|
|
|
|
|
restartApp();
|
|
|
|
|
});
|
2026-04-04 09:15:13 +02:00
|
|
|
|
2026-04-02 11:17:49 +05:30
|
|
|
// Folder sync handlers
|
|
|
|
|
ipcMain.handle(IPC_CHANNELS.FOLDER_SYNC_SELECT_FOLDER, () => selectFolder());
|
|
|
|
|
|
|
|
|
|
ipcMain.handle(IPC_CHANNELS.FOLDER_SYNC_ADD_FOLDER, (_event, config) =>
|
|
|
|
|
addWatchedFolder(config)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
ipcMain.handle(IPC_CHANNELS.FOLDER_SYNC_REMOVE_FOLDER, (_event, folderPath: string) =>
|
|
|
|
|
removeWatchedFolder(folderPath)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
ipcMain.handle(IPC_CHANNELS.FOLDER_SYNC_GET_FOLDERS, () => getWatchedFolders());
|
|
|
|
|
|
|
|
|
|
ipcMain.handle(IPC_CHANNELS.FOLDER_SYNC_GET_STATUS, () => getWatcherStatus());
|
|
|
|
|
|
|
|
|
|
ipcMain.handle(IPC_CHANNELS.FOLDER_SYNC_PAUSE, () => pauseWatcher());
|
|
|
|
|
|
|
|
|
|
ipcMain.handle(IPC_CHANNELS.FOLDER_SYNC_RESUME, () => resumeWatcher());
|
2026-04-02 22:20:11 +05:30
|
|
|
|
|
|
|
|
ipcMain.handle(IPC_CHANNELS.FOLDER_SYNC_RENDERER_READY, () => {
|
|
|
|
|
markRendererReady();
|
|
|
|
|
});
|
2026-04-03 00:28:24 +05:30
|
|
|
|
2026-04-03 00:40:49 +05:30
|
|
|
ipcMain.handle(IPC_CHANNELS.FOLDER_SYNC_GET_PENDING_EVENTS, () =>
|
|
|
|
|
getPendingFileEvents()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
ipcMain.handle(IPC_CHANNELS.FOLDER_SYNC_ACK_EVENTS, (_event, eventIds: string[]) =>
|
|
|
|
|
acknowledgeFileEvents(eventIds)
|
|
|
|
|
);
|
|
|
|
|
|
2026-04-08 15:46:52 +05:30
|
|
|
ipcMain.handle(IPC_CHANNELS.FOLDER_SYNC_LIST_FILES, (_event, config: WatchedFolderConfig) =>
|
|
|
|
|
listFolderFiles(config)
|
|
|
|
|
);
|
|
|
|
|
|
2026-04-08 16:07:25 +05:30
|
|
|
ipcMain.handle(
|
|
|
|
|
IPC_CHANNELS.FOLDER_SYNC_SEED_MTIMES,
|
|
|
|
|
(_event, folderPath: string, mtimes: Record<string, number>) =>
|
|
|
|
|
seedFolderMtimes(folderPath, mtimes),
|
|
|
|
|
);
|
|
|
|
|
|
2026-04-03 02:56:24 +05:30
|
|
|
ipcMain.handle(IPC_CHANNELS.BROWSE_FILES, () => browseFiles());
|
2026-04-03 00:28:24 +05:30
|
|
|
|
|
|
|
|
ipcMain.handle(IPC_CHANNELS.READ_LOCAL_FILES, (_event, paths: string[]) =>
|
|
|
|
|
readLocalFiles(paths)
|
|
|
|
|
);
|
2026-04-06 23:02:25 -07:00
|
|
|
|
|
|
|
|
ipcMain.handle(IPC_CHANNELS.SET_AUTH_TOKENS, (_event, tokens: { bearer: string; refresh: string }) => {
|
|
|
|
|
authTokens = tokens;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ipcMain.handle(IPC_CHANNELS.GET_AUTH_TOKENS, () => {
|
|
|
|
|
return authTokens;
|
|
|
|
|
});
|
2026-04-07 00:43:40 -07:00
|
|
|
|
|
|
|
|
ipcMain.handle(IPC_CHANNELS.GET_SHORTCUTS, () => getShortcuts());
|
|
|
|
|
|
2026-04-07 04:45:48 -07:00
|
|
|
ipcMain.handle(IPC_CHANNELS.GET_ACTIVE_SEARCH_SPACE, () => getActiveSearchSpaceId());
|
|
|
|
|
|
|
|
|
|
ipcMain.handle(IPC_CHANNELS.SET_ACTIVE_SEARCH_SPACE, (_event, id: string) =>
|
|
|
|
|
setActiveSearchSpaceId(id)
|
|
|
|
|
);
|
|
|
|
|
|
2026-04-07 00:43:40 -07:00
|
|
|
ipcMain.handle(IPC_CHANNELS.SET_SHORTCUTS, async (_event, config: Partial<ShortcutConfig>) => {
|
|
|
|
|
const updated = await setShortcuts(config);
|
2026-04-07 03:42:46 -07:00
|
|
|
if (config.generalAssist) await reregisterGeneralAssist();
|
2026-04-07 00:43:40 -07:00
|
|
|
if (config.quickAsk) await reregisterQuickAsk();
|
|
|
|
|
if (config.autocomplete) await reregisterAutocomplete();
|
|
|
|
|
return updated;
|
|
|
|
|
});
|
2026-03-20 20:06:21 +02:00
|
|
|
}
|