Skip to content

Commit

Permalink
feat(navbar): add plus button for new window, manage navbar buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
akhileshthite committed Feb 22, 2025
1 parent 54ad7c3 commit 54e912a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 12 deletions.
42 changes: 30 additions & 12 deletions src/pages/nav-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,44 @@ class NavBox extends HTMLElement {
buildNavBox() {
this.id = "navbox";
const buttons = [
{ id: "back", svg: "left.svg" },
{ id: "forward", svg: "right.svg" },
{ id: "refresh", svg: "reload.svg" },
{ id: "home", svg: "home.svg" },
{ id: "back", svg: "left.svg", position: "start" },
{ id: "forward", svg: "right.svg", position: "start" },
{ id: "refresh", svg: "reload.svg", position: "start" },
{ id: "home", svg: "home.svg", position: "start" },
{ id: "plus", svg: "plus.svg", position: "end" },
];

this.buttonElements = {};

buttons.forEach((button) => {
const btnElement = this.createButton(
button.id,
`peersky://static/assets/svg/${button.svg}`
);
this.appendChild(btnElement);
this.buttonElements[button.id] = btnElement;
});
// Create buttons that should appear before the URL input
buttons
.filter((btn) => btn.position === "start")
.forEach((button) => {
const btnElement = this.createButton(
button.id,
`peersky://static/assets/svg/${button.svg}`
);
this.appendChild(btnElement);
this.buttonElements[button.id] = btnElement;
});

const urlInput = document.createElement("input");
urlInput.type = "text";
urlInput.id = "url";
urlInput.placeholder = "Search with DuckDuckGo or type a P2P URL";
this.appendChild(urlInput);

// Create buttons that should appear after the URL input
buttons
.filter((btn) => btn.position === "end")
.forEach((button) => {
const btnElement = this.createButton(
button.id,
`peersky://static/assets/svg/${button.svg}`
);
this.appendChild(btnElement);
this.buttonElements[button.id] = btnElement;
});
}

createButton(id, svgPath) {
Expand Down Expand Up @@ -124,6 +140,8 @@ class NavBox extends HTMLElement {
} else {
this.dispatchEvent(new CustomEvent("reload"));
}
} else if (button.id === "plus") {
this.dispatchEvent(new CustomEvent("new-window"));
} else if (!button.disabled) {
this.navigate(button.id);
}
Expand Down
3 changes: 3 additions & 0 deletions src/pages/static/assets/svg/plus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ document.addEventListener("DOMContentLoaded", () => {
const { url } = detail;
navigateTo(url);
});
nav.addEventListener("new-window", () => {
ipcRenderer.send("new-window");
});

// Handle webview loading events to toggle refresh/stop button
if (webviewContainer.webviewElement) {
Expand Down
7 changes: 7 additions & 0 deletions src/window-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ class WindowManager {
this.saverInterval = DEFAULT_SAVE_INTERVAL;
this.isSaving = false; // Flag to prevent concurrent saves
this.isQuitting = false; // Flag to indicate app is quitting
this.registerListeners();
}

registerListeners() {
ipcMain.on("new-window", () => {
this.open();
});
}

setQuitting(flag) {
Expand Down

0 comments on commit 54e912a

Please sign in to comment.