Compare commits

...

69 Commits

Author SHA1 Message Date
8ea3f5b05a Version 1.3.1 2022-03-17 13:14:59 +01:00
dca81dd4f2 Upgrade to fontawesome 6 2022-03-17 13:06:17 +01:00
18c3219e9b Allow popups to be opened when their url starts with the referrer url 2022-03-17 12:56:40 +01:00
ab38ff51dc Upgrade to electron 17, upgrade dependencies 2022-03-17 12:36:40 +01:00
5f0f601a4c Version 1.3.0 2021-09-25 11:27:33 +02:00
94879e4258 Fix target="_blank" links not opening, use new api for new window handling 2021-09-25 11:22:14 +02:00
fd6fe7675a Version 1.2.14 2021-09-22 15:53:19 +02:00
42e636a3d1 Webpack: use new asset module instead of deprecated file-loader 2021-09-22 15:53:19 +02:00
7672a5fbe4 Rollback svgo to 9.0.0 while https://github.com/webpack-contrib/image-minimizer-webpack-plugin/issues/237 is not fixed 2021-09-22 15:53:19 +02:00
de6d4b7e7f Fix svgo config deprecation 2021-09-22 15:53:19 +02:00
16ecfd112f Upgrade dependencies, bump electron to 15.0.0 2021-09-22 15:53:19 +02:00
969f5b65a9 Merge branch 'develop' 2021-07-11 12:08:00 +02:00
1c6291ef7c Update built electron version 2021-07-11 12:07:30 +02:00
1ce6a961fd Merge branch 'develop' 2021-07-11 12:06:00 +02:00
a6344769e5 Version 1.2.13 2021-07-11 12:05:45 +02:00
91af273af1 Fix icon path 2021-07-11 12:02:46 +02:00
35cdc94e1a Replace img-loader with image-minimizer-webpack-plugin 2021-07-11 12:02:34 +02:00
9b45602973 Upgrade dependencies 2021-07-11 11:47:48 +02:00
547cc26b5f Merge branch 'develop' 2021-05-25 12:16:38 +02:00
11d38a1cd9 Version 1.2.12 2021-05-25 12:16:19 +02:00
6ab51f7b38 Merge branch 'node-16' into develop 2021-05-25 12:15:41 +02:00
099f5bec64 Use local version of font-awesome instead of cdn 2021-05-25 12:14:52 +02:00
102aea4158 Upgrade dependencies, electron 13, electron-builder next 2021-05-25 11:22:46 +02:00
600ea07377 Upgrade dependencies, bump ts-loader 2021-05-11 10:30:36 +02:00
283080f00e Replace node-sass with sass 2021-05-11 10:10:47 +02:00
341b8a184a Merge branch 'develop' 2021-04-16 11:23:40 +02:00
8a463c682c Version 1.2.11 2021-04-16 11:22:59 +02:00
b761a644a4 Upgrade dependencies, electron 12.0.4 2021-04-16 11:22:33 +02:00
b85e562975 Merge branch 'develop' 2021-03-26 13:46:33 +01:00
ea8c45ef45 Version 1.2.10 2021-03-26 13:46:21 +01:00
9dff598011 Upgrade dependencies, electron 12.0.2 2021-03-26 13:45:17 +01:00
ec3c282a41 Merge branch 'develop' 2021-03-16 16:27:48 +01:00
7414e023e0 Version 1.2.9 2021-03-16 16:27:45 +01:00
e793d51039 Upgrade dependencies, electron 12.0.1 2021-03-16 16:26:57 +01:00
9d0bef5709 Merge branch 'develop' 2021-03-06 18:46:14 +01:00
9aef4047c9 Version 1.2.8 2021-03-06 18:45:37 +01:00
aeed83a9f7 Update electron updater url 2021-03-06 18:45:37 +01:00
b8861a7d45 Update default config service url 2021-03-06 18:45:37 +01:00
a6d7bd3604 Stop using remote in renderer process
Fix unused import
2021-03-06 18:45:37 +01:00
86e442f548 Disable contextIsolation in all UI windows 2021-03-06 18:45:37 +01:00
9fb8354878 Remove explicitly setting contextIsolation to true
contextIsolation is now true by default in electron 12.x
2021-03-06 18:45:37 +01:00
29f9b22d21 Upgrade dependencies i.e. electron 12.x
Remove explicit @types/node dependency to automatically align version with electron
Fix electron version
2021-03-06 18:45:37 +01:00
8d7f9a942e package.json: update homepage 2021-02-06 10:30:46 +01:00
17eafb33be Merge branch 'develop' 2021-02-06 10:20:39 +01:00
c2d221184d Version 1.2.7 2021-02-06 10:20:27 +01:00
23c11659e1 Upgrade dependencies i.e. electron 11.2.3 2021-02-06 10:19:13 +01:00
e851b10487 Merge branch 'develop' 2021-01-25 10:31:58 +01:00
bbaae1e287 Version 1.2.6 2021-01-25 10:31:53 +01:00
49991d11b1 Upgrade dependencies i.e. electron 11.2.1 2021-01-25 10:31:39 +01:00
5917d9bf1c Merge branch 'develop' 2021-01-20 12:50:48 +01:00
2e3586b28b Version 1.2.5 2021-01-20 12:46:33 +01:00
f3a5a5c0f8 Upgrade dependencies i.e. electron 11.2.0 2021-01-20 12:45:51 +01:00
61daa66396 Merge branch 'develop' 2020-12-21 15:41:14 +01:00
1d218f588d Version 1.2.4 2020-12-21 15:40:59 +01:00
e7bf51fcea Upgrade dependencies i.e. electron 11.1.0 2020-12-21 15:38:01 +01:00
d7c689db61 Merge branch 'develop' 2020-11-27 14:48:47 +01:00
68b545e342 Version 1.2.3 2020-11-27 14:48:28 +01:00
79b79e0aec Fix protocol status badge not updating for active service with id 0 2020-11-27 14:47:11 +01:00
ada191e971 Update new update download link 2020-11-27 14:31:42 +01:00
1d73545841 Update default config service url 2020-11-27 14:31:27 +01:00
79e8290971 Upgrade dependencies i.e. electron 11.0.3 2020-11-27 11:58:13 +01:00
64e1b59aeb Merge branch 'develop' 2020-11-17 12:14:09 +01:00
529a0abe13 Version 1.2.2 2020-11-17 12:13:54 +01:00
108d48b35d Add temporary fix for twitter (and others) not loading in webviews
Pending https://github.com/electron/electron/issues/25469
2020-11-17 12:11:41 +01:00
0e9ed7492c Upgrade dependencies i.e. electron v11.0.0 2020-11-17 11:52:48 +01:00
8e37cf3467 Merge branch 'develop' 2020-11-16 17:24:27 +01:00
3ee6c20842 Version 1.2.1 2020-11-16 17:23:47 +01:00
656d2c9589 Upgrade dependencies 2020-11-16 17:23:38 +01:00
effb625515 Update update/publish source 2020-11-16 16:15:58 +01:00
20 changed files with 3189 additions and 3783 deletions

