-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
59 lines (47 loc) · 1.88 KB
/
main.js
File metadata and controls
59 lines (47 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const { app, BrowserWindow, session } = require('electron');
const path = require('path');
const { ElectronBlocker } = require('@cliqz/adblocker-electron');
app.disableHardwareAcceleration();
let mainWindow;
async function createWindow() {
const fetch = (await import('node-fetch')).default;
mainWindow = new BrowserWindow({
width: 1200,
height: 800,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
nodeIntegration: true,
contextIsolation: false
},
icon: __dirname + "/icon.png",
frame: true,
});
// Remove cookies on startup if CLI parameter is activated
if (process.argv.includes('--clear-cookies')) {
session.defaultSession.clearStorageData({ storages: ['cookies'] }).then(() => {
console.log('Cookies cleared');
}).catch((error) => {
console.error('Failed to clear cookies:', error);
});
}
// Set a valid user agent
const userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36';
mainWindow.webContents.setUserAgent(userAgent);
// Allow certain URLs to open new windows
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
return { action: 'allow' };
});
// Load SoundCloud
mainWindow.loadURL('https://soundcloud.com');
// Apply adblocker to prevent ads
ElectronBlocker.fromPrebuiltAdsAndTracking(fetch).then((blocker) => {
blocker.enableBlockingInSession(session.defaultSession);
});
mainWindow.webContents.on('did-fail-load', (event, errorCode, errorDescription, validatedURL) => {
console.log(`Failed to load ${validatedURL}: ${errorDescription} (${errorCode})`);
});
mainWindow.on('closed', function () {
mainWindow = null;
});
}
app.on('ready', createWindow);