74 lines
No EOL
2.1 KiB
JavaScript
74 lines
No EOL
2.1 KiB
JavaScript
/**
|
|
* Sneedium Browser - Main Process
|
|
*
|
|
* This is the main entry point for the Electron application.
|
|
* It initializes all necessary modules and manages application lifecycle.
|
|
*/
|
|
|
|
const { app, BrowserWindow, ipcMain, session } = require('electron');
|
|
const http = require('http');
|
|
const { createProxy } = require('proxy');
|
|
|
|
// Import our modular components
|
|
const initExtensionManager = require('./extension-manager');
|
|
const initAdBlocker = require('./ad-blocker');
|
|
const initWindowManager = require('./window-manager');
|
|
|
|
// Create HTTP proxy server
|
|
const proxy = createProxy(http.createServer());
|
|
proxy.listen(3129);
|
|
|
|
// Initialize our modules
|
|
const extensionManager = initExtensionManager();
|
|
const adBlocker = initAdBlocker(session.defaultSession);
|
|
const windowManager = initWindowManager(adBlocker, extensionManager);
|
|
|
|
// Handle IPC messages from renderer process
|
|
setupIpcHandlers();
|
|
|
|
/**
|
|
* Set up IPC handlers for renderer process
|
|
*/
|
|
function setupIpcHandlers() {
|
|
// Create a new window when requested
|
|
ipcMain.on('windowmaker', () => {
|
|
windowManager.createWindow();
|
|
});
|
|
|
|
// Request media access permissions
|
|
ipcMain.on('allowCam', () => {
|
|
windowManager.setMediaAccess();
|
|
});
|
|
}
|
|
|
|
// This method will be called when Electron has finished initialization
|
|
// and is ready to create browser windows.
|
|
app.whenReady().then(() => {
|
|
// Create main window
|
|
const mainWindow = windowManager.createWindow();
|
|
|
|
// Enable ad blocking
|
|
adBlocker.enableAdBlocking(session.defaultSession).then(() => {
|
|
console.log("Ad blocking enabled");
|
|
}).catch(error => {
|
|
console.error("Error enabling ad blocking:", error);
|
|
});
|
|
|
|
// On macOS it's common to re-create a window when the
|
|
// dock icon is clicked and there are no other windows open
|
|
app.on('activate', function () {
|
|
if (BrowserWindow.getAllWindows().length === 0) windowManager.createWindow();
|
|
});
|
|
});
|
|
|
|
// Quit when all windows are closed, except on macOS
|
|
app.on('window-all-closed', function () {
|
|
if (process.platform !== 'darwin') {
|
|
app.quit();
|
|
}
|
|
});
|
|
|
|
// Set up DNS configuration when app is ready
|
|
app.on('ready', () => {
|
|
windowManager.setupDnsConfig();
|
|
}); |