mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-27 09:46:25 +02:00
refactor(desktop): extract IPC channels and handlers into src/ipc/
This commit is contained in:
parent
b6a7f0afa7
commit
fb4dbf04ae
3 changed files with 28 additions and 16 deletions
6
surfsense_desktop/src/ipc/channels.ts
Normal file
6
surfsense_desktop/src/ipc/channels.ts
Normal 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;
|
||||
19
surfsense_desktop/src/ipc/handlers.ts
Normal file
19
surfsense_desktop/src/ipc/handlers.ts
Normal 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();
|
||||
});
|
||||
}
|
||||
|
|
@ -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 () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue