feat(tray): show a list of bookmarks

This commit is contained in:
Elian Doran 2025-02-01 02:29:34 +02:00
parent 84edf0348f
commit cd0c79e3d2
No known key found for this signature in database

View File

@ -6,6 +6,7 @@ import { fileURLToPath } from "url";
import type { KeyboardActionNames } from "./keyboard_actions_interface.js"; import type { KeyboardActionNames } from "./keyboard_actions_interface.js";
import date_notes from "./date_notes.js"; import date_notes from "./date_notes.js";
import type BNote from "../becca/entities/bnote.js"; import type BNote from "../becca/entities/bnote.js";
import becca from "../becca/becca.js";
let tray: Tray; let tray: Tray;
// `mainWindow.isVisible` doesn't work with `mainWindow.show` and `mainWindow.hide` - it returns `false` when the window // `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); 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([ const contextMenu = Menu.buildFromTemplate([
{ {
label: "New Note", label: "New Note",
@ -75,6 +96,11 @@ function updateTrayMenu() {
type: "normal", type: "normal",
click: () => openInSameTab(date_notes.getTodayNote()) click: () => openInSameTab(date_notes.getTodayNote())
}, },
{
label: "Bookmarks",
type: "submenu",
submenu: buildBookmarksMenu()
},
{ type: "separator" }, { type: "separator" },
{ {
label: isVisible ? "Hide" : "Show", label: isVisible ? "Hide" : "Show",