View File

@ -1,6 +1,5 @@
owner: ArisuOngaku provider: generic
repo: tabs url: "https://update.eternae.ink/ashpie/tabs"
provider: github
updaterCacheDirName: tabs-updater updaterCacheDirName: tabs-updater
publisherName: publisherName:
- Alice Gaudon - Alice Gaudon

View File

@ -4,10 +4,7 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>An error occured</title> <title>An error occured</title>
<meta http-equiv="Content-Security-Policy" <meta http-equiv="Content-Security-Policy"
content="style-src 'self' 'unsafe-inline' https://use.fontawesome.com; font-src 'self' https://use.fontawesome.com; script-src 'self'"> content="style-src 'self' 'unsafe-inline'; font-src 'self'; script-src 'self'">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css"
integrity="sha384-oS3vJWv+0UjzBfQzYUhtDYW+Pj2yciDJxpsK1OYPAYjqT085Qq/1cq5FLXAZQ7Ay" crossorigin="anonymous">
<link rel="stylesheet" href="css/layout.css"> <link rel="stylesheet" href="css/layout.css">
<link rel="stylesheet" href="css/error.css"> <link rel="stylesheet" href="css/error.css">

View File

@ -4,10 +4,7 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>An error occured</title> <title>An error occured</title>
<meta http-equiv="Content-Security-Policy" <meta http-equiv="Content-Security-Policy"
content="style-src 'self' 'unsafe-inline' https://use.fontawesome.com; font-src 'self' https://use.fontawesome.com; script-src 'self'"> content="style-src 'self' 'unsafe-inline'; font-src 'self'; script-src 'self'">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css"
integrity="sha384-oS3vJWv+0UjzBfQzYUhtDYW+Pj2yciDJxpsK1OYPAYjqT085Qq/1cq5FLXAZQ7Ay" crossorigin="anonymous">
<link rel="stylesheet" href="css/layout.css"> <link rel="stylesheet" href="css/layout.css">
<link rel="stylesheet" href="css/error.css"> <link rel="stylesheet" href="css/error.css">

View File

@ -4,10 +4,7 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Tabs</title> <title>Tabs</title>
<meta http-equiv="Content-Security-Policy" content="style-src 'self' 'unsafe-inline' https://use.fontawesome.com; font-src 'self' https://use.fontawesome.com; script-src 'self' 'sha256-oPC0l5nxLnJ2LX6qU9Laxa4/cjhuHDRIqdUsBDWYqnw='"> <meta http-equiv="Content-Security-Policy" content="style-src 'self' 'unsafe-inline'; font-src 'self'; script-src 'self' 'sha256-oPC0l5nxLnJ2LX6qU9Laxa4/cjhuHDRIqdUsBDWYqnw='">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css"
integrity="sha384-oS3vJWv+0UjzBfQzYUhtDYW+Pj2yciDJxpsK1OYPAYjqT085Qq/1cq5FLXAZQ7Ay" crossorigin="anonymous">
<link rel="stylesheet" href="css/layout.css"> <link rel="stylesheet" href="css/layout.css">
<link rel="stylesheet" href="css/index.css"> <link rel="stylesheet" href="css/index.css">

View File

@ -1,3 +1,5 @@
@import url('../../node_modules/@fortawesome/fontawesome-free/css/all.css');
* { * {
box-sizing: border-box; box-sizing: border-box;
} }

View File

@ -4,10 +4,7 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Service settings</title> <title>Service settings</title>
<meta http-equiv="Content-Security-Policy" content="style-src 'self' 'unsafe-inline' https://use.fontawesome.com; font-src 'self' https://use.fontawesome.com; script-src 'self' 'sha256-5gY/z34s5Mtc3YL8GkwZQhzk9LymQIuFUQRVvs7Gh0o='"> <meta http-equiv="Content-Security-Policy" content="style-src 'self' 'unsafe-inline'; font-src 'self'; script-src 'self' 'sha256-5gY/z34s5Mtc3YL8GkwZQhzk9LymQIuFUQRVvs7Gh0o='">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css"
integrity="sha384-oS3vJWv+0UjzBfQzYUhtDYW+Pj2yciDJxpsK1OYPAYjqT085Qq/1cq5FLXAZQ7Ay" crossorigin="anonymous">
<link rel="stylesheet" href="css/layout.css"> <link rel="stylesheet" href="css/layout.css">
<link rel="stylesheet" href="css/service-settings.css"> <link rel="stylesheet" href="css/service-settings.css">

View File

@ -5,10 +5,7 @@
<title>Service settings</title> <title>Service settings</title>
<meta http-equiv="Content-Security-Policy" <meta http-equiv="Content-Security-Policy"
content="style-src 'self' 'unsafe-inline' https://use.fontawesome.com; font-src 'self' https://use.fontawesome.com; script-src 'self' 'sha256-UoPUIMX0PZl7cy3YoegZ0EDleSaHxTURPMyK09xsa0E='"> content="style-src 'self' 'unsafe-inline'; font-src 'self'; script-src 'self' 'sha256-UoPUIMX0PZl7cy3YoegZ0EDleSaHxTURPMyK09xsa0E='">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css"
integrity="sha384-oS3vJWv+0UjzBfQzYUhtDYW+Pj2yciDJxpsK1OYPAYjqT085Qq/1cq5FLXAZQ7Ay" crossorigin="anonymous">
<link rel="stylesheet" href="css/layout.css"> <link rel="stylesheet" href="css/layout.css">
<link rel="stylesheet" href="css/service-settings.css"> <link rel="stylesheet" href="css/service-settings.css">

View File

