mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-30 03:16:25 +02:00
92 lines
2.4 KiB
TypeScript
92 lines
2.4 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';
|
|
|
|
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)
|
|
);
|
|
}
|