Skip to content

Commit a1e91df

Browse files
committed
add button to unload web panel, add option to unload web panel after closing
1 parent b8a164c commit a1e91df

File tree

7 files changed

+148
-29
lines changed

7 files changed

+148
-29
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ There are many forks of Firefox, but I prefer to continue using the original bro
1515
1. Adding a new web panel by left-clicking on the plus sign. If you are on a web page, the current address will be automatically inserted into the address bar.
1616
2. Changing the width of the sidebar, each web panel has its own width.
1717
3. Pinning and unpinning the sidebar, each web panel has its own state. In the pinned state, the sidebar will be located statically next to the page. The unpinned sidebar appears on top of the page and closes when the focus is lost.
18-
4. Editing the web panel by right-clicking on the corresponding button:
18+
4. Closing sidebar with unloading of the web panel;
19+
5. Editing the web panel by right-clicking on the corresponding button:
1920
- Changing the web address.
2021
- Changing the favicon.
2122
- Resetting the favicon.
23+
- Option to unload from memory after closing.
2224
- Moving the web panel button.
2325
- Deleting the web panel.
24-
5. Managing the page opened in the web panel: going back and forth, refreshing the page and going to the home page.
25-
6. Sound indicator.
26+
6. Managing the page opened in the web panel: going back and forth, refreshing the page and going to the home page.
27+
7. Sound indicator.
2628

2729
## Install
2830

second_sidebar.uc.mjs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { SidebarController } from './second_sidebar/sidebar_controller.mjs';
1+
import { SidebarController } from "./second_sidebar/sidebar_controller.mjs";
22

33
const TIMEOUT = 1000;
44

