Compare commits

..

No commits in common. "develop" and "v1.1.15" have entirely different histories.

20 changed files with 3842 additions and 3226 deletions

View File

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

View File

@ -4,7 +4,10 @@
<meta charset="UTF-8">
<title>An error occured</title>
<meta http-equiv="Content-Security-Policy"
content="style-src 'self' 'unsafe-inline'; font-src 'self'; script-src 'self'">
content="style-src 'self' 'unsafe-inline' https://use.fontawesome.com; font-src 'self' https://use.fontawesome.com; 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/error.css">

View File

@ -4,7 +4,10 @@
<meta charset="UTF-8">
<title>An error occured</title>
<meta http-equiv="Content-Security-Policy"
content="style-src 'self' 'unsafe-inline'; font-src 'self'; script-src 'self'">
content="style-src 'self' 'unsafe-inline' https://use.fontawesome.com; font-src 'self' https://use.fontawesome.com; 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/error.css">

View File

@ -4,7 +4,10 @@
<meta charset="UTF-8">
<title>Tabs</title>
<meta http-equiv="Content-Security-Policy" content="style-src 'self' 'unsafe-inline'; font-src 'self'; script-src 'self' 'sha256-oPC0l5nxLnJ2LX6qU9Laxa4/cjhuHDRIqdUsBDWYqnw='">
<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='">
<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/index.css">

View File

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

View File

@ -4,7 +4,10 @@
<meta charset="UTF-8">
<title>Service settings</title>
<meta http-equiv="Content-Security-Policy" content="style-src 'self' 'unsafe-inline'; font-src 'self'; script-src 'self' 'sha256-5gY/z34s5Mtc3YL8GkwZQhzk9LymQIuFUQRVvs7Gh0o='">
<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='">
<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/service-settings.css">

View File

@ -5,7 +5,10 @@
<title>Service settings</title>
<meta http-equiv="Content-Security-Policy"
content="style-src 'self' 'unsafe-inline'; font-src 'self'; script-src 'self' 'sha256-UoPUIMX0PZl7cy3YoegZ0EDleSaHxTURPMyK09xsa0E='">
content="style-src 'self' 'unsafe-inline' https://use.fontawesome.com; font-src 'self' https://use.fontawesome.com; 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/service-settings.css">

View File

