Merge branch 'develop'
This commit is contained in:
commit
9a24df4984
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "tabs",
|
"name": "tabs",
|
||||||
"version": "0.6.0",
|
"version": "0.6.1",
|
||||||
"description": "Persistent and separate browser tabs in one window.",
|
"description": "Persistent and separate browser tabs in one window.",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Alice Gaudon",
|
"name": "Alice Gaudon",
|
||||||
|
@ -49,7 +49,51 @@ function openServiceContextMenu(event, serviceId) {
|
|||||||
},
|
},
|
||||||
enabled: ready,
|
enabled: ready,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
menu.append(new MenuItem({type: "separator"}));
|
menu.append(new MenuItem({type: "separator"}));
|
||||||
|
|
||||||
|
let permissionsMenu = [];
|
||||||
|
if (ready) {
|
||||||
|
for (const domain in service.permissions) {
|
||||||
|
if (service.permissions.hasOwnProperty(domain)) {
|
||||||
|
const domainPermissionsMenu = [];
|
||||||
|
|
||||||
|
const domainPermissions = service.permissions[domain];
|
||||||
|
for (const permission of domainPermissions) {
|
||||||
|
domainPermissionsMenu.push({
|
||||||
|
label: (permission.authorized ? '✓' : '❌') + ' ' + permission.name,
|
||||||
|
submenu: [{
|
||||||
|
label: 'Toggle',
|
||||||
|
click: () => {
|
||||||
|
permission.authorized = !permission.authorized;
|
||||||
|
updateServicePermissions(serviceId);
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
label: 'Forget',
|
||||||
|
click: () => {
|
||||||
|
service.permissions[domain] = domainPermissions.filter(p => p !== permission);
|
||||||
|
},
|
||||||
|
}],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (domainPermissionsMenu.length > 0) {
|
||||||
|
permissionsMenu.push({
|
||||||
|
label: domain,
|
||||||
|
submenu: domainPermissionsMenu,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
menu.append(new MenuItem({
|
||||||
|
label: 'Permissions',
|
||||||
|
enabled: ready,
|
||||||
|
submenu: permissionsMenu,
|
||||||
|
}));
|
||||||
|
|
||||||
|
menu.append(new MenuItem({type: "separator"}));
|
||||||
|
|
||||||
menu.append(new MenuItem({
|
menu.append(new MenuItem({
|
||||||
label: 'Edit', click: () => {
|
label: 'Edit', click: () => {
|
||||||
ipcRenderer.send('openServiceSettings', serviceId);
|
ipcRenderer.send('openServiceSettings', serviceId);
|
||||||
@ -384,24 +428,56 @@ function loadService(serviceId, service) {
|
|||||||
setContextMenu(webContents);
|
setContextMenu(webContents);
|
||||||
|
|
||||||
// Set permission request handler
|
// Set permission request handler
|
||||||
session.fromPartition(service.view.partition)
|
function getUrlDomain(url) {
|
||||||
.setPermissionRequestHandler(((webContents, permission, callback, details) => {
|
let domain = url.match(/^https?:\/\/((.+?)\/|(.+))/i)[1];
|
||||||
dialog.showMessageBox(remote.getCurrentWindow(), {
|
if (domain.endsWith('/')) domain = domain.substr(0, domain.length - 1);
|
||||||
type: 'question',
|
return domain;
|
||||||
title: 'Grant ' + permission + ' permission',
|
}
|
||||||
message: 'Do you wish to grant the ' + permission + ' permission to ' + details.requestingUrl + '?',
|
|
||||||
buttons: ['Deny', 'Authorize'],
|
function getDomainPermissions(domain) {
|
||||||
cancelId: 0,
|
let domainPermissions = service.permissions[domain];
|
||||||
}).then(result => {
|
if (!domainPermissions) domainPermissions = service.permissions[domain] = [];
|
||||||
if (result.response === 1) {
|
return domainPermissions;
|
||||||
console.log('Granted', permission, 'for service', details.requestingUrl);
|
}
|
||||||
callback(true);
|
|
||||||
} else {
|
let serviceSession = session.fromPartition(service.view.partition);
|
||||||
console.log('Denied', permission, 'for service', details.requestingUrl);
|
serviceSession.setPermissionRequestHandler(((webContents, permissionName, callback, details) => {
|
||||||
callback(false);
|
let domain = getUrlDomain(details.requestingUrl);
|
||||||
}
|
let domainPermissions = getDomainPermissions(domain);
|
||||||
}).catch(console.error);
|
|
||||||
}));
|
let existingPermissions = domainPermissions.filter(p => p.name === permissionName);
|
||||||
|
if (existingPermissions.length > 0) {
|
||||||
|
callback(existingPermissions[0].authorized);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dialog.showMessageBox(remote.getCurrentWindow(), {
|
||||||
|
type: 'question',
|
||||||
|
title: 'Grant ' + permissionName + ' permission',
|
||||||
|
message: 'Do you wish to grant the ' + permissionName + ' permission to ' + domain + '?',
|
||||||
|
buttons: ['Deny', 'Authorize'],
|
||||||
|
cancelId: 0,
|
||||||
|
}).then(result => {
|
||||||
|
const authorized = result.response === 1;
|
||||||
|
|
||||||
|
domainPermissions.push({
|
||||||
|
name: permissionName,
|
||||||
|
authorized: authorized,
|
||||||
|
});
|
||||||
|
updateServicePermissions(serviceId);
|
||||||
|
|
||||||
|
console.log(authorized ? 'Granted' : 'Denied', permissionName, 'for domain', domain);
|
||||||
|
callback(authorized);
|
||||||
|
}).catch(console.error);
|
||||||
|
}));
|
||||||
|
serviceSession.setPermissionCheckHandler((webContents1, permissionName, requestingOrigin, details) => {
|
||||||
|
console.log('Permission check', permissionName, requestingOrigin, details);
|
||||||
|
let domain = getUrlDomain(details.requestingUrl);
|
||||||
|
let domainPermissions = getDomainPermissions(domain);
|
||||||
|
|
||||||
|
let existingPermissions = domainPermissions.filter(p => p.name === permissionName);
|
||||||
|
return existingPermissions.length > 0 && existingPermissions[0].authorized;
|
||||||
|
});
|
||||||
|
|
||||||
service.view.setAttribute('src', service.url);
|
service.view.setAttribute('src', service.url);
|
||||||
});
|
});
|
||||||
@ -469,6 +545,11 @@ function reloadService(serviceId) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateServicePermissions(serviceId) {
|
||||||
|
const service = services[serviceId];
|
||||||
|
ipcRenderer.send('updateServicePermissions', serviceId, service.permissions);
|
||||||
|
}
|
||||||
|
|
||||||
function updateNavigation() {
|
function updateNavigation() {
|
||||||
console.debug('Updating navigation');
|
console.debug('Updating navigation');
|
||||||
// Update active list element
|
// Update active list element
|
||||||
|
@ -36,6 +36,7 @@ Service.requiredProperties = {
|
|||||||
'autoLoad': false,
|
'autoLoad': false,
|
||||||
'customCSS': null,
|
'customCSS': null,
|
||||||
'customUserAgent': null,
|
'customUserAgent': null,
|
||||||
|
'permissions': {},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Service;
|
export default Service;
|
||||||
|
@ -183,6 +183,11 @@ function createWindow() {
|
|||||||
config.save();
|
config.save();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ipcMain.on('updateServicePermissions', (e, serviceId, permissions) => {
|
||||||
|
config.services[serviceId].permissions = permissions;
|
||||||
|
config.save();
|
||||||
|
});
|
||||||
|
|
||||||
ipcMain.on('updateWindowTitle', (event, serviceId, viewTitle) => {
|
ipcMain.on('updateWindowTitle', (event, serviceId, viewTitle) => {
|
||||||
if (serviceId === null) {
|
if (serviceId === null) {
|
||||||
window.setTitle(Meta.title);
|
window.setTitle(Meta.title);
|
||||||
|
Loading…
Reference in New Issue
Block a user