Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

feat: add basic context menu in desktop app

thecodrrf9e8e8c92cfc
diff --git a/apps/web/desktop/electron.js b/apps/web/desktop/electron.js
index 30c2ec969..87b6f7a34 100644
--- a/apps/web/desktop/electron.js
+++ b/apps/web/desktop/electron.js
@@ -7,6 +7,7 @@ const { configureAutoUpdater } = require("./autoupdate");
const { getBackgroundColor, getTheme, setTheme } = require("./config/theme");
const getZoomFactor = require("./ipc/calls/getZoomFactor");
const { logger } = require("./logger");
+const { setupMenu } = require("./menu");
require("./ipc/index.js");
try {
require("electron-reloader")(module);
@@ -36,6 +37,7 @@ async function createWindow() {
});
global.win = mainWindow;
setTheme(getTheme());
+ setupMenu(mainWindow);
if (isDevelopment())
mainWindow.webContents.openDevTools({ mode: "right", activate: true });
diff --git a/apps/web/desktop/menu.js b/apps/web/desktop/menu.js
new file mode 100644
index 000000000..f23eaf63e
--- /dev/null
+++ b/apps/web/desktop/menu.js
@@ -0,0 +1,90 @@
+const { BrowserWindow, Menu, MenuItem, clipboard } = require("electron");
+
+/**
+ *
+ * @param {BrowserWindow} mainWindow
+ */
+function setupMenu(mainWindow) {
+ mainWindow.webContents.on("context-menu", (event, params) => {
+ const menu = new Menu();
+ if (params.isEditable) {
+ menu.append(
+ new MenuItem({
+ label: "Undo",
+ role: "undo",
+ enabled: params.isEditable,
+ accelerator: "CommandOrControl+Z",
+ })
+ );
+
+ menu.append(
+ new MenuItem({
+ label: "Redo",
+ role: "redo",
+ enabled: params.isEditable,
+ accelerator: "CommandOrControl+Y",
+ })
+ );
+
+ menu.append(
+ new MenuItem({
+ type: "separator",
+ })
+ );
+ }
+
+ if (params.isEditable)
+ menu.append(
+ new MenuItem({
+ label: "Cut",
+ role: "cut",
+ enabled: params.selectionText.length > 0,
+ accelerator: "CommandOrControl+X",
+ })
+ );
+
+ menu.append(
+ new MenuItem({
+ label: "Copy",
+ role: "copy",
+ enabled: params.selectionText.length > 0,
+ accelerator: "CommandOrControl+C",
+ })
+ );
+
+ if (params.isEditable)
+ menu.append(
+ new MenuItem({
+ label: "Paste",
+ role: "pasteAndMatchStyle",
+ enabled: clipboard.readText("clipboard").length > 0,
+ accelerator: "CommandOrControl+V",
+ })
+ );
+
+ // Add each spelling suggestion
+ // for (const suggestion of params.dictionarySuggestions) {
+ // menu.append(
+ // new MenuItem({
+ // label: suggestion,
+ // click: () => mainWindow.webContents.replaceMisspelling(suggestion),
+ // })
+ // );
+ // }
+
+ // Allow users to add the misspelled word to the dictionary
+ // if (params.misspelledWord) {
+ // menu.append(
+ // new MenuItem({
+ // label: "Add to dictionary",
+ // click: () =>
+ // mainWindow.webContents.session.addWordToSpellCheckerDictionary(
+ // params.misspelledWord
+ // ),
+ // })
+ // );
+ // }
+ menu.popup();
+ });
+}
+module.exports = { setupMenu };