refactor(desktop): extract IPC channels and handlers into src/ipc/

This commit is contained in:
CREDO23 2026-03-20 20:06:21 +02:00
parent b6a7f0afa7
commit fb4dbf04ae
3 changed files with 28 additions and 16 deletions

View file

@ -0,0 +1,6 @@
export const IPC_CHANNELS = {
OPEN_EXTERNAL: 'open-external',
GET_APP_VERSION: 'get-app-version',
DEEP_LINK: 'deep-link',
GET_CLIPBOARD_CONTENT: 'get-clipboard-content',
} as const;

View file

@ -0,0 +1,19 @@
import { app, ipcMain, shell } from 'electron';
import { IPC_CHANNELS } from './channels';
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();
});
}

View file

@ -1,10 +1,11 @@
import { app, BrowserWindow, shell, ipcMain } from 'electron';
import { app, BrowserWindow } from 'electron';
import { registerGlobalErrorHandlers, showErrorDialog } from './modules/errors';
import { startNextServer } from './modules/server';
import { createMainWindow } from './modules/window';
import { setupDeepLinks, handlePendingDeepLink } from './modules/deep-links';
import { setupAutoUpdater } from './modules/auto-updater';
import { setupMenu } from './modules/menu';
import { registerIpcHandlers } from './ipc/handlers';
registerGlobalErrorHandlers();
@ -12,21 +13,7 @@ if (!setupDeepLinks()) {
app.quit();
}
// IPC handlers
ipcMain.on('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('get-app-version', () => {
return app.getVersion();
});
registerIpcHandlers();
// App lifecycle
app.whenReady().then(async () => {