added permissions for website

This commit is contained in:
2024-11-04 11:55:14 -05:00
parent 5c845ffe61
commit 014e4c8b7b
19 changed files with 507 additions and 71 deletions
+15 -10
View File
@@ -4,6 +4,7 @@ import fs from 'fs';
import { findPath } from './paths.js';
import * as tabModule from '../serverJS/tabs_server.js';
import loggermod from '../utils/logger.cjs';
import { getSitePerms, promptForPerms, setSitePerms } from './dialogue.js';
const { logger } = loggermod;
@@ -24,17 +25,19 @@ export default function init(customSession) {
ipcMain.on('tab-close', (e, id) => tabModule.closeTab(e, id, customSession));
ipcMain.on('tab-new', (e, id, url) => tabModule.addTab(e, id, customSession, url));
// TODO: add logic here to save/return site perms
ipcMain.on('set-site-perms', (e, sitehostname) => console.log(sitehostname));
ipcMain.on('get-site-perms', (e, sitehostname) => {
console.log(sitehostname);
e.sender.send('site-perms', { popups: false });
});
ipcMain.on('set-site-perms', (e, sitehostname, id, value) => setSitePerms(e, sitehostname, id, value));
ipcMain.on('set-site-perms-all', (e, sitehostname, id, value) => setSitePerms(e, sitehostname, id, value, true));
ipcMain.on('get-site-perms', getSitePerms);
ipcMain.on('prompt-terms', (e, sitehostname) => promptForPerms(tabModule.getCurrentWindow(), sitehostname));
// TODO: make an actual settings page
ipcMain.on('open-settings', async (e) => promptForPerms(tabModule.getCurrentWindow(), await tabModule.getCurrentTab()?.webContents.executeJavaScript('window.location.hostname')));
}
const renderer = (fs.readFileSync(await findPath('renderer.js'), 'utf-8')),
optimize = (fs.readFileSync(await findPath('optimize.js'), 'utf-8'));
optimize = (fs.readFileSync(await findPath('optimize.js'), 'utf-8')),
adblock = (fs.readFileSync(await findPath('clientAdBlock.js'), 'utf-8'))
/**
@@ -42,9 +45,11 @@ const renderer = (fs.readFileSync(await findPath('renderer.js'), 'utf-8')),
*/
export async function startinject(mainWindow, uid) {
// execute the script in the renderer process
mainWindow.webContents.executeJavaScript(renderer);
mainWindow.webContents.executeJavaScript(optimize);
// mainWindow.webContents.executeJavaScript(tabs);
await mainWindow.webContents.executeJavaScript(renderer);
await mainWindow.webContents.executeJavaScript(optimize);
await mainWindow.webContents.executeJavaScript(adblock);
const perms = (await getSitePerms(null, mainWindow.webContents.getURL())) || {};
await mainWindow.webContents.executeJavaScript(`setupAdBlock(${JSON.stringify(perms)})`);
const title = await mainWindow.webContents.executeJavaScript('document.title');
addHistory(uid, mainWindow.webContents.getURL(), 200, title);