Skip to content

Commit 4f249e8

Browse files
committed
ADD UPDATE TITLE
1 parent ca20acf commit 4f249e8

13 files changed

+44
-222
lines changed

.vscode/launch.json

-59
This file was deleted.

.vscode/tasks.json

-12
This file was deleted.

README-resources/gif.gif

-6 MB
Binary file not shown.

README.md

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1 @@
1-
# electron-browser
2-
3-
Simple yet powerful library for implimenting browser in electron.
4-
5-
Each tab has its own webview, so every renderer is seperated from each other.
6-
7-
You can also add 'div' view, which allows any html content you want to use for the tab. This allows more control.
8-
9-
Comes with built int dark and light theme for the tabs.
10-
11-
![](README-resources/gif.gif)
1+
# electron-browser

src/electron-browser.js

+43-28
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
let instanceId = 0
32

43
const Draggabilly = require('draggabilly')
@@ -23,7 +22,6 @@ class ChromeTabs {
2322

2423
init(el) {
2524
this.DOM_chrome_tabs = el
26-
2725
this.instanceId = instanceId
2826
this.DOM_chrome_tabs.setAttribute(DATA_TABS_INSTANCE_ID, this.instanceId)
2927
instanceId += 1
@@ -36,7 +34,9 @@ class ChromeTabs {
3634
}
3735

3836
emit(eventName, data) {
39-
this.DOM_chrome_tabs.dispatchEvent(new CustomEvent(eventName, { detail: data }))
37+
this.DOM_chrome_tabs.dispatchEvent(new CustomEvent(eventName, {
38+
detail: data
39+
}))
4040
}
4141

4242
setupCustomProperties() {
@@ -149,7 +149,10 @@ class ChromeTabs {
149149
return div.firstElementChild
150150
}
151151

152-
addTab(tabProperties, { animate = true, background = false } = {}) {
152+
addTab(tabProperties, {
153+
animate = true,
154+
background = false
155+
} = {}) {
153156
const tabEl = this.createNewTabEl()
154157

155158
if (animate) {
@@ -161,7 +164,9 @@ class ChromeTabs {
161164
this.tabContentEl.appendChild(tabEl)
162165
this.setTabCloseEventListener(tabEl)
163166
this.updateTab(tabEl, tabProperties)
164-
this.emit('tabAdd', { tabEl })
167+
this.emit('tabAdd', {
168+
tabEl
169+
})
165170
if (!background) this.setCurrentTab(tabEl)
166171
this.cleanUpPreviouslyDraggedTabs()
167172
this.layoutTabs()
@@ -191,10 +196,15 @@ class ChromeTabs {
191196
}
192197
tabEl.setAttribute('active', '')
193198
tabEl.classList.add("selected")
194-
this.emit('activeTabChange', { tabEl })
199+
this.emit('activeTabChange', {
200+
tabEl
201+
})
195202
}
196203

197204
removeTab(tabEl) {
205+
if (document.getElementsByTagName('webview').length == 1) {
206+
return
207+
}
198208
if (tabEl === this.activeTabEl) {
199209
if (tabEl.nextElementSibling) {
200210
this.setCurrentTab(tabEl.nextElementSibling)
@@ -203,7 +213,9 @@ class ChromeTabs {
203213
}
204214
}
205215
tabEl.parentNode.removeChild(tabEl)
206-
this.emit('tabRemove', { tabEl })
216+
this.emit('tabRemove', {
217+
tabEl
218+
})
207219
this.cleanUpPreviouslyDraggedTabs()
208220
this.layoutTabs()
209221
this.setupDraggabilly()
@@ -226,6 +238,10 @@ class ChromeTabs {
226238
}
227239
}
228240

241+
setTitle(tabEl, title) {
242+
tabEl.querySelector(`.${TAB_CLASS}-title`).textContent = title
243+
}
244+
229245
cleanUpPreviouslyDraggedTabs() {
230246
this.tabEls.forEach((tabEl) => tabEl.classList.remove(`${TAB_CLASS}-was-just-dragged`))
231247
}
@@ -317,13 +333,17 @@ class ChromeTabs {
317333
} else {
318334
tabEl.parentNode.insertBefore(tabEl, this.tabEls[destinationIndex + 1])
319335
}
320-
this.emit('tabReorder', { tabEl, originIndex, destinationIndex })
336+
this.emit('tabReorder', {
337+
tabEl,
338+
originIndex,
339+
destinationIndex
340+
})
321341
this.layoutTabs()
322342
}
323343
}
324344

325345

326-
const noop = _ => { }
346+
const noop = _ => {}
327347

328348
const closest = (value, array) => {
329349
let closest = Infinity
@@ -352,7 +372,7 @@ const tabTemplate = `
352372
`
353373

354374
const defaultTapProperties = {
355-
title: 'New tab',
375+
title: '新标签',
356376
favicon: false
357377
}
358378

@@ -365,7 +385,7 @@ class ElectronChromeTabs {
365385
accTabId = 0; //Tab id accumulator
366386

367387
tabs = []
368-
views = []
388+
views = []
369389

370390
viewToPush = undefined;
371391

@@ -405,9 +425,8 @@ class ElectronChromeTabs {
405425
let id = this.accTabId++
406426
tab["data-ectTabId"] = id
407427
this.tabs.push(tab)
408-
//console.debug("Tab added:", id, event.detail)
409428

410-
if(this.viewToPush)
429+
if (this.viewToPush)
411430
this.views.push(this.viewToPush)
412431
else {
413432
throw "View to push is undefined"
@@ -417,35 +436,28 @@ class ElectronChromeTabs {
417436
this.DOM_tabs.addEventListener("tabRemove", (event) => {
418437
let tab = event.detail.tabEl
419438
let id = tab["data-ectTabId"]
420-
console.debug("Tab remove: ", id)
421-
422-
console.debug("Tab array: ", this.views)
423-
424-
this.views[id].remove() //Delete from document
425-
delete this.views[id] //Delete from array
426-
427-
console.debug("Tab array after delete: ", this.views)
439+
this.views[id].remove()
440+
delete this.views[id]
428441
});
429442
}
430443

431-
addTab(title, favicon="", src=undefined) {
444+
addTab(title, favicon = "", src = undefined) {
432445
let child = undefined
433-
if(src) {
434-
console.log("Adding webview view")
446+
if (src) {
447+
// console.log("Adding webview view" + this.accTabId)
435448
child = document.createElement("webview")
436449
child.setAttribute("src", src);
450+
child.setAttribute("id", 'julan' + (this.accTabId ? this.accTabId : null));
451+
child.setAttribute("allowpopups", true)
437452
} else {
438-
console.log("Adding div view")
453+
// console.log("Adding div view")
439454
child = document.createElement("div");
440-
441-
//child.innerHTML = "<html><body>Test Body</body></html>"
442455
}
443456
child.classList.add("eb-view");
444457
child.dataset.eb_view_id = this.accTabId;
445458

446459
this.viewToPush = child;
447460

448-
449461
this.DOM_browser_views.appendChild(child);
450462

451463
let tabEl = chromeTabs.addTab({
@@ -473,6 +485,9 @@ class ElectronChromeTabs {
473485
"activeWebview": this.activeView
474486
}
475487
}
488+
setCurrentTitle(title) {
489+
chromeTabs.setTitle(this.activeTab, title)
490+
}
476491

477492
hideTabsBar() {
478493
document.getElementById("eb-tabs-bar").style.display = "none";
-5.3 KB
Binary file not shown.
-5.3 KB
Binary file not shown.
-31.3 KB
Binary file not shown.

src/example/index.css

-14
This file was deleted.

src/example/index.html

-30
This file was deleted.

src/example/index.js

-48
This file was deleted.

src/example/renderer.js

-15
This file was deleted.

src/example/test.html

-5
This file was deleted.

0 commit comments

Comments
 (0)