From cd0c79e3d2638bb3ac30dd6c25ab4c6472ca1857 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 1 Feb 2025 02:29:34 +0200 Subject: [PATCH] feat(tray): show a list of bookmarks --- src/services/tray.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/services/tray.ts b/src/services/tray.ts index 992d67053..9378d8593 100644 --- a/src/services/tray.ts +++ b/src/services/tray.ts @@ -6,6 +6,7 @@ import { fileURLToPath } from "url"; import type { KeyboardActionNames } from "./keyboard_actions_interface.js"; import date_notes from "./date_notes.js"; import type BNote from "../becca/entities/bnote.js"; +import becca from "../becca/becca.js"; let tray: Tray; // `mainWindow.isVisible` doesn't work with `mainWindow.show` and `mainWindow.hide` - it returns `false` when the window @@ -64,6 +65,26 @@ function updateTrayMenu() { mainWindow?.webContents.send("openInSameTab", note.noteId); } + function buildBookmarksMenu() { + const parentNote = becca.getNoteOrThrow("_lbBookmarks"); + const menuItems: Electron.MenuItemConstructorOptions[] = []; + + for (const bookmarkNote of parentNote?.children) { + if (bookmarkNote.isLabelTruthy("bookmarkFolder")) { + // Ignore bookmark folders for now. + continue; + } + + menuItems.push({ + label: bookmarkNote.title, + type: "normal", + click: () => openInSameTab(bookmarkNote) + }); + } + + return menuItems; + } + const contextMenu = Menu.buildFromTemplate([ { label: "New Note", @@ -75,6 +96,11 @@ function updateTrayMenu() { type: "normal", click: () => openInSameTab(date_notes.getTodayNote()) }, + { + label: "Bookmarks", + type: "submenu", + submenu: buildBookmarksMenu() + }, { type: "separator" }, { label: isVisible ? "Hide" : "Show",