Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
chore(client/ts): port menus/electron_context_menu
Elian Doraneb9a55bf4f4f
diff --git a/src/public/app/menus/context_menu.ts b/src/public/app/menus/context_menu.tsindex 8e4ec6374e..fd3021fd21 100644--- a/src/public/app/menus/context_menu.ts+++ b/src/public/app/menus/context_menu.ts@@ -15,17 +15,18 @@ interface MenuSeparatorItem {export interface MenuCommandItem {title: string;command?: string;- type: string;- uiIcon: string;+ type?: string;+ uiIcon?: string;templateNoteId?: string;enabled?: boolean;handler?: MenuHandler;items?: MenuItem[];shortcut?: string;+ spellingSuggestion?: string;}export type MenuItem = MenuCommandItem | MenuSeparatorItem;-export type MenuHandler = (item: MenuItem, e: JQuery.MouseDownEvent<HTMLElement, undefined, HTMLElement, HTMLElement>) => void;+export type MenuHandler = (item: MenuCommandItem, e: JQuery.MouseDownEvent<HTMLElement, undefined, HTMLElement, HTMLElement>) => void;class ContextMenu {diff --git a/src/public/app/menus/electron_context_menu.js b/src/public/app/menus/electron_context_menu.tssimilarity index 94%rename from src/public/app/menus/electron_context_menu.jsrename to src/public/app/menus/electron_context_menu.tsindex 62dc36191b..faa10a62a1 100644--- a/src/public/app/menus/electron_context_menu.js+++ b/src/public/app/menus/electron_context_menu.ts@@ -3,12 +3,14 @@ import options from "../services/options.js";import zoomService from "../components/zoom.js";import contextMenu from "./context_menu.js";import { t } from "../services/i18n.js";+import type { BrowserWindow } from "electron";function setupContextMenu() {const electron = utils.dynamicRequire('electron');const remote = utils.dynamicRequire('@electron/remote');- const {webContents} = remote.getCurrentWindow();+ // FIXME: Remove typecast once Electron is properly integrated.+ const {webContents} = remote.getCurrentWindow() as BrowserWindow;webContents.on('context-menu', (event, params) => {const {editFlags} = params;@@ -97,7 +99,7 @@ function setupContextMenu() {// Read the search engine from the options and fallback to DuckDuckGo if the option is not set.const customSearchEngineName = options.get("customSearchEngineName");- const customSearchEngineUrl = options.get("customSearchEngineUrl");+ const customSearchEngineUrl = options.get("customSearchEngineUrl") as string;let searchEngineName;let searchEngineUrl;if (customSearchEngineName && customSearchEngineUrl) {@@ -132,7 +134,7 @@ function setupContextMenu() {y: params.y / zoomLevel,items,selectMenuItemHandler: ({command, spellingSuggestion}) => {- if (command === 'replaceMisspelling') {+ if (command === 'replaceMisspelling' && spellingSuggestion) {webContents.insertText(spellingSuggestion);}}diff --git a/src/public/app/widgets/dialogs/note_type_chooser.ts b/src/public/app/widgets/dialogs/note_type_chooser.tsindex 6af7c4e3bd..a330c41f95 100644--- a/src/public/app/widgets/dialogs/note_type_chooser.ts+++ b/src/public/app/widgets/dialogs/note_type_chooser.ts@@ -131,9 +131,9 @@ export default class NoteTypeChooserDialog extends BasicWidget {const commandItem = (noteType as MenuCommandItem)this.$noteTypeDropdown.append($('<a class="dropdown-item" tabindex="0">')- .attr("data-note-type", commandItem.type)+ .attr("data-note-type", commandItem.type || "").attr("data-template-note-id", commandItem.templateNoteId || "")- .append($("<span>").addClass(commandItem.uiIcon))+ .append($("<span>").addClass(commandItem.uiIcon || "")).append(` ${noteType.title}`));}