Skip to content

Commit

Permalink
Improve main menu
Browse files Browse the repository at this point in the history
Especially on macoS. There is now an application menu additionally to
the file menu. Some entries are moved to this new menu, e.g. "Quit" and
"Settings". This application menu contains also some additional entries
that are usual n macOS.

For all operating systems, there is now a "Window" menu with OS
specific window management entries.
  • Loading branch information
c3er committed Jul 21, 2024
1 parent 8d13247 commit f6daf26
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 31 deletions.
74 changes: 55 additions & 19 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -139,13 +174,17 @@ function createMainMenu() {
fileHistory.clear()
},
},
{ type: "separator" },
{
label: "&Quit",
click() {
_mainWindow?.close()
},
},
...(!common.isMacOS()
? [
{ type: "separator" },
{
label: "&Quit",
click() {
_mainWindow?.close()
},
},
]
: []),
],
},
{
Expand Down Expand Up @@ -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],
},
]
: []),
])
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mdview",
"version": "3.1.2",
"version": "3.2.0",
"description": "Standalone Markdown Viewer",
"keywords": [
"markdown",
Expand Down
4 changes: 4 additions & 0 deletions test/integration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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}"`, () => {
Expand Down
41 changes: 30 additions & 11 deletions test/mocking.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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: {
Expand All @@ -232,9 +247,11 @@ exports.elements = {
clearRecentFiles: {
label: "Clear Recent Files List",
},
quit: {
label: "&Quit",
},
quit: !common.isMacOS()
? {
label: "&Quit",
}
: {},
},
},
edit: {
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit f6daf26

Please sign in to comment.