Use ES modules and single-instance, and update default config

This commit is contained in:
Alice Gaudon 2020-01-03 15:01:15 +01:00
parent 6b771982f9
commit 3abd3dfd5e
6 changed files with 67 additions and 24 deletions

View File

@ -1,6 +1,6 @@
{
"name": "tabs",
"version": "0.0.1",
"version": "0.0.2",
"description": "Persistent and separate browser tabs in one window",
"author": {
"name": "Alice Gaudon",
@ -8,7 +8,8 @@
},
"homepage": "https://gitlab.com/ArisuOngaku/tabs",
"license": "MIT",
"main": "src/main.js",
"main": "tabs.js",
"type": "module",
"scripts": {
"start": "electron .",
"dev": "electron . --dev",
@ -17,6 +18,11 @@
"pack": "electron-builder --dir",
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"ejs": "^3.0.1",
"esm": "^3.2.25",
"single-instance": "^0.0.1"
},
"devDependencies": {
"electron": "^6.0.10",
"electron-builder": "^21.2.0"

View File

@ -1,12 +1,13 @@
const fs = require('fs');
const path = require('path');
import fs from "fs";
import path from "path";
import {homedir} from "os";
const Service = require('./Service');
import Service from "./Service";
const configDir = path.resolve(__dirname, '../config');
const configDir = path.resolve(homedir(), '.tabs-app');
const configFile = path.resolve(configDir, 'config.json');
class Config {
export default class Config {
constructor() {
// Load data from config file
let data = {};
@ -28,8 +29,7 @@ class Config {
}
if (this.services.length === 0) {
this.services.push(new Service('webmail', 'WebMail', 'far fa-envelope', false, 'https://mail.arisu.fr/', true));
this.services.push(new Service('arisucloud', 'Arisu Cloud', 'arisucloud.svg', true, 'https://cloud.arisu.fr/', true));
this.services.push(new Service('welcome', 'Welcome', 'fas fa-rocket', false, 'https://gitlab.com/ArisuOngaku/tabs', false));
}
this.save();
@ -38,6 +38,4 @@ class Config {
save() {
fs.writeFileSync(configFile, JSON.stringify(this, null, 4));
}
}
module.exports = Config;
}

View File

@ -35,4 +35,4 @@ Service.requiredProperties = {
'useFavicon': true,
};
module.exports = Service;
export default Service;

View File

@ -1,15 +1,11 @@
const {
app,
BrowserWindow,
ipcMain,
Tray,
Menu,
} = require('electron');
const fs = require('fs');
const path = require('path');
const Config = require('./Config');
import fs from "fs";
import path from "path";
import {app, BrowserWindow, ipcMain, Menu, Tray} from "electron";
import Config from "./Config";
const resourcesDir = path.resolve(__dirname, '../resources');
const iconPath = path.resolve(resourcesDir, 'logo.png');
const config = new Config();
@ -33,7 +29,7 @@ function toggleMainWindow() {
function createWindow() {
// System tray
tray = new Tray(path.resolve(resourcesDir, 'logo.png'));
tray = new Tray(iconPath);
tray.setToolTip('Tabs');
tray.setContextMenu(Menu.buildFromTemplate([
{label: 'Tabs', enabled: false},
@ -51,6 +47,7 @@ function createWindow() {
webviewTag: true,
},
autoHideMenuBar: true,
icon: iconPath,
});
window.maximize();
window.on('closed', () => {
@ -103,6 +100,9 @@ function createWindow() {
mode: 'right'
});
}
addServiceWindow.webContents.on('dom-ready', () => {
addServiceWindow.webContents.send('syncIcons', listIcons('brands'), listIcons('solid'));
});
addServiceWindow.loadFile(path.resolve(resourcesDir, 'add-service.html'))
.catch(console.error);
}
@ -117,4 +117,11 @@ function setActiveService(index) {
selectedService = index;
}
function listIcons(set) {
const directory = path.resolve(resourcesDir, 'icons/' + set);
const icons = [];
fs.readdirSync(directory).forEach(i => icons.push(i.split('.svg')[0]));
return icons;
}
app.on('ready', createWindow);

10
tabs.js Normal file
View File

@ -0,0 +1,10 @@
#!/bin/electron
const SingleInstance = require('single-instance');
const lock = new SingleInstance('tabs-app');
lock.lock().then(() => {
require = require("esm")(module);
module.exports = require("./src/main.js");
}).catch(error => {
console.error(error);
process.exit(0);
});

View File

@ -492,6 +492,11 @@ ejs@^2.6.2:
resolved "https://registry.yarnpkg.com/ejs/-/ejs-2.7.4.tgz#48661287573dcc53e366c7a1ae52c3a120eec9ba"
integrity sha512-7vmuyh5+kuUyJKePhQfRQBhXV5Ce+RnaeeQArKu1EAMpL3WbgMt5WG6uQZpEVvYSSsxMXRKOewtDk9RaTKXRlA==
ejs@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/ejs/-/ejs-3.0.1.tgz#30c8f6ee9948502cc32e85c37a3f8b39b5a614a5"
integrity sha512-cuIMtJwxvzumSAkqaaoGY/L6Fc/t6YvoP9/VIaK0V/CyqKLEQ8sqODmYfy/cjXEdZ9+OOL8TecbJu+1RsofGDw==
electron-builder@^21.2.0:
version "21.2.0"
resolved "https://registry.yarnpkg.com/electron-builder/-/electron-builder-21.2.0.tgz#b68ec4def713fc0b8602654ce842f972432f50c5"
@ -577,6 +582,11 @@ escape-string-regexp@^1.0.5:
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=
esm@^3.2.25:
version "3.2.25"
resolved "https://registry.yarnpkg.com/esm/-/esm-3.2.25.tgz#342c18c29d56157688ba5ce31f8431fbb795cc10"
integrity sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==
esprima@^4.0.0:
version "4.0.1"
resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71"
@ -1508,6 +1518,11 @@ responselike@^1.0.2:
dependencies:
lowercase-keys "^1.0.0"
rsvp@^3.1.0:
version "3.6.2"
resolved "https://registry.yarnpkg.com/rsvp/-/rsvp-3.6.2.tgz#2e96491599a96cde1b515d5674a8f7a91452926a"
integrity sha512-OfWGQTb9vnwRjwtA2QwpG2ICclHC3pgXZO5xt8H2EfgDquO0qVdSb5T88L4qJVAEugbS56pAuV4XZM58UX8ulw==
safe-buffer@^5.0.1, safe-buffer@^5.1.2:
version "5.2.0"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.0.tgz#b74daec49b1148f88c64b68d49b1e815c1f2f519"
@ -1574,6 +1589,13 @@ signal-exit@^3.0.0, signal-exit@^3.0.2:
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
integrity sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=
single-instance@^0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/single-instance/-/single-instance-0.0.1.tgz#ef0f0673fe9800b6753445d97058d253f5d4b8ed"
integrity sha1-7w8Gc/6YALZ1NEXZcFjSU/XUuO0=
dependencies:
rsvp "^3.1.0"
single-line-log@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/single-line-log/-/single-line-log-1.1.2.tgz#c2f83f273a3e1a16edb0995661da0ed5ef033364"