mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-11 16:52:38 +02:00
- Introduced IPC channels for getting and setting the active search space, enhancing user experience across the application. - Updated the preload script to expose new API methods for active search space management. - Modified the main window and quick ask functionalities to sync the active search space based on user navigation. - Enhanced the desktop and web applications to allow users to select and manage their default search space seamlessly. - Implemented automatic synchronization of the active search space during login and navigation events.
123 lines
3.7 KiB
TypeScript
123 lines
3.7 KiB
TypeScript
import { app, ipcMain, shell } from 'electron';
|
|
import { IPC_CHANNELS } from './channels';
|
|
import {
|
|
getPermissionsStatus,
|
|
requestAccessibility,
|
|
requestScreenRecording,
|
|
restartApp,
|
|
} from '../modules/permissions';
|
|
import {
|
|
selectFolder,
|
|
addWatchedFolder,
|
|
removeWatchedFolder,
|
|
getWatchedFolders,
|
|
getWatcherStatus,
|
|
getPendingFileEvents,
|
|
acknowledgeFileEvents,
|
|
pauseWatcher,
|
|
resumeWatcher,
|
|
markRendererReady,
|
|
browseFiles,
|
|
readLocalFiles,
|
|
} from '../modules/folder-watcher';
|
|
import { getShortcuts, setShortcuts, type ShortcutConfig } from '../modules/shortcuts';
|
|
import { getActiveSearchSpaceId, setActiveSearchSpaceId } from '../modules/active-search-space';
|
|
import { reregisterQuickAsk } from '../modules/quick-ask';
|
|
import { reregisterAutocomplete } from '../modules/autocomplete';
|
|
import { reregisterGeneralAssist } from '../modules/tray';
|
|
|
|
let authTokens: { bearer: string; refresh: string } | null = null;
|
|
|
|
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();
|
|
});
|
|
|
|
ipcMain.handle(IPC_CHANNELS.GET_PERMISSIONS_STATUS, () => {
|
|
return getPermissionsStatus();
|
|
});
|
|
|
|
ipcMain.handle(IPC_CHANNELS.REQUEST_ACCESSIBILITY, () => {
|
|
requestAccessibility();
|
|
});
|
|
|
|
ipcMain.handle(IPC_CHANNELS.REQUEST_SCREEN_RECORDING, () => {
|
|
requestScreenRecording();
|
|
});
|
|
|
|
ipcMain.handle(IPC_CHANNELS.RESTART_APP, () => {
|
|
restartApp();
|
|
});
|
|
|
|
// 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());
|
|
|
|
ipcMain.handle(IPC_CHANNELS.FOLDER_SYNC_RENDERER_READY, () => {
|
|
markRendererReady();
|
|
});
|
|
|
|
ipcMain.handle(IPC_CHANNELS.FOLDER_SYNC_GET_PENDING_EVENTS, () =>
|
|
getPendingFileEvents()
|
|
);
|
|
|
|
ipcMain.handle(IPC_CHANNELS.FOLDER_SYNC_ACK_EVENTS, (_event, eventIds: string[]) =>
|
|
acknowledgeFileEvents(eventIds)
|
|
);
|
|
|
|
ipcMain.handle(IPC_CHANNELS.BROWSE_FILES, () => browseFiles());
|
|
|
|
ipcMain.handle(IPC_CHANNELS.READ_LOCAL_FILES, (_event, paths: string[]) =>
|
|
readLocalFiles(paths)
|
|
);
|
|
|
|
ipcMain.handle(IPC_CHANNELS.SET_AUTH_TOKENS, (_event, tokens: { bearer: string; refresh: string }) => {
|
|
authTokens = tokens;
|
|
});
|
|
|
|
ipcMain.handle(IPC_CHANNELS.GET_AUTH_TOKENS, () => {
|
|
return authTokens;
|
|
});
|
|
|
|
ipcMain.handle(IPC_CHANNELS.GET_SHORTCUTS, () => getShortcuts());
|
|
|
|
ipcMain.handle(IPC_CHANNELS.GET_ACTIVE_SEARCH_SPACE, () => getActiveSearchSpaceId());
|
|
|
|
ipcMain.handle(IPC_CHANNELS.SET_ACTIVE_SEARCH_SPACE, (_event, id: string) =>
|
|
setActiveSearchSpaceId(id)
|
|
);
|
|
|
|
ipcMain.handle(IPC_CHANNELS.SET_SHORTCUTS, async (_event, config: Partial<ShortcutConfig>) => {
|
|
const updated = await setShortcuts(config);
|
|
if (config.generalAssist) await reregisterGeneralAssist();
|
|
if (config.quickAsk) await reregisterQuickAsk();
|
|
if (config.autocomplete) await reregisterAutocomplete();
|
|
return updated;
|
|
});
|
|
}
|