@ -1,8 +1,26 @@
import {DidFailLoadEvent, ipcRenderer, PageFaviconUpdatedEvent, UpdateTargetUrlEvent} from "electron";
import {
clipboard,
ContextMenuParams,
DidFailLoadEvent,
ipcRenderer,
PageFaviconUpdatedEvent,
remote,
shell,
UpdateTargetUrlEvent,
WebContents,
WebviewTag,
} from "electron";
import Service from "../../src/Service";
import {IconProperties, IconSet, SpecialPages} from "../../src/Meta";
import Config from "../../src/Config";
const {
Menu,
MenuItem,
dialog,
session,
} = remote;
const appInfo: {
title?: string;
} = {};
@ -24,6 +42,101 @@ let serviceSelector: HTMLElement | null = null;
let lastDragPosition: HTMLElement | 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"}));
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', (
event,
@ -117,44 +230,6 @@ ipcRenderer.on('data', (
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 {
// Remove nav
const nav = document.querySelector('#service-selector');
@ -255,20 +330,7 @@ function createServiceNavigationElement(index: number, nextNavButton?: Element |
ipcRenderer.send('setActiveService', id);
}
});
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,
);
});
button.addEventListener('contextmenu', e => openServiceContextMenu(e, index));
let icon: HTMLImageElement | HTMLElement;
if (service.useFavicon && service.favicon != null) {
@ -400,7 +462,7 @@ document.addEventListener('DOMContentLoaded', () => {
refreshButton?.addEventListener('click', () => reload());
addButton = document.getElementById('add-button');
addButton?.addEventListener('click', () => ipcRenderer.send('create-new-service', null));
addButton?.addEventListener('click', () => ipcRenderer.send('openServiceSettings', null));
settingsButton = document.getElementById('settings-button');
settingsButton?.addEventListener('click', () => ipcRenderer.send('openSettings', null));
@ -443,9 +505,12 @@ function loadService(serviceId: number, service: FrontService) {
view.setAttribute('enableRemoteModule', 'false');
view.setAttribute('partition', 'persist:service_' + service.partition);
view.setAttribute('autosize', 'true');
view.setAttribute('allowpopups', 'true');
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
view.addEventListener('did-fail-load', (e: DidFailLoadEvent) => {
if (e.errorCode <= -100 && e.errorCode > -200) {
@ -482,17 +547,72 @@ function loadService(serviceId: number, service: FrontService) {
}
});
const webContents = remote.webContents.fromId(view.getWebContentsId());
// Set custom user agent
if (typeof service.customUserAgent === 'string') {
ipcRenderer.send('set-web-contents-user-agent', view.getWebContentsId(), service.customUserAgent);
webContents.setUserAgent(service.customUserAgent);
}
// Set context menu
ipcRenderer.send('open-service-content-context-menu', view.getWebContentsId());
setContextMenu(webContents);
// Set permission request handler
ipcRenderer.send('set-partition-permissions', serviceId, view.partition);
function getUrlDomain(url: string) {
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);
});
@ -573,6 +693,13 @@ 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() {
console.debug('Updating navigation');
// Update active list element
@ -617,8 +744,7 @@ function updateNavigation() {
}
function updateStatusButton() {
if (typeof selectedServiceId !== 'number') return;
if (!selectedServiceId) return;
const protocol = services[selectedServiceId]?.view?.getURL().split('://')[0] || 'unknown';
securityButton?.childNodes.forEach(el => {
if (el instanceof HTMLElement) {
@ -630,11 +756,11 @@ function updateStatusButton() {
function updateWindowTitle() {
if (selectedServiceId === null) {
ipcRenderer.send('update-window-title', null);
ipcRenderer.send('updateWindowTitle', null);
} else {
const service = services[selectedServiceId];
if (service?.viewReady && service.view) {
ipcRenderer.send('update-window-title', selectedServiceId, service.view.getWebContentsId());
ipcRenderer.send('updateWindowTitle', selectedServiceId, remote.webContents.fromId(service.view.getWebContentsId()).getTitle());
}
}
}
@ -653,14 +779,14 @@ function goForward() {
if (selectedServiceId === null) return;
const view = services[selectedServiceId]?.view;
if (view) ipcRenderer.send('go-forward', view.getWebContentsId());
if (view) remote.webContents.fromId(view.getWebContentsId()).goForward();
}
function goBack() {
if (selectedServiceId === null) return;
const view = services[selectedServiceId]?.view;
if (view) ipcRenderer.send('go-back', view.getWebContentsId());
if (view) remote.webContents.fromId(view.getWebContentsId()).goBack();
}
function reload() {
@ -669,13 +795,140 @@ function reload() {
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) => {
if (fullscreen) document.body.classList.add('fullscreen');
else document.body.classList.remove('fullscreen');
});
type FrontService = Service & {
view?: Electron.WebviewTag;
view?: WebviewTag;
viewReady?: boolean;
li?: NavigationElement;
};

View File

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

View File

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

View File

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

View File

@ -1,4 +1,4 @@
import {app, dialog, Menu, shell, Tray} from "electron";
import {app, Menu, shell, Tray} from "electron";
import Meta from "./Meta";
import Config from "./Config";
import Updater from "./Updater";
@ -52,36 +52,16 @@ export default class Application {
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() {
// Open external links in default OS browser
app.on('web-contents-created', (e, contents) => {
if (contents.getType() === 'webview') {
console.log('Setting external links to open in default OS browser');
contents.setWindowOpenHandler(details => {
if (details.url.startsWith(details.referrer.url)) return {action: 'allow'};
const url = details.url;
this.openExternalLink(url)
.catch(console.error);
return {action: 'deny'};
contents.on('new-window', (e, url) => {
e.preventDefault();
if (url.startsWith('https://')) {
shell.openExternal(url).catch(console.error);
}
});
}
});

View File

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

View File

@ -32,19 +32,6 @@ export default abstract class Window {
this.teardown();
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 {
@ -93,7 +80,6 @@ export default abstract class Window {
public getWindow(): BrowserWindow {
if (!this.window) throw Error('Window not initialized.');
else if (this.window.isDestroyed()) throw Error('Window destroyed.');
return this.window;
}
}

View File

@ -4,9 +4,6 @@ import {app} from "electron";
import Meta from "./Meta";
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());
// Check if application is already running

View File

@ -1,10 +1,11 @@
import path from "path";
import {clipboard, ContextMenuParams, dialog, ipcMain, Menu, MenuItem, session, webContents} from "electron";
import {ipcMain} from "electron";
import ServiceSettingsWindow from "./ServiceSettingsWindow";
import SettingsWindow from "./SettingsWindow";
import Application from "../Application";
import Meta, {SpecialPages} from "../Meta";
import Window from "../Window";
import {ServicePermissions} from "../Service";
export default class MainWindow extends Window {
private activeServiceId: number = 0;
@ -19,8 +20,8 @@ export default class MainWindow extends Window {
super.setup({
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true,
webviewTag: true,
contextIsolation: false,
},
autoHideMenuBar: true,
icon: Meta.ICON_PATH,
@ -80,14 +81,40 @@ export default class MainWindow extends Window {
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
ipcMain.on('update-window-title', (event, serviceId: number | null, webContentsId?: number) => {
ipcMain.on('updateWindowTitle', (event, serviceId: number | null, viewTitle?: string) => {
if (serviceId === null) {
window.setTitle(Meta.title);
} else if (webContentsId) {
} else if (viewTitle) {
const service = this.config.services[serviceId];
const serviceWebContents = webContents.fromId(webContentsId);
window.setTitle(Meta.getTitleForService(service, serviceWebContents.getTitle()));
window.setTitle(Meta.getTitleForService(service, viewTitle));
}
});
// 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;
});
}
});
@ -103,50 +130,6 @@ 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.webContents.send('fullscreenchange', true);
});
@ -177,335 +160,4 @@ export default class MainWindow extends Window {
console.log('Set active service', 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({
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true,
webviewTag: true,
contextIsolation: false,
},
modal: true,
autoHideMenuBar: true,

View File

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

View File

@ -1,7 +1,5 @@
const path = require('path');
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 dev = process.env.NODE_ENV === 'development';
@ -39,6 +37,9 @@ const config = {
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: '/',
}
},
'css-loader',
'sass-loader',
@ -46,17 +47,25 @@ const config = {
},
{
test: /\.(woff2?|eot|ttf|otf)$/i,
type: 'asset/resource',
generator: {
filename: '../fonts/[name][ext]',
},
use: 'file-loader?name=../fonts/[name].[ext]',
},
{
test: /\.(png|jpe?g|gif|svg)$/i,
type: 'asset/resource',
generator: {
filename: '../images/[name][ext]',
},
use: [
'file-loader?name=../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,
@ -66,14 +75,13 @@ const config = {
configFile: 'tsconfig.frontend.json',
}
},
exclude: '/node_modules/',
exclude: '/node_modules/'
},
{
test: /\.html$/i,
type: 'asset/resource',
generator: {
filename: '../[name][ext]',
},
use: [
'file-loader?name=../[name].[ext]',
]
}
],
},
@ -86,56 +94,6 @@ const config = {
{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"}],
// },
// },
// },
// },
// },
// },
],
],
},
},
}),
]
};

5997
yarn.lock

File diff suppressed because it is too large Load Diff