mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-04 14:22:09 +03:00
fix: improve Electron security and functionality
- Add window control IPC handlers (minimize, maximize, close) - Add URL validation for open-external to prevent security issues - Add single instance lock to prevent multiple app instances - Add deep link protocol support (omniroute://) Refs: #149
This commit is contained in:
@@ -10,6 +10,21 @@ const path = require('path');
|
||||
const { spawn } = require('child_process');
|
||||
const fs = require('fs');
|
||||
|
||||
// Single instance lock - prevent multiple instances
|
||||
const gotTheLock = app.requestSingleInstanceLock();
|
||||
if (!gotTheLock) {
|
||||
app.quit();
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
app.on('second-instance', () => {
|
||||
if (mainWindow) {
|
||||
if (mainWindow.isMinimized()) mainWindow.restore();
|
||||
mainWindow.show();
|
||||
mainWindow.focus();
|
||||
}
|
||||
});
|
||||
|
||||
// Environment detection
|
||||
const isDev = process.env.NODE_ENV === 'development' || !app.isPackaged;
|
||||
const isProduction = !isDev;
|
||||
@@ -224,7 +239,14 @@ function setupIpcHandlers() {
|
||||
|
||||
// Open external URL
|
||||
ipcMain.handle('open-external', (event, url) => {
|
||||
shell.openExternal(url);
|
||||
try {
|
||||
const parsedUrl = new URL(url);
|
||||
if (['http:', 'https:'].includes(parsedUrl.protocol)) {
|
||||
shell.openExternal(url);
|
||||
}
|
||||
} catch {
|
||||
console.error('Invalid URL:', url);
|
||||
}
|
||||
});
|
||||
|
||||
// Get data directory
|
||||
@@ -240,6 +262,25 @@ function setupIpcHandlers() {
|
||||
startNextServer();
|
||||
return { success: true };
|
||||
});
|
||||
|
||||
// Window controls
|
||||
ipcMain.on('window-minimize', () => {
|
||||
mainWindow?.minimize();
|
||||
});
|
||||
|
||||
ipcMain.on('window-maximize', () => {
|
||||
if (mainWindow) {
|
||||
if (mainWindow.isMaximized()) {
|
||||
mainWindow.unmaximize();
|
||||
} else {
|
||||
mainWindow.maximize();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.on('window-close', () => {
|
||||
mainWindow?.close();
|
||||
});
|
||||
}
|
||||
|
||||
// App lifecycle events
|
||||
|
||||
@@ -24,6 +24,12 @@
|
||||
"appId": "online.omniroute.desktop",
|
||||
"productName": "OmniRoute",
|
||||
"copyright": "Copyright © 2025 OmniRoute",
|
||||
"protocols": [
|
||||
{
|
||||
"name": "OmniRoute",
|
||||
"schemes": ["omniroute"]
|
||||
}
|
||||
],
|
||||
"directories": {
|
||||
"output": "dist-electron",
|
||||
"buildResources": "assets"
|
||||
|
||||
Reference in New Issue
Block a user