Actually fix the code.

This commit is contained in:
Sam Sneed 2024-08-12 15:16:12 -05:00
parent 84f489be00
commit 039b5b14c8
3 changed files with 7443 additions and 6 deletions

25
main.js
View file

@ -3,18 +3,32 @@ const {app, BrowserWindow, session, ipcMain} = require('electron')
const path = require('path') const path = require('path')
const fetch = require("cross-fetch") const fetch = require("cross-fetch")
const { ElectronChromeExtensions } = require('electron-chrome-extensions') const { ElectronChromeExtensions } = require('electron-chrome-extensions')
const { ElectronBlocker } = require('@cliqz/adblocker-electron');
ipcMain.on('windowmaker', (event, arg) => { ipcMain.on('windowmaker', (event, arg) => {
createWindow(); createWindow();
}) })
function createWindow () {
// Create the browser window.
const extensions = new ElectronChromeExtensions({ //Function to enable AD Blocking and extensions...
session: session.defaultSession let blocker = undefined
let extensions = undefined
async function enableGoodies(s) {
blocker = await ElectronBlocker.fromLists(fetch, [
'https://easylist.to/easylist/easylist.txt',
'https://secure.fanboy.co.nz/fanboy-annoyance.txt',
'https://easylist.to/easylist/easyprivacy.txt',
'https://easylist-downloads.adblockplus.org/antiadblockfilters.txt',
'https://raw.githubusercontent.com/hoshsadiq/adblock-nocoin-list/master/nocoin.txt',
'https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/adblock/pro.plus.txt'
])
blocker.enableBlockingInSession(s);
extensions = new ElectronChromeExtensions({
session: s
}) })
}
function createWindow () {
const mainWindow = new BrowserWindow({ const mainWindow = new BrowserWindow({
width: 1000, width: 1000,
height: 600, height: 600,
@ -101,8 +115,6 @@ const regexPatterns = [
return callback({}) return callback({})
}) })
extensions.addTab(mainWindow.webContents, mainWindow)
// and load the index.html of the app. // and load the index.html of the app.
mainWindow.loadFile('index.html') mainWindow.loadFile('index.html')
@ -117,6 +129,7 @@ const regexPatterns = [
// Some APIs can only be used after this event occurs. // Some APIs can only be used after this event occurs.
app.whenReady().then(() => { app.whenReady().then(() => {
let x = createWindow() let x = createWindow()
enableGoodies().then()
app.on('activate', function () { app.on('activate', function () {
// On macOS it's common to re-create a window in the app when the // On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open. // dock icon is clicked and there are no other windows open.

7423
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -30,6 +30,7 @@
"electron-packager": "^17.1.2" "electron-packager": "^17.1.2"
}, },
"dependencies": { "dependencies": {
"@cliqz/adblocker-electron": "^1.31.3",
"cross-fetch": "^3.1.5", "cross-fetch": "^3.1.5",
"electron-chrome-extensions": "^3.10.0", "electron-chrome-extensions": "^3.10.0",
"electron-squirrel-startup": "^1.0.1", "electron-squirrel-startup": "^1.0.1",