mirror of
https://github.com/ION606/browser-chromium.git
synced 2026-05-14 22:26:56 +00:00
added permissions for website
This commit is contained in:
+68
-3
@@ -1,4 +1,8 @@
|
||||
import { dialog } from 'electron';
|
||||
import { BrowserWindow, dialog } from 'electron';
|
||||
import { findPath } from './paths.js';
|
||||
import { redisclient } from '../serverJS/history.cjs';
|
||||
|
||||
const preloadpath = await findPath('permspopup.cjs', true);
|
||||
|
||||
export async function askUserQuestion(window, title, question) {
|
||||
const response = await dialog.showMessageBox(window, {
|
||||
@@ -8,6 +12,67 @@ export async function askUserQuestion(window, title, question) {
|
||||
title,
|
||||
message: question,
|
||||
});
|
||||
|
||||
|
||||
return response.response === 0; // true if 'Yes' was clicked, false if 'No'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
const perms = ["geolocation", "camera", "microphone", "notifications", "popups"];
|
||||
|
||||
export async function promptForPerms(window, origin) {
|
||||
return new Promise(async (resolve) => {
|
||||
const w = new BrowserWindow({
|
||||
height: 600,
|
||||
width: 400,
|
||||
alwaysOnTop: true,
|
||||
autoHideMenuBar: true,
|
||||
darkTheme: true,
|
||||
modal: true,
|
||||
parent: window,
|
||||
webPreferences: {
|
||||
contextIsolation: true,
|
||||
javascript: true,
|
||||
allowRunningInsecureContent: false,
|
||||
nodeIntegration: true,
|
||||
preload: preloadpath
|
||||
}
|
||||
});
|
||||
|
||||
await w.loadFile(await findPath('permspopup.html'), {
|
||||
search: `origin=${origin}`
|
||||
});
|
||||
w.show();
|
||||
w.on('close', resolve);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Electron.IpcMainEvent} e
|
||||
* @param {String} sitehostname
|
||||
* @param {String} id
|
||||
* @param {String} value
|
||||
*/
|
||||
export async function setSitePerms(e, sitehostname, id, value = 'ask', all = false) {
|
||||
const client = await redisclient(),
|
||||
dataRaw = await client.get(`perms-${sitehostname}`),
|
||||
data = dataRaw ? JSON.parse(dataRaw) : null;
|
||||
|
||||
if (all || !data) await client.set(`perms-${sitehostname}`, JSON.stringify(Object.fromEntries(perms.map(p => [p, value]))));
|
||||
else {
|
||||
data[id] = value;
|
||||
await client.set(`perms-${sitehostname}`, JSON.stringify(data));
|
||||
}
|
||||
|
||||
if (e?.sender) e.sender.send('site-perms', JSON.stringify(data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Electron.IpcMainEvent} e
|
||||
* @param {String} sitehostname
|
||||
*/
|
||||
export async function getSitePerms(e, sitehostname) {
|
||||
const client = await redisclient();
|
||||
if (!e) return await client.get(`perms-${sitehostname}`);
|
||||
else e.sender.send('site-perms', await client.get(`perms-${sitehostname}`));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user