feat: work without any nodeIntegration requirements

This commit is contained in:
Todd Tarsi 2021-05-23 20:09:47 -05:00
parent 986f762ae1
commit 2b8e506f5a
3 changed files with 15 additions and 6 deletions

View file

@ -23,7 +23,6 @@ Electron-tabs uses webviews, so you first need to use the following `webPreferen
```js
const mainWindow = new electron.BrowserWindow({
webPreferences: {
nodeIntegration: true,
webviewTag: true
}
});

View file

@ -4,7 +4,6 @@ const app = electron.app;
app.on('ready', function () {
const mainWindow = new electron.BrowserWindow({
webPreferences: {
nodeIntegration: true,
webviewTag: true
}
});

View file

@ -1,5 +1,3 @@
const EventEmitter = require("events");
if (!document) {
throw Error("electron-tabs module must be called in renderer process");
}
@ -22,6 +20,19 @@ if (!document) {
document.getElementsByTagName("head")[0].appendChild(styleTag);
})();
/**
* This makes the browser EventTarget API work similar to EventEmitter
*/
class EventEmitter extends EventTarget {
emit (type, ...args) {
this.dispatchEvent(new CustomEvent(type, { detail: args }));
}
on (type, fn) {
this.addEventListener(type, ({ detail }) => fn.apply(this, detail));
}
}
class TabGroup extends EventEmitter {
constructor (args = {}) {
super();
@ -126,8 +137,8 @@ const TabGroupPrivate = {
initVisibility: function () {
function toggleTabsVisibility(tab, tabGroup) {
var visibilityThreshold = this.options.visibilityThreshold;
var el = tabGroup.tabContainer.parentNode;
let visibilityThreshold = this.options.visibilityThreshold;
let el = tabGroup.tabContainer.parentNode;
if (this.tabs.length >= visibilityThreshold) {
el.classList.add("visible");
} else {