Skip to content

Commit

Permalink
Fix reloading menu #159
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Dec 12, 2021
1 parent 5e277ac commit 2ed225e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
18 changes: 10 additions & 8 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1586,14 +1586,6 @@ const createTray = () => {
* Create application menu
*/
const createMenu = () => {
if (window_application !== undefined) {
window_application.webContents.send("refreshMenu")
window_settings.webContents.send("refreshMenu")
window_import.webContents.send("refreshMenu")
window_export.webContents.send("refreshMenu")
window_edit.webContents.send("refreshMenu")
}

const template = [
{
label: "File",
Expand Down Expand Up @@ -1921,8 +1913,18 @@ const createMenu = () => {
},
]

// Set menu
menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)

// Reload menu
if (window_application !== undefined && platform === "windows") {
window_application.webContents.send("refreshMenu")
window_settings.webContents.send("refreshMenu")
window_import.webContents.send("refreshMenu")
window_export.webContents.send("refreshMenu")
window_edit.webContents.send("refreshMenu")
}
}

/**
Expand Down
7 changes: 6 additions & 1 deletion preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ document.addEventListener("drop", (event) => event.preventDefault())
*/
const currentWindow = getCurrentWindow()
let titlebar
let loaded = false

if (process.platform === "win32") {
currentWindow.webContents.once("dom-ready", () => {
Expand All @@ -99,12 +100,16 @@ if (process.platform === "win32") {
icon: "../../img/icon.png",
unfocusEffect: false,
})

loaded = true
})
}

/**
* Refresh title bar
*/
ipc.on("refreshMenu", () => {
titlebar.updateMenu(Menu.getApplicationMenu())
if (loaded === true) {
titlebar.updateMenu(Menu.getApplicationMenu())
}
})

0 comments on commit 2ed225e

Please sign in to comment.