55
const STYLE = `
6+
@import url("chrome://global/content/elements/moz-toggle.css");
7+
68
#browser {
79
position: relative;
810
@@ -109,8 +111,8 @@ const STYLE = `
109111
#sidebar-2-toolbar {
110112
display: flex;
111113
flex-direction: row;
112-
gap: 8px;
113-
padding: 4px;
114+
gap: 4px;
115+
padding: 4px 0;
114116
background-color: var(--toolbar-bgcolor);
115117
color: var(--toolbar-color);
116118
}
@@ -216,6 +218,12 @@ const STYLE = `
216218
background-repeat: no-repeat;
217219
}
218220
221+
#sidebar-2-web-panel-popup-edit-unload-group {
222+
justify-content: space-between;
223+
align-items: center;
224+
width: 100%;
225+
}
226+
219227
#sidebar-2-web-panel-popup-edit-multiview-buttons-row {
220228
justify-content: space-between;
221229
width: 100%;
@@ -239,14 +247,14 @@ class SecondSidebar {
239247
}
240248

241249
decorate() {
242-
const style = document.createElement('style');
250+
const style = document.createElement("style");
243251
style.innerHTML = STYLE;
244-
document.querySelector('head').appendChild(style);
252+
document.querySelector("head").appendChild(style);
245253
}
246254
}
247255

248256
var interval = setInterval(() => {
249-
if (document.querySelector('#browser')) {
257+
if (document.querySelector("#browser")) {
250258
window.second_sidebar = new SecondSidebar();
251259
window.SecondSidebarController = SidebarController;
252260
clearInterval(interval);

second_sidebar/sidebar_toolbar.mjs

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,20 @@ export class SidebarToolbar extends Toolbar {
2626
(panel) => panel.goHome()
2727
);
2828

29-
this.toolbarButtons = this.#createToolbarButtons();
30-
this.toolbarTitle = this.#createToolbarTitle();
3129
this.pinButton = this.#createPinButton();
30+
this.closeButton = this.#createCloseButton();
31+
32+
this.toolbarNavButtons = this.#createNavButtons();
33+
this.toolbarTitle = this.#createToolbarTitle();
34+
this.toolbarSidebarButtons = this.#createSidebarButtons();
3235
}
3336

3437
/**
3538
*
3639
* @returns {HBox}
3740
*/
38-
#createToolbarButtons() {
39-
const toolbarButtons = new HBox({ id: "sidebar-2-toolbar-buttons" })
41+
#createNavButtons() {
42+
const toolbarButtons = new HBox({ id: "sidebar-2-toolbar-nav-buttons" })
4043
.appendChild(this.backButton)
4144
.appendChild(this.forwardButton)
4245
.appendChild(this.reloadButton)
@@ -46,6 +49,19 @@ export class SidebarToolbar extends Toolbar {
4649
return toolbarButtons;
4750
}
4851

52+
/**
53+
*
54+
* @returns {HBox}
55+
*/
56+
#createSidebarButtons() {
57+
const toolbarButtons = new HBox({ id: "sidebar-2-toolbar-sidebar-buttons" })
58+
.appendChild(this.pinButton)
59+
.appendChild(this.closeButton);
60+
61+
this.appendChild(toolbarButtons);
62+
return toolbarButtons;
63+
}
64+
4965
/**
5066
*
5167
* @returns {Label}
@@ -56,6 +72,10 @@ export class SidebarToolbar extends Toolbar {
5672
return toolbarTitle;
5773
}
5874

75+
/**
76+
*
77+
* @returns {ToolbarButton}
78+
*/
5979
#createPinButton() {
6080
const pinButton = new ToolbarButton({
6181
id: "sidebar-2-pin-button",
@@ -85,6 +105,29 @@ export class SidebarToolbar extends Toolbar {
85105
return pinButton;
86106
}
87107

108+
/**
109+
*
110+
* @returns {ToolbarButton}
111+
*/
112+
#createCloseButton() {
113+
const closeButton = new ToolbarButton({
114+
id: "sidebar-2-close-button",
115+
}).setIcon("chrome://global/skin/icons/close.svg");
116+
117+
closeButton.addEventListener("mousedown", (event) => {
118+
if (event.button !== 0) {
119+
return;
120+
}
121+
122+
const activeWebPanel = SidebarController.webPanels.getActive();
123+
SidebarController.close();
124+
activeWebPanel.remove();
125+
});
126+
127+
this.appendChild(closeButton);
128+
return closeButton;
129+
}
130+
88131
/**
89132
*
90133
* @param {string} title

second_sidebar/web_panel.mjs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,25 @@ export class WebPanel extends Browser {
99
* @param {string} faviconURL
1010
* @param {boolean} pinned
1111
* @param {string} width
12+
* @param {boolean} unloadOnClose
1213
*/
13-
constructor(url, faviconURL, pinned = false, width = "400") {
14+
constructor(
15+
url,
16+
faviconURL,
17+
pinned = false,
18+
width = "400",
19+
unloadOnClose = false
20+
) {
1421
super({ classList: ["web-panel"] });
1522
this.setDisableGlobalHistory("true").setType("content").setRemote("true");
23+
1624
this.url = url;
1725
this.faviconURL = faviconURL;
1826
this.pinned = pinned;
1927
this.width = width;
20-
this.button = null;
28+
this.unloadOnClose = unloadOnClose;
2129

30+
this.button = null;
2231
this.listener = null;
2332
}
2433

@@ -72,15 +81,6 @@ export class WebPanel extends Browser {
7281
return this.go(this.url);
7382
}
7483

75-
/**
76-
*
77-
* @returns {WebPanel}
78-
*/
79-
remove() {
80-
SidebarController.webPanels.delete(this);
81-
return Browser.prototype.remove.call(this);
82-
}
83-
8484
/**
8585
*
8686
* @param {string} url
@@ -122,6 +122,9 @@ export class WebPanel extends Browser {
122122
*/
123123
hide() {
124124
this.button.setOpen(false);
125+
if (this.unloadOnClose) {
126+
this.remove();
127+
}
125128
return Browser.prototype.hide.call(this);
126129
}
127130
}

second_sidebar/web_panel_popup_edit.mjs

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ export class WebPanelPopupEdit extends Panel {
2020

2121
this.panelHeader = new HBox({ classList: ["panel-header"] });
2222
this.header = new Header(1).setText("Edit Web Panel");
23-
this.separator = new ToolbarSeparator();
2423

25-
this.urlInputHeader = new Header(1).setText("URL");
24+
this.urlInputHeader = new Header(1).setText("Page web address");
2625
this.urlInput = this.#createURLInput();
2726

28-
this.faviconURLInputHeader = new Header(1).setText("Favicon URL");
27+
this.faviconURLInputHeader = new Header(1).setText("Favicon web address");
2928
this.faviconURLInput = this.#createFaviconURLInput();
3029
this.faviconResetButton = this.#createFaviconResetButton();
3130
this.faviconRow = this.#createFaviconRow();
@@ -42,6 +41,9 @@ export class WebPanelPopupEdit extends Panel {
4241
id: "sidebar-2-web-panel-popup-edit-storage-buttons",
4342
});
4443

44+
this.unloadOnCloseToggle = this.#createUnloadOnCloseToggle();
45+
this.unloadOnCloseGroup = this.#createUnloadOnCloseGroup();
46+
4547
this.buttonsRow = this.#createButtonsRow();
4648
this.multiView = this.#createMultiView();
4749

@@ -112,11 +114,12 @@ export class WebPanelPopupEdit extends Panel {
112114
id: "sidebar-2-web-panel-popup-edit-multiview",
113115
})
114116
.appendChild(this.panelHeader)
115-
.appendChild(this.separator)
117+
.appendChild(new ToolbarSeparator())
116118
.appendChild(this.urlInputHeader)
117119
.appendChild(this.urlInput)
118120
.appendChild(this.faviconURLInputHeader)
119121
.appendChild(this.faviconRow)
122+
.appendChild(this.unloadOnCloseGroup)
120123
.appendChild(this.buttonsRow);
121124

122125
this.appendChild(multiView);
@@ -209,6 +212,38 @@ export class WebPanelPopupEdit extends Panel {
209212
return button;
210213
}
211214

215+
/**
216+
*
217+
* @returns {Button}
218+
*/
219+
#createUnloadOnCloseToggle() {
220+
const button = new Button({
221+
id: "moz-toggle-button",
222+
classList: ["toggle-button"],
223+
});
224+
button.setAttribute("part", "button");
225+
button.setAttribute("type", "button");
226+
227+
button.addEventListener("click", (event) => {
228+
if (event.button === 0) {
229+
button.setPressed(!button.getPressed());
230+
}
231+
});
232+
233+
return button;
234+
}
235+
236+
/**
237+
*
238+
* @returns {HBox}
239+
*/
240+
#createUnloadOnCloseGroup() {
241+
const box = new HBox({ id: "sidebar-2-web-panel-popup-edit-unload-group" });
242+
const label = new Header(1).setText("Unload from memory after closing");
243+
box.appendChild(label).appendChild(this.unloadOnCloseToggle);
244+
return box;
245+
}
246+
212247
/**
213248
*
214249
* @returns {Button}
@@ -240,6 +275,11 @@ export class WebPanelPopupEdit extends Panel {
240275
this.webPanelButton.setIcon(faviconURL);
241276
}
242277

278+
this.webPanel.unloadOnClose = this.unloadOnCloseToggle.getPressed();
279+
if (this.webPanel.unloadOnClose && this.webPanel.hidden()) {
280+
this.webPanel.hide();
281+
}
282+
243283
SidebarController.webPanelPopupEdit.hidePopup();
244284
SidebarController.webPanels.save();
245285
});
@@ -265,6 +305,7 @@ export class WebPanelPopupEdit extends Panel {
265305
SidebarController.close();
266306
}
267307

308+
SidebarController.webPanels.delete(this.webPanel);
268309
this.webPanel.remove();
269310
this.webPanelButton.remove();
270311
SidebarController.webPanelPopupEdit.hidePopup();
@@ -288,6 +329,8 @@ export class WebPanelPopupEdit extends Panel {
288329
.setValue(this.webPanel.faviconURL)
289330
.setBackgroundImage(this.webPanel.faviconURL);
290331

332+
this.unloadOnCloseToggle.setPressed(this.webPanel.unloadOnClose);
333+
291334
this.moveUpButton.setDisabled(
292335
SidebarController.webPanels.isFirst(this.webPanel)
293336
);

second_sidebar/web_panels.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ export class WebPanels extends VBox {
178178
webPanelPref.url,
179179
webPanelPref.faviconURL,
180180
webPanelPref.pinned ?? true,
181-
webPanelPref.width ?? "400"
181+
webPanelPref.width ?? "400",
182+
webPanelPref.unloadOnClose ?? false
182183
);
183184
const webPanelButton = new WebPanelButton(webPanel);
184185
SidebarController.webPanelButtons.appendChild(webPanelButton);
@@ -197,6 +198,7 @@ export class WebPanels extends VBox {
197198
faviconURL: webPanel.faviconURL,
198199
pinned: webPanel.pinned,
199200
width: webPanel.width,
201+
unloadOnClose: webPanel.unloadOnClose,
200202
});
201203
}
202204
console.log("Saving prefs: ", prefs);

second_sidebar/xul/button.mjs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,22 @@ export class Button extends XULElement {
2424
this.element.innerText = text;
2525
return this;
2626
}
27+
28+
/**
29+
*
30+
* @returns {boolean}
31+
*/
32+
getPressed() {
33+
return this.element.ariaPressed === "true";
34+
}
35+
36+
/**
37+
*
38+
* @param {boolean} value
39+
* @returns {Button}
40+
*/
41+
setPressed(value) {
42+
this.element.ariaPressed = value;
43+
return this;
44+
}
2745
}

0 commit comments

Comments
 (0)