mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-29 19:12:27 +08:00
fix: 🐛 fix tray.ts build error
This commit is contained in:
parent
7f381cb733
commit
a554085681
@ -1,23 +1,24 @@
|
|||||||
import { Menu, Tray, BrowserWindow } from "electron";
|
import { BrowserWindow,Menu, Tray } from "electron";
|
||||||
import path from "path";
|
|
||||||
import windowService from "./window.js";
|
|
||||||
import optionService from "./options.js";
|
|
||||||
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";
|
|
||||||
import becca_service from "../becca/becca_service.js";
|
|
||||||
import type BRecentNote from "../becca/entities/brecent_note.js";
|
|
||||||
import { ipcMain, nativeTheme } from "electron/main";
|
import { ipcMain, nativeTheme } from "electron/main";
|
||||||
import { default as i18next, t } from "i18next";
|
import { default as i18next, t } from "i18next";
|
||||||
import { isDev, isMac } from "./utils.js";
|
import path from "path";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
|
import becca from "../becca/becca.js";
|
||||||
|
import becca_service from "../becca/becca_service.js";
|
||||||
|
import type BNote from "../becca/entities/bnote.js";
|
||||||
|
import type BRecentNote from "../becca/entities/brecent_note.js";
|
||||||
import cls from "./cls.js";
|
import cls from "./cls.js";
|
||||||
|
import date_notes from "./date_notes.js";
|
||||||
|
import type { KeyboardActionNames } from "./keyboard_actions_interface.js";
|
||||||
|
import optionService from "./options.js";
|
||||||
|
import { isDev, isMac } from "./utils.js";
|
||||||
|
import windowService from "./window.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
|
||||||
// is minimized
|
// is minimized
|
||||||
let windowVisibilityMap: Record<number, boolean> = {};; // Dictionary for storing window ID and its visibility status
|
const windowVisibilityMap: Record<number, boolean> = {};; // Dictionary for storing window ID and its visibility status
|
||||||
|
|
||||||
function getTrayIconPath() {
|
function getTrayIconPath() {
|
||||||
let name: string;
|
let name: string;
|
||||||
@ -75,7 +76,7 @@ function updateWindowVisibilityMap(allWindows: BrowserWindow[]) {
|
|||||||
const currentWindowIds: number[] = allWindows.map(window => window.id);
|
const currentWindowIds: number[] = allWindows.map(window => window.id);
|
||||||
|
|
||||||
// Deleting closed windows from windowVisibilityMap
|
// Deleting closed windows from windowVisibilityMap
|
||||||
for (const [id, visibility] of Object.entries(windowVisibilityMap)) {
|
for (const [id, _] of Object.entries(windowVisibilityMap)) {
|
||||||
const windowId = Number(id);
|
const windowId = Number(id);
|
||||||
if (!currentWindowIds.includes(windowId)) {
|
if (!currentWindowIds.includes(windowId)) {
|
||||||
delete windowVisibilityMap[windowId];
|
delete windowVisibilityMap[windowId];
|
||||||
@ -133,7 +134,7 @@ function updateTrayMenu() {
|
|||||||
const parentNote = becca.getNoteOrThrow("_lbBookmarks");
|
const parentNote = becca.getNoteOrThrow("_lbBookmarks");
|
||||||
const menuItems: Electron.MenuItemConstructorOptions[] = [];
|
const menuItems: Electron.MenuItemConstructorOptions[] = [];
|
||||||
|
|
||||||
for (const bookmarkNote of parentNote?.children) {
|
for (const bookmarkNote of parentNote?.children ?? []) {
|
||||||
if (bookmarkNote.isLabelTruthy("bookmarkFolder")) {
|
if (bookmarkNote.isLabelTruthy("bookmarkFolder")) {
|
||||||
menuItems.push({
|
menuItems.push({
|
||||||
label: bookmarkNote.title,
|
label: bookmarkNote.title,
|
||||||
@ -194,7 +195,7 @@ function updateTrayMenu() {
|
|||||||
|
|
||||||
for (const idStr in windowVisibilityMap) {
|
for (const idStr in windowVisibilityMap) {
|
||||||
const id = parseInt(idStr, 10); // Get the ID of the window and make sure it is a number
|
const id = parseInt(idStr, 10); // Get the ID of the window and make sure it is a number
|
||||||
const isVisible = windowVisibilityMap[id];
|
const isVisible = windowVisibilityMap[id];
|
||||||
const win = allWindows.find(w => w.id === id);
|
const win = allWindows.find(w => w.id === id);
|
||||||
if (!win) {
|
if (!win) {
|
||||||
continue;
|
continue;
|
||||||
@ -214,10 +215,10 @@ function updateTrayMenu() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const contextMenu = Menu.buildFromTemplate([
|
const contextMenu = Menu.buildFromTemplate([
|
||||||
...windowVisibilityMenuItems,
|
...windowVisibilityMenuItems,
|
||||||
{ type: "separator" },
|
{ type: "separator" },
|
||||||
{
|
{
|
||||||
label: t("tray.open_new_window"),
|
label: t("tray.open_new_window"),
|
||||||
@ -235,7 +236,7 @@ function updateTrayMenu() {
|
|||||||
label: t("tray.today"),
|
label: t("tray.today"),
|
||||||
type: "normal",
|
type: "normal",
|
||||||
icon: getIconPath("today"),
|
icon: getIconPath("today"),
|
||||||
click: cls.wrap(() => openInSameTab(date_notes.getTodayNote()))
|
click: cls.wrap(async () => openInSameTab(await date_notes.getTodayNote()))
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: t("tray.bookmarks"),
|
label: t("tray.bookmarks"),
|
||||||
@ -268,7 +269,7 @@ function updateTrayMenu() {
|
|||||||
|
|
||||||
function changeVisibility() {
|
function changeVisibility() {
|
||||||
const lastFocusedWindow = windowService.getLastFocusedWindow();
|
const lastFocusedWindow = windowService.getLastFocusedWindow();
|
||||||
|
|
||||||
if (!lastFocusedWindow) {
|
if (!lastFocusedWindow) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user