diff --git a/app/main.js b/app/main.js index 0887c6f..892379f 100644 --- a/app/main.js +++ b/app/main.js @@ -89,7 +89,42 @@ function restoreScrollPosition() { } function createMainMenu() { + const aboutEntry = { + label: "&About", + id: about.ABOUT_DIALOG_MENU_ID, + click() { + about.open() + }, + } + const settingsEntry = { + label: "&Settings...", + accelerator: "CmdOrCtrl+,", + id: settings.SETTINGS_MENU_ID, + click() { + settings.open() + }, + } return electron.Menu.buildFromTemplate([ + ...(common.isMacOS() + ? [ + { + label: electron.app.name, + submenu: [ + aboutEntry, + { type: "separator" }, + settingsEntry, + { role: "services" }, + { type: "separator" }, + { role: "hide" }, + { role: "hideOthers" }, + { role: "unhide" }, + { type: "separator" }, + { type: "separator" }, + { role: "quit" }, + ], + }, + ] + : []), { label: "&File", submenu: [ @@ -139,13 +174,17 @@ function createMainMenu() { fileHistory.clear() }, }, - { type: "separator" }, - { - label: "&Quit", - click() { - _mainWindow?.close() - }, - }, + ...(!common.isMacOS() + ? [ + { type: "separator" }, + { + label: "&Quit", + click() { + _mainWindow?.close() + }, + }, + ] + : []), ], }, { @@ -346,18 +385,15 @@ function createMainMenu() { }, ], }, - { - label: "&Help", - submenu: [ - { - label: "&About", - id: about.ABOUT_DIALOG_MENU_ID, - click() { - about.open() - }, - }, - ], - }, + { role: "windowMenu" }, + ...(!common.isMacOS() + ? [ + { + label: "&Help", + submenu: [aboutEntry], + }, + ] + : []), ]) } diff --git a/package.json b/package.json index 11597d7..99eb029 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mdview", - "version": "3.1.2", + "version": "3.2.0", "description": "Standalone Markdown Viewer", "keywords": [ "markdown", diff --git a/test/integration.spec.js b/test/integration.spec.js index d184160..0a34636 100644 --- a/test/integration.spec.js +++ b/test/integration.spec.js @@ -7,6 +7,7 @@ const playwright = require("playwright") const lib = require("./testLib") const mocking = require("./mocking") +const common = require("../app/lib/common") const settings = require("../app/lib/settingsMain") const toc = require("../app/lib/tocMain") @@ -198,6 +199,9 @@ describe("Integration tests with single app instance", () => { function assertMenu(menu, itemPath) { for (const [, currentItem] of Object.entries(menu)) { + if (common.isEmptyObject(currentItem)) { + continue + } const currentItemLabel = currentItem.label const currentItemPath = [...itemPath, currentItemLabel] describe(`Menu item "${currentItemLabel}"`, () => { diff --git a/test/mocking.js b/test/mocking.js index 2aa2888..9b5b37a 100644 --- a/test/mocking.js +++ b/test/mocking.js @@ -3,6 +3,8 @@ const path = require("path") const lodashClonedeep = require("lodash.clonedeep") +const common = require("../app/lib/common") + const DEFAULT_THEME = "system" const _electronIpcEvent = {} @@ -217,6 +219,19 @@ exports.dataDir = path.join(__dirname, "data") exports.elements = { mainMenu: { + application: common.isMacOS() + ? { + label: "mdview", + sub: { + about: { + label: "&About", + }, + settings: { + label: "&Settings...", + }, + }, + } + : {}, file: { label: "&File", sub: { @@ -232,9 +247,11 @@ exports.elements = { clearRecentFiles: { label: "Clear Recent Files List", }, - quit: { - label: "&Quit", - }, + quit: !common.isMacOS() + ? { + label: "&Quit", + } + : {}, }, }, edit: { @@ -338,14 +355,16 @@ exports.elements = { }, }, }, - help: { - label: "&Help", - sub: { - about: { - label: "&About", - }, - }, - }, + help: !common.isMacOS() + ? { + label: "&Help", + sub: { + about: { + label: "&About", + }, + }, + } + : {}, }, blockedContentArea: { path: "#blocked-content-info",