@ -1,26 +1,8 @@
import { import {DidFailLoadEvent, ipcRenderer, PageFaviconUpdatedEvent, UpdateTargetUrlEvent} from "electron";
clipboard,
ContextMenuParams,
DidFailLoadEvent,
ipcRenderer,
PageFaviconUpdatedEvent,
remote,
shell,
UpdateTargetUrlEvent,
WebContents,
WebviewTag,
} from "electron";
import Service from "../../src/Service"; import Service from "../../src/Service";
import {IconProperties, IconSet, SpecialPages} from "../../src/Meta"; import {IconProperties, IconSet, SpecialPages} from "../../src/Meta";
import Config from "../../src/Config"; import Config from "../../src/Config";
const {
Menu,
MenuItem,
dialog,
session,
} = remote;
const appInfo: { const appInfo: {
title?: string; title?: string;
} = {}; } = {};
@ -42,129 +24,6 @@ let serviceSelector: HTMLElement | null = null;
let lastDragPosition: HTMLElement | null = null; let lastDragPosition: HTMLElement | null = null;
let oldActiveService: number | null = null; let oldActiveService: number | null = null;
// Service context menu
function openServiceContextMenu(event: Event, serviceId: number) {
event.preventDefault();
const service = services[serviceId];
if (!service) throw new Error('Service doesn\'t exist.');
const menu = new Menu();
const ready = service.view && service.viewReady, notReady = !service.view && !service.viewReady;
menu.append(new MenuItem({
label: 'Home', click: () => {
service.view?.loadURL(service.url)
.catch(console.error);
},
enabled: ready,
}));
menu.append(new MenuItem({
label: ready ? 'Reload' : 'Load', click: () => {
reloadService(serviceId);
},
enabled: ready || notReady,
}));
menu.append(new MenuItem({
label: 'Close', click: () => {
unloadService(serviceId);
},
enabled: ready,
}));
menu.append(new MenuItem({type: "separator"}));
menu.append(new MenuItem({
label: 'Reset zoom level', click: () => {
if (service.view) {
service.view.setZoomFactor(1);
service.view.setZoomLevel(0);
}
},
enabled: ready && service.view?.getZoomFactor() !== 1 && service.view?.getZoomLevel() !== 0,
}));
menu.append(new MenuItem({
label: 'Zoom in', click: () => {
if (service.view) {
service.view.setZoomLevel(service.view.getZoomLevel() + 1);
}
},
enabled: ready,
}));
menu.append(new MenuItem({
label: 'Zoom out', click: () => {
if (service.view) {
service.view.setZoomLevel(service.view.getZoomLevel() - 1);
}
},
enabled: ready,
}));
menu.append(new MenuItem({type: "separator"}));
const permissionsMenu = [];
if (ready) {
for (const domain of Object.keys(service.permissions)) {
const domainPermissionsMenu = [];
const domainPermissions = service.permissions[domain];
if (domainPermissions) {
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({
label: 'Edit', click: () => {
ipcRenderer.send('openServiceSettings', serviceId);
},
}));
menu.append(new MenuItem({
label: 'Delete', click: () => {
dialog.showMessageBox(remote.getCurrentWindow(), {
type: 'question',
title: 'Confirm',
message: 'Are you sure you want to delete this service?',
buttons: ['Cancel', 'Confirm'],
cancelId: 0,
}).then(result => {
if (result.response === 1) {
ipcRenderer.send('deleteService', serviceId);
}
}).catch(console.error);
},
}));
menu.popup({window: remote.getCurrentWindow()});
}
ipcRenderer.on('data', ( ipcRenderer.on('data', (
event, event,
@ -258,6 +117,44 @@ ipcRenderer.on('data', (
document.documentElement.style.setProperty('--nav-width', config.bigNavBar ? '64px' : '48px'); document.documentElement.style.setProperty('--nav-width', config.bigNavBar ? '64px' : '48px');
}); });
ipcRenderer.on('load-service-home', (event, serviceId: number) => {
const service = services[serviceId];
if (!service) throw new Error('Service doesn\'t exist.');
service.view?.loadURL(service.url)
.catch(console.error);
});
ipcRenderer.on('reload-service', (event, serviceId: number) => {
reloadService(serviceId);
});
ipcRenderer.on('unload-service', (event, serviceId: number) => {
unloadService(serviceId);
});
ipcRenderer.on('reset-service-zoom-level', (event, serviceId: number) => {
const service = services[serviceId];
if (service?.view) {
service.view.setZoomFactor(1);
service.view.setZoomLevel(0);
}
});
ipcRenderer.on('zoom-in-service', (event, serviceId: number) => {
const service = services[serviceId];
if (service?.view) {
service.view.setZoomLevel(service.view.getZoomLevel() + 1);
}
});
ipcRenderer.on('zoom-out-service', (event, serviceId: number) => {
const service = services[serviceId];
if (service?.view) {
service.view.setZoomLevel(service.view.getZoomLevel() - 1);
}
});
function removeServiceFeatures(id: number): Element | null { function removeServiceFeatures(id: number): Element | null {
// Remove nav // Remove nav
const nav = document.querySelector('#service-selector'); const nav = document.querySelector('#service-selector');
@ -358,7 +255,20 @@ function createServiceNavigationElement(index: number, nextNavButton?: Element |
ipcRenderer.send('setActiveService', id); ipcRenderer.send('setActiveService', id);
} }
}); });
button.addEventListener('contextmenu', e => openServiceContextMenu(e, index)); button.addEventListener('contextmenu', e => {
e.preventDefault();
const service = services[index];
if (!service) throw new Error('Service doesn\'t exist.');
ipcRenderer.send(
'open-service-navigation-context-menu',
index,
!!service.view && !!service.viewReady,
!service.view && !service.viewReady,
service.view?.getZoomFactor() !== 1 && service.view?.getZoomLevel() !== 0,
);
});
let icon: HTMLImageElement | HTMLElement; let icon: HTMLImageElement | HTMLElement;
if (service.useFavicon && service.favicon != null) { if (service.useFavicon && service.favicon != null) {
@ -490,7 +400,7 @@ document.addEventListener('DOMContentLoaded', () => {
refreshButton?.addEventListener('click', () => reload()); refreshButton?.addEventListener('click', () => reload());
addButton = document.getElementById('add-button'); addButton = document.getElementById('add-button');
addButton?.addEventListener('click', () => ipcRenderer.send('openServiceSettings', null)); addButton?.addEventListener('click', () => ipcRenderer.send('create-new-service', null));
settingsButton = document.getElementById('settings-button'); settingsButton = document.getElementById('settings-button');
settingsButton?.addEventListener('click', () => ipcRenderer.send('openSettings', null)); settingsButton?.addEventListener('click', () => ipcRenderer.send('openSettings', null));
@ -533,12 +443,9 @@ function loadService(serviceId: number, service: FrontService) {
view.setAttribute('enableRemoteModule', 'false'); view.setAttribute('enableRemoteModule', 'false');
view.setAttribute('partition', 'persist:service_' + service.partition); view.setAttribute('partition', 'persist:service_' + service.partition);
view.setAttribute('autosize', 'true'); view.setAttribute('autosize', 'true');
view.setAttribute('allowpopups', 'true');
if (specialPages) view.setAttribute('src', specialPages.empty); if (specialPages) view.setAttribute('src', specialPages.empty);
// Enable context isolation. This is currently not used as there is no preload script; however it could prevent
// eventual future human mistakes.
view.setAttribute('webpreferences', 'contextIsolation=yes');
// Error handling // Error handling
view.addEventListener('did-fail-load', (e: DidFailLoadEvent) => { view.addEventListener('did-fail-load', (e: DidFailLoadEvent) => {
if (e.errorCode <= -100 && e.errorCode > -200) { if (e.errorCode <= -100 && e.errorCode > -200) {
@ -575,72 +482,17 @@ function loadService(serviceId: number, service: FrontService) {
} }
}); });
const webContents = remote.webContents.fromId(view.getWebContentsId());
// Set custom user agent // Set custom user agent
if (typeof service.customUserAgent === 'string') { if (typeof service.customUserAgent === 'string') {
webContents.setUserAgent(service.customUserAgent); ipcRenderer.send('set-web-contents-user-agent', view.getWebContentsId(), service.customUserAgent);
} }
// Set context menu // Set context menu
setContextMenu(webContents); ipcRenderer.send('open-service-content-context-menu', view.getWebContentsId());
// Set permission request handler // Set permission request handler
function getUrlDomain(url: string) { ipcRenderer.send('set-partition-permissions', serviceId, view.partition);
const matches = url.match(/^https?:\/\/((.+?)\/|(.+))/i);
if (matches !== null) {
let domain = matches[1];
if (domain.endsWith('/')) domain = domain.substr(0, domain.length - 1);
return domain;
}
return '';
}
function getDomainPermissions(domain: string) {
let domainPermissions = service.permissions[domain];
if (!domainPermissions) domainPermissions = service.permissions[domain] = [];
return domainPermissions;
}
const serviceSession = session.fromPartition(view.partition);
serviceSession.setPermissionRequestHandler((webContents, permissionName, callback, details) => {
const domain = getUrlDomain(details.requestingUrl);
const domainPermissions = getDomainPermissions(domain);
const 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);
const domain = getUrlDomain(details.requestingUrl);
const domainPermissions = getDomainPermissions(domain);
const existingPermissions = domainPermissions.filter(p => p.name === permissionName);
return existingPermissions.length > 0 && existingPermissions[0].authorized;
});
view.setAttribute('src', service.url); view.setAttribute('src', service.url);
}); });
@ -721,13 +573,6 @@ function reloadService(serviceId: number) {
} }
} }
function updateServicePermissions(serviceId: number) {
const service = services[serviceId];
if (!service) throw new Error('Service doesn\'t exist.');
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
@ -772,7 +617,8 @@ function updateNavigation() {
} }
function updateStatusButton() { function updateStatusButton() {
if (!selectedServiceId) return; if (typeof selectedServiceId !== 'number') return;
const protocol = services[selectedServiceId]?.view?.getURL().split('://')[0] || 'unknown'; const protocol = services[selectedServiceId]?.view?.getURL().split('://')[0] || 'unknown';
securityButton?.childNodes.forEach(el => { securityButton?.childNodes.forEach(el => {
if (el instanceof HTMLElement) { if (el instanceof HTMLElement) {
@ -784,11 +630,11 @@ function updateStatusButton() {
function updateWindowTitle() { function updateWindowTitle() {
if (selectedServiceId === null) { if (selectedServiceId === null) {
ipcRenderer.send('updateWindowTitle', null); ipcRenderer.send('update-window-title', null);
} else { } else {
const service = services[selectedServiceId]; const service = services[selectedServiceId];
if (service?.viewReady && service.view) { if (service?.viewReady && service.view) {
ipcRenderer.send('updateWindowTitle', selectedServiceId, remote.webContents.fromId(service.view.getWebContentsId()).getTitle()); ipcRenderer.send('update-window-title', selectedServiceId, service.view.getWebContentsId());
} }
} }
} }
@ -807,14 +653,14 @@ function goForward() {
if (selectedServiceId === null) return; if (selectedServiceId === null) return;
const view = services[selectedServiceId]?.view; const view = services[selectedServiceId]?.view;
if (view) remote.webContents.fromId(view.getWebContentsId()).goForward(); if (view) ipcRenderer.send('go-forward', view.getWebContentsId());
} }
function goBack() { function goBack() {
if (selectedServiceId === null) return; if (selectedServiceId === null) return;
const view = services[selectedServiceId]?.view; const view = services[selectedServiceId]?.view;
if (view) remote.webContents.fromId(view.getWebContentsId()).goBack(); if (view) ipcRenderer.send('go-back', view.getWebContentsId());
} }
function reload() { function reload() {
@ -823,140 +669,13 @@ function reload() {
reloadService(selectedServiceId); reloadService(selectedServiceId);
} }
function setContextMenu(webContents: WebContents) {
webContents.on('context-menu', (event, props: ContextMenuParams) => {
const menu = new Menu();
const {editFlags} = props;
// linkURL
if (props.linkURL.length > 0) {
if (menu.items.length > 0) {
menu.append(new MenuItem({type: 'separator'}));
}
menu.append(new MenuItem({
label: 'Copy link URL',
click: () => {
clipboard.writeText(props.linkURL);
},
}));
menu.append(new MenuItem({
label: 'Open URL in default browser',
click: () => {
if (props.linkURL.startsWith('https://')) {
shell.openExternal(props.linkURL)
.catch(console.error);
}
},
}));
}
// Image
if (props.hasImageContents) {
if (menu.items.length > 0) {
menu.append(new MenuItem({type: 'separator'}));
}
menu.append(new MenuItem({
label: 'Copy image',
click: () => {
webContents.copyImageAt(props.x, props.y);
},
}));
menu.append(new MenuItem({
label: 'Save image as',
click: () => {
webContents.downloadURL(props.srcURL);
},
}));
}
// Text clipboard
if (editFlags.canUndo || editFlags.canRedo || editFlags.canCut || editFlags.canCopy || editFlags.canPaste ||
editFlags.canDelete) {
if (editFlags.canUndo || editFlags.canRedo) {
if (menu.items.length > 0) {
menu.append(new MenuItem({type: 'separator'}));
}
if (editFlags.canUndo) {
menu.append(new MenuItem({
label: 'Undo',
role: 'undo',
}));
}
if (editFlags.canRedo) {
menu.append(new MenuItem({
label: 'Redo',
role: 'redo',
}));
}
}
if (menu.items.length > 0) {
menu.append(new MenuItem({type: 'separator'}));
}
menu.append(new MenuItem({
label: 'Cut',
role: 'cut',
enabled: editFlags.canCut,
}));
menu.append(new MenuItem({
label: 'Copy',
role: 'copy',
enabled: editFlags.canCopy,
}));
menu.append(new MenuItem({
label: 'Paste',
role: 'paste',
enabled: editFlags.canPaste,
}));
menu.append(new MenuItem({
label: 'Delete',
role: 'delete',
enabled: editFlags.canDelete,
}));
}
if (editFlags.canSelectAll) {
if (menu.items.length > 0) {
menu.append(new MenuItem({type: 'separator'}));
}
menu.append(new MenuItem({
label: 'Select all',
role: 'selectAll',
}));
}
// Inspect element
if (menu.items.length > 0) {
menu.append(new MenuItem({type: 'separator'}));
}
menu.append(new MenuItem({
label: 'Inspect element',
click: () => {
webContents.inspectElement(props.x, props.y);
},
}));
menu.popup({
window: remote.getCurrentWindow(),
});
});
}
ipcRenderer.on('fullscreenchange', (e, fullscreen: boolean) => { ipcRenderer.on('fullscreenchange', (e, fullscreen: boolean) => {
if (fullscreen) document.body.classList.add('fullscreen'); if (fullscreen) document.body.classList.add('fullscreen');
else document.body.classList.remove('fullscreen'); else document.body.classList.remove('fullscreen');
}); });
type FrontService = Service & { type FrontService = Service & {
view?: WebviewTag; view?: Electron.WebviewTag;
viewReady?: boolean; viewReady?: boolean;
li?: NavigationElement; li?: NavigationElement;
}; };

View File

@ -1,4 +1,4 @@
import {ipcRenderer, remote} from "electron"; import {ipcRenderer} from "electron";
import Service from "../../src/Service"; import Service from "../../src/Service";
import {IconProperties, IconSet} from "../../src/Meta"; import {IconProperties, IconSet} from "../../src/Meta";
@ -64,7 +64,7 @@ document.addEventListener('DOMContentLoaded', () => {
document.getElementById('cancel-button')?.addEventListener('click', e => { document.getElementById('cancel-button')?.addEventListener('click', e => {
e.preventDefault(); e.preventDefault();
remote.getCurrentWindow().close(); ipcRenderer.send('close-window', 'ServiceSettingsWindow');
}); });
document.querySelector('form')?.addEventListener('submit', e => { document.querySelector('form')?.addEventListener('submit', e => {
@ -226,7 +226,7 @@ function save() {
} }
ipcRenderer.send('saveService', serviceId, service); ipcRenderer.send('saveService', serviceId, service);
remote.getCurrentWindow().close(); ipcRenderer.send('close-window', 'ServiceSettingsWindow');
} }
function isValid() { function isValid() {

View File

@ -1,4 +1,4 @@
import {ipcRenderer, remote, shell} from "electron"; import {ipcRenderer, shell} from "electron";
import Config from "../../src/Config"; import Config from "../../src/Config";
import {SemVer} from "semver"; import {SemVer} from "semver";
import {UpdateInfo} from "electron-updater"; import {UpdateInfo} from "electron-updater";
@ -63,7 +63,7 @@ function save() {
config.refreshButton = formData.get('refresh-button') === 'on'; config.refreshButton = formData.get('refresh-button') === 'on';
ipcRenderer.send('save-config', config); ipcRenderer.send('save-config', config);
remote.getCurrentWindow().close(); ipcRenderer.send('close-window', 'SettingsWindow');
} }
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
@ -71,7 +71,7 @@ document.addEventListener('DOMContentLoaded', () => {
updateStatus = document.getElementById('update-status'); updateStatus = document.getElementById('update-status');
updateButton = document.getElementById('download-button'); updateButton = document.getElementById('download-button');
updateButton?.addEventListener('click', () => { updateButton?.addEventListener('click', () => {
shell.openExternal(`https://github.com/ArisuOngaku/tabs/releases/download/v${updateInfo.version}/${updateInfo.path}`) shell.openExternal(`https://update.eternae.ink/ashpie/tabs/${updateInfo.path}`)
.catch(console.error); .catch(console.error);
}); });
@ -87,7 +87,7 @@ document.addEventListener('DOMContentLoaded', () => {
document.getElementById('cancel-button')?.addEventListener('click', e => { document.getElementById('cancel-button')?.addEventListener('click', e => {
e.preventDefault(); e.preventDefault();
remote.getCurrentWindow().close(); ipcRenderer.send('close-window', 'SettingsWindow');
}); });
document.querySelector('form')?.addEventListener('submit', e => { document.querySelector('form')?.addEventListener('submit', e => {

View File

@ -1,12 +1,12 @@
{ {
"name": "tabs", "name": "tabs",
"version": "1.2.0", "version": "1.3.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",
"email": "alice@gaudon.pro" "email": "alice@gaudon.pro"
}, },
"homepage": "https://github.com/ArisuOngaku/tabs", "homepage": "https://eternae.ink/ashpie/tabs",
"license": "GPL-3.0-only", "license": "GPL-3.0-only",
"main": "build/main.js", "main": "build/main.js",
"scripts": { "scripts": {
@ -30,28 +30,28 @@
"devDependencies": { "devDependencies": {
"@babel/core": "^7.9.6", "@babel/core": "^7.9.6",
"@babel/preset-env": "^7.9.6", "@babel/preset-env": "^7.9.6",
"@fortawesome/fontawesome-free": "^5.13.0", "@fortawesome/fontawesome-free": "^6.1.0",
"@types/node": "^12.12.54", "@types/node": "^14.6.2",
"@typescript-eslint/eslint-plugin": "^4.3.0", "@typescript-eslint/eslint-plugin": "^5.15.0",
"@typescript-eslint/parser": "^4.3.0", "@typescript-eslint/parser": "^5.15.0",
"babel-loader": "^8.1.0", "babel-loader": "^8.1.0",
"concurrently": "^5.2.0", "concurrently": "^7.0.0",
"copy-webpack-plugin": "^6.0.1", "copy-webpack-plugin": "^10.2.4",
"css-loader": "^5.0.0", "css-loader": "^6.3.0",
"electron": "^10.0.0", "electron": "^17.1.2",
"electron-builder": "^22.4.0", "electron-builder": "^22.11.5",
"eslint": "^7.10.0", "eslint": "^8.11.0",
"file-loader": "^6.0.0", "image-minimizer-webpack-plugin": "^3.2.3",
"imagemin": "^7.0.1", "imagemin": "^8.0.1",
"imagemin-gifsicle": "^7.0.0", "imagemin-gifsicle": "^7.0.0",
"imagemin-mozjpeg": "^9.0.0", "imagemin-mozjpeg": "^10.0.0",
"imagemin-pngquant": "^9.0.0", "imagemin-pngquant": "^9.0.2",
"imagemin-svgo": "^8.0.0", "imagemin-svgo": "^10.0.1",
"img-loader": "^3.0.1", "mini-css-extract-plugin": "^2.1.0",
"mini-css-extract-plugin": "^1.2.0", "sass": "^1.32.12",
"node-sass": "^5.0.0", "sass-loader": "^12.1.0",
"sass-loader": "^10.0.0", "svgo": "^2.3.1",
"ts-loader": "^8.0.0", "ts-loader": "^9.1.2",
"typescript": "^4.0.2", "typescript": "^4.0.2",
"webpack": "^5.2.0", "webpack": "^5.2.0",
"webpack-cli": "^4.1.0" "webpack-cli": "^4.1.0"
@ -62,48 +62,33 @@
"resources/**/*", "resources/**/*",
"build/**/*" "build/**/*"
], ],
"publish": [
{
"provider": "generic",
"url": "https://update.eternae.ink/ashpie/tabs"
}
],
"linux": { "linux": {
"target": "AppImage", "target": "AppImage",
"icon": "resources/images/logo.png", "icon": "frontend/images/logo.png",
"category": "Utility", "category": "Utility",
"executableName": "tabs", "executableName": "tabs",
"desktop": { "desktop": {
"StartupWMClass": "Tabs", "StartupWMClass": "Tabs",
"MimeType": "x-scheme-handler/tabs" "MimeType": "x-scheme-handler/tabs"
}, }
"publish": [
{
"provider": "github",
"owner": "ArisuOngaku",
"repo": "tabs"
}
]
}, },
"win": { "win": {
"target": "nsis", "target": "nsis",
"icon": "resources/images/logo.png", "icon": "frontend/images/logo.png",
"publisherName": "Alice Gaudon", "publisherName": "Alice Gaudon",
"verifyUpdateCodeSignature": "false", "verifyUpdateCodeSignature": "false"
"publish": [
{
"provider": "github",
"owner": "ArisuOngaku",
"repo": "tabs"
}
]
}, },
"mac": { "mac": {
"target": "default", "target": "default",
"icon": "resources/images/logo.png", "icon": "frontend/images/logo.png",
"category": "public.app-category.utilities", "category": "public.app-category.utilities"
"publish": [
{
"provider": "github",
"owner": "ArisuOngaku",
"repo": "tabs"
}
]
}, },
"electronVersion": "10.1.5" "electronVersion": "15.0.0"
} }
} }

View File

@ -1,4 +1,4 @@
import {app, Menu, shell, Tray} from "electron"; import {app, dialog, Menu, shell, Tray} from "electron";
import Meta from "./Meta"; import Meta from "./Meta";
import Config from "./Config"; import Config from "./Config";
import Updater from "./Updater"; import Updater from "./Updater";
@ -52,16 +52,36 @@ export default class Application {
return this.devMode; return this.devMode;
} }
public async openExternalLink(url: string): Promise<void> {
if (url.startsWith('https://')) {
console.log('Opening link', url);
await shell.openExternal(url);
} else {
const {response} = await dialog.showMessageBox({
message: 'Are you sure you want to open this link?\n' + url,
type: 'question',
buttons: ['Cancel', 'Open link'],
});
if (response === 1) {
console.log('Opening link', url);
await shell.openExternal(url);
}
}
}
private setupElectronTweaks() { private setupElectronTweaks() {
// Open external links in default OS browser // Open external links in default OS browser
app.on('web-contents-created', (e, contents) => { app.on('web-contents-created', (e, contents) => {
if (contents.getType() === 'webview') { if (contents.getType() === 'webview') {
console.log('Setting external links to open in default OS browser'); console.log('Setting external links to open in default OS browser');
contents.on('new-window', (e, url) => { contents.setWindowOpenHandler(details => {
e.preventDefault(); if (details.url.startsWith(details.referrer.url)) return {action: 'allow'};
if (url.startsWith('https://')) {
shell.openExternal(url).catch(console.error); const url = details.url;
} this.openExternalLink(url)
.catch(console.error);
return {action: 'deny'};
}); });
} }
}); });

View File

@ -52,7 +52,7 @@ export default class Config {
'Welcome', 'Welcome',
'rocket', 'rocket',
false, false,
'https://github.com/ArisuOngaku/tabs', 'https://eternae.ink/ashpie/tabs',
false, false,
)); ));
} }

View File

@ -32,6 +32,19 @@ export default abstract class Window {
this.teardown(); this.teardown();
this.window = undefined; this.window = undefined;
}); });
this.onIpc('close-window', (
event,
constructorName: string,
) => {
if (constructorName === this.constructor.name) {
console.log('Closing', this.constructor.name);
const window = this.getWindow();
if (window.closable) {
window.close();
}
}
});
} }
public teardown(): void { public teardown(): void {
@ -80,6 +93,7 @@ export default abstract class Window {
public getWindow(): BrowserWindow { public getWindow(): BrowserWindow {
if (!this.window) throw Error('Window not initialized.'); if (!this.window) throw Error('Window not initialized.');
else if (this.window.isDestroyed()) throw Error('Window destroyed.');
return this.window; return this.window;
} }
} }

View File

@ -4,6 +4,9 @@ import {app} from "electron";
import Meta from "./Meta"; import Meta from "./Meta";
import Application from "./Application"; import Application from "./Application";
// Fix for twitter (and others) in webviews - pending https://github.com/electron/electron/issues/25469
app.commandLine.appendSwitch('disable-features', 'CrossOriginOpenerPolicy');
const application = new Application(Meta.isDevMode()); const application = new Application(Meta.isDevMode());
// Check if application is already running // Check if application is already running

View File

@ -1,11 +1,10 @@
import path from "path"; import path from "path";
import {ipcMain} from "electron"; import {clipboard, ContextMenuParams, dialog, ipcMain, Menu, MenuItem, session, webContents} from "electron";
import ServiceSettingsWindow from "./ServiceSettingsWindow"; import ServiceSettingsWindow from "./ServiceSettingsWindow";
import SettingsWindow from "./SettingsWindow"; import SettingsWindow from "./SettingsWindow";
import Application from "../Application"; import Application from "../Application";
import Meta, {SpecialPages} from "../Meta"; import Meta, {SpecialPages} from "../Meta";
import Window from "../Window"; import Window from "../Window";
import {ServicePermissions} from "../Service";
export default class MainWindow extends Window { export default class MainWindow extends Window {
private activeServiceId: number = 0; private activeServiceId: number = 0;
@ -20,8 +19,8 @@ export default class MainWindow extends Window {
super.setup({ super.setup({
webPreferences: { webPreferences: {
nodeIntegration: true, nodeIntegration: true,
enableRemoteModule: true,
webviewTag: true, webviewTag: true,
contextIsolation: false,
}, },
autoHideMenuBar: true, autoHideMenuBar: true,
icon: Meta.ICON_PATH, icon: Meta.ICON_PATH,
@ -81,40 +80,14 @@ export default class MainWindow extends Window {
this.config.save(); this.config.save();
}); });
// Delete service
this.onIpc('deleteService', (e, id: number) => {
console.log('Deleting service', id);
this.config.services.splice(id, 1);
this.config.save();
window.webContents.send('deleteService', id);
});
// Update service permissions
ipcMain.on('updateServicePermissions', (e, serviceId: number, permissions: ServicePermissions) => {
this.config.services[serviceId].permissions = permissions;
this.config.save();
});
// Update window title // Update window title
ipcMain.on('updateWindowTitle', (event, serviceId: number | null, viewTitle?: string) => { ipcMain.on('update-window-title', (event, serviceId: number | null, webContentsId?: number) => {
if (serviceId === null) { if (serviceId === null) {
window.setTitle(Meta.title); window.setTitle(Meta.title);
} else if (viewTitle) { } else if (webContentsId) {
const service = this.config.services[serviceId]; const service = this.config.services[serviceId];
window.setTitle(Meta.getTitleForService(service, viewTitle)); const serviceWebContents = webContents.fromId(webContentsId);
} window.setTitle(Meta.getTitleForService(service, serviceWebContents.getTitle()));
});
// Open service settings window
ipcMain.on('openServiceSettings', (e, serviceId: number | null) => {
if (!this.serviceSettingsWindow) {
console.log('Opening service settings', serviceId);
this.serviceSettingsWindow = new ServiceSettingsWindow(this.application, this, serviceId);
this.serviceSettingsWindow.setup();
this.serviceSettingsWindow.onClose(() => {
this.serviceSettingsWindow = undefined;
});
} }
}); });
@ -130,6 +103,50 @@ export default class MainWindow extends Window {
} }
}); });
// Context menus
ipcMain.on('open-service-navigation-context-menu', (
event,
serviceId: number,
ready: boolean,
notReady: boolean,
canResetZoom: boolean,
) => {
this.openServiceNavigationContextMenu(serviceId, ready, notReady, canResetZoom);
});
ipcMain.on('open-service-content-context-menu', (
event,
webContentsId: number,
) => {
this.openServiceContentContextMenu(webContentsId);
});
// User agent
ipcMain.on('set-web-contents-user-agent', (event, webContentsId: number, userAgent: string) => {
webContents.fromId(webContentsId).setUserAgent(userAgent);
});
// Permission management
ipcMain.on('set-partition-permissions', (
event,
serviceId: number,
partition: string,
) => {
this.setPartitionPermissions(serviceId, partition);
});
// Navigation
ipcMain.on('go-forward', (event, webContentsId: number) => {
webContents.fromId(webContentsId).goForward();
});
ipcMain.on('go-back', (event, webContentsId: number) => {
webContents.fromId(webContentsId).goBack();
});
// Create new service
ipcMain.on('create-new-service', () => {
this.openServiceSettings(null);
});
window.on('enter-full-screen', () => { window.on('enter-full-screen', () => {
window.webContents.send('fullscreenchange', true); window.webContents.send('fullscreenchange', true);
}); });
@ -160,4 +177,335 @@ export default class MainWindow extends Window {
console.log('Set active service', index); console.log('Set active service', index);
this.activeServiceId = index; this.activeServiceId = index;
} }
private openServiceSettings(serviceId: number | null): void {
console.log('o', serviceId, !!this.serviceSettingsWindow);
if (!this.serviceSettingsWindow) {
console.log('Opening service settings', serviceId);
this.serviceSettingsWindow = new ServiceSettingsWindow(this.application, this, serviceId);
this.serviceSettingsWindow.setup();
this.serviceSettingsWindow.onClose(() => {
this.serviceSettingsWindow = undefined;
});
}
}
private deleteService(serviceId: number): void {
console.log('Deleting service', serviceId);
this.config.services.splice(serviceId, 1);
this.config.save();
this.getWindow().webContents.send('deleteService', serviceId);
}
private openServiceNavigationContextMenu(
serviceId: number,
ready: boolean,
notReady: boolean,
canResetZoom: boolean,
): void {
const ipc = this.getWindow().webContents;
const permissions = this.config.services[serviceId].permissions;
const menu = new Menu();
menu.append(new MenuItem({
label: 'Home', click: () => {
ipc.send('load-service-home', serviceId);
},
enabled: ready,
}));
menu.append(new MenuItem({
label: ready ? 'Reload' : 'Load', click: () => {
ipc.send('reload-service', serviceId);
},
enabled: ready || notReady,
}));
menu.append(new MenuItem({
label: 'Close', click: () => {
ipc.send('unload-service', serviceId);
},
enabled: ready,
}));
menu.append(new MenuItem({type: "separator"}));
menu.append(new MenuItem({
label: 'Reset zoom level', click: () => {
ipc.send('reset-service-zoom-level', serviceId);
},
enabled: ready && canResetZoom,
}));
menu.append(new MenuItem({
label: 'Zoom in', click: () => {
ipc.send('zoom-in-service', serviceId);
},
enabled: ready,
}));
menu.append(new MenuItem({
label: 'Zoom out', click: () => {
ipc.send('zoom-out-service', serviceId);
},
enabled: ready,
}));
menu.append(new MenuItem({type: "separator"}));
const permissionsMenu = [];
if (ready) {
for (const domain of Object.keys(permissions)) {
const domainPermissionsMenu = [];
const domainPermissions = permissions[domain];
if (domainPermissions) {
for (const permission of domainPermissions) {
domainPermissionsMenu.push({
label: (permission.authorized ? '✓' : '❌') + ' ' + permission.name,
submenu: [{
label: 'Toggle',
click: () => {
permission.authorized = !permission.authorized;
this.config.save();
},
}, {
label: 'Forget',
click: () => {
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({
label: 'Edit', click: () => {
this.openServiceSettings(serviceId);
},
}));
menu.append(new MenuItem({
label: 'Delete', click: () => {
dialog.showMessageBox(this.getWindow(), {
type: 'question',
title: 'Confirm',
message: 'Are you sure you want to delete this service?',
buttons: ['Cancel', 'Confirm'],
cancelId: 0,
}).then(result => {
if (result.response === 1) {
this.deleteService(serviceId);
}
}).catch(console.error);
},
}));
menu.popup({window: this.getWindow()});
}
private openServiceContentContextMenu(
webContentsId: number,
): void {
const serviceWebContents = webContents.fromId(webContentsId);
serviceWebContents.on('context-menu', (event, props: ContextMenuParams) => {
const menu = new Menu();
const {editFlags} = props;
// linkURL
if (props.linkURL.length > 0) {
if (menu.items.length > 0) {
menu.append(new MenuItem({type: 'separator'}));
}
menu.append(new MenuItem({
label: 'Copy link URL',
click: () => {
clipboard.writeText(props.linkURL);
},
}));
menu.append(new MenuItem({
label: 'Open URL in default browser',
click: () => {
this.application.openExternalLink(props.linkURL)
.catch(console.error);
},
}));
}
// Image
if (props.hasImageContents) {
if (menu.items.length > 0) {
menu.append(new MenuItem({type: 'separator'}));
}
menu.append(new MenuItem({
label: 'Copy image',
click: () => {
serviceWebContents.copyImageAt(props.x, props.y);
},
}));
menu.append(new MenuItem({
label: 'Save image as',
click: () => {
serviceWebContents.downloadURL(props.srcURL);
},
}));
}
// Text clipboard
if (editFlags.canUndo || editFlags.canRedo || editFlags.canCut || editFlags.canCopy || editFlags.canPaste ||
editFlags.canDelete) {
if (editFlags.canUndo || editFlags.canRedo) {
if (menu.items.length > 0) {
menu.append(new MenuItem({type: 'separator'}));
}
if (editFlags.canUndo) {
menu.append(new MenuItem({
label: 'Undo',
role: 'undo',
}));
}
if (editFlags.canRedo) {
menu.append(new MenuItem({
label: 'Redo',
role: 'redo',
}));
}
}
if (menu.items.length > 0) {
menu.append(new MenuItem({type: 'separator'}));
}
menu.append(new MenuItem({
label: 'Cut',
role: 'cut',
enabled: editFlags.canCut,
}));
menu.append(new MenuItem({
label: 'Copy',
role: 'copy',
enabled: editFlags.canCopy,
}));
menu.append(new MenuItem({
label: 'Paste',
role: 'paste',
enabled: editFlags.canPaste,
}));
menu.append(new MenuItem({
label: 'Delete',
role: 'delete',
enabled: editFlags.canDelete,
}));
}
if (editFlags.canSelectAll) {
if (menu.items.length > 0) {
menu.append(new MenuItem({type: 'separator'}));
}
menu.append(new MenuItem({
label: 'Select all',
role: 'selectAll',
}));
}
// Inspect element
if (menu.items.length > 0) {
menu.append(new MenuItem({type: 'separator'}));
}
menu.append(new MenuItem({
label: 'Inspect element',
click: () => {
serviceWebContents.inspectElement(props.x, props.y);
},
}));
menu.popup({
window: this.getWindow(),
});
});
}
private setPartitionPermissions(
serviceId: number,
partition: string,
): void {
const service = this.config.services[serviceId];
function getUrlDomain(url: string | undefined) {
if (!url) return '';
const matches = url.match(/^https?:\/\/((.+?)\/|(.+))/i);
if (matches !== null) {
let domain = matches[1];
if (domain.endsWith('/')) domain = domain.substr(0, domain.length - 1);
return domain;
}
return '';
}
function getDomainPermissions(domain: string) {
let domainPermissions = service.permissions[domain];
if (!domainPermissions) domainPermissions = service.permissions[domain] = [];
return domainPermissions;
}
const serviceSession = session.fromPartition(partition);
serviceSession.setPermissionRequestHandler((webContents, permissionName, callback, details) => {
const domain = getUrlDomain(details.requestingUrl);
const domainPermissions = getDomainPermissions(domain);
const existingPermissions = domainPermissions.filter(p => p.name === permissionName);
if (existingPermissions.length > 0) {
callback(existingPermissions[0].authorized);
return;
}
dialog.showMessageBox(this.getWindow(), {
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,
});
this.config.save();
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);
const domain = getUrlDomain(details.requestingUrl);
const domainPermissions = getDomainPermissions(domain);
const existingPermissions = domainPermissions.filter(p => p.name === permissionName);
return existingPermissions.length > 0 && existingPermissions[0].authorized;
});
}
} }

View File

@ -16,8 +16,8 @@ export default class ServiceSettingsWindow extends Window {
super.setup({ super.setup({
webPreferences: { webPreferences: {
nodeIntegration: true, nodeIntegration: true,
enableRemoteModule: true,
webviewTag: true, webviewTag: true,
contextIsolation: false,
}, },
modal: true, modal: true,
autoHideMenuBar: true, autoHideMenuBar: true,

View File

@ -10,8 +10,8 @@ export default class SettingsWindow extends Window {
super.setup({ super.setup({
webPreferences: { webPreferences: {
nodeIntegration: true, nodeIntegration: true,
enableRemoteModule: true,
webviewTag: true, webviewTag: true,
contextIsolation: false,
}, },
modal: true, modal: true,
autoHideMenuBar: true, autoHideMenuBar: true,

View File

@ -1,5 +1,7 @@
const path = require('path'); const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const ImageMinimizerPlugin = require("image-minimizer-webpack-plugin");
const {extendDefaultPlugins} = require("svgo");
const CopyWebpackPlugin = require('copy-webpack-plugin'); const CopyWebpackPlugin = require('copy-webpack-plugin');
const dev = process.env.NODE_ENV === 'development'; const dev = process.env.NODE_ENV === 'development';
@ -37,9 +39,6 @@ const config = {
use: [ use: [
{ {
loader: MiniCssExtractPlugin.loader, loader: MiniCssExtractPlugin.loader,
options: {
publicPath: '/',
}
}, },
'css-loader', 'css-loader',
'sass-loader', 'sass-loader',
@ -47,25 +46,17 @@ const config = {
}, },
{ {
test: /\.(woff2?|eot|ttf|otf)$/i, test: /\.(woff2?|eot|ttf|otf)$/i,
use: 'file-loader?name=../fonts/[name].[ext]', type: 'asset/resource',
generator: {
filename: '../fonts/[name][ext]',
},
}, },
{ {
test: /\.(png|jpe?g|gif|svg)$/i, test: /\.(png|jpe?g|gif|svg)$/i,
use: [ type: 'asset/resource',
'file-loader?name=../images/[name].[ext]', generator: {
{ filename: '../images/[name][ext]',
loader: 'img-loader', },
options: {
enabled: !dev,
plugins: [
require('imagemin-gifsicle')({}),
require('imagemin-mozjpeg')({}),
require('imagemin-pngquant')({}),
require('imagemin-svgo')({}),
]
}
}
]
}, },
{ {
test: /\.ts$/i, test: /\.ts$/i,
@ -75,13 +66,14 @@ const config = {
configFile: 'tsconfig.frontend.json', configFile: 'tsconfig.frontend.json',
} }
}, },
exclude: '/node_modules/' exclude: '/node_modules/',
}, },
{ {
test: /\.html$/i, test: /\.html$/i,
use: [ type: 'asset/resource',
'file-loader?name=../[name].[ext]', generator: {
] filename: '../[name][ext]',
},
} }
], ],
}, },
@ -94,6 +86,56 @@ const config = {
{from: 'node_modules/@fortawesome/fontawesome-free/svgs', to: '../images/icons'} {from: 'node_modules/@fortawesome/fontawesome-free/svgs', to: '../images/icons'}
] ]
}), }),
new ImageMinimizerPlugin({
minimizer: {
implementation: ImageMinimizerPlugin.imageminMinify,
options: {
// Lossless optimization with custom option
// Feel free to experiment with options for better result for you
plugins: [
["gifsicle", {}],
["mozjpeg", {}],
["pngquant", {}],
// Svgo configuration here https://github.com/svg/svgo#configuration
[
"svgo",
{
plugins: extendDefaultPlugins([
{
name: "removeViewBox",
active: false,
},
{
name: "addAttributesToSVGElement",
params: {
attributes: [{ xmlns: "http://www.w3.org/2000/svg" }],
},
},
]),
},
// todo: still not fixed
// {
// plugins: {
// name: 'preset-default',
// params: {
// overrides: {
// removeViewBox: {
// active: false,
// },
// addAttributesToSVGElement: {
// params: {
// attributes: [{xmlns: "http://www.w3.org/2000/svg"}],
// },
// },
// },
// },
// },
// },
],
],
},
},
}),
] ]
}; };

5873
yarn.lock

File diff suppressed because it is too large Load Diff