Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(main): create popup menu in win
  • Loading branch information
antonreshetov committed Apr 10, 2022
commit 0f42308558b4617ff6119d76b97f0dfdebcd6180
7 changes: 0 additions & 7 deletions src/main/components/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,3 @@ export const createMenu = (template: MenuItemConstructorOptions[]) => {
const menu = Menu.buildFromTemplate(template)
return menu
}

export const createPopupMenu = (template: MenuItemConstructorOptions[]) => {
const menu = createMenu(template)
menu.popup({ window: BrowserWindow.getFocusedWindow()! })

return menu
}
16 changes: 12 additions & 4 deletions src/main/services/ipc/context-menu.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createPopupMenu } from '../../components/menu'
import { createMenu } from '../../components/menu'
import type { MenuItemConstructorOptions } from 'electron'
import { BrowserWindow, MenuItem, dialog, ipcMain } from 'electron'
import type {
Expand All @@ -14,7 +14,7 @@ export const subscribeToContextMenu = () => {
const { name, type } = payload

return new Promise(resolve => {
createPopupMenu([
const menu = createMenu([
{
label: `Rename "${name}"`,
click: () =>
Expand Down Expand Up @@ -45,6 +45,8 @@ export const subscribeToContextMenu = () => {
}
}
])

menu.popup({ window: BrowserWindow.getFocusedWindow()! })
})
}
)
Expand All @@ -55,7 +57,7 @@ export const subscribeToContextMenu = () => {
const { name, type, selectedCount } = payload

return new Promise(resolve => {
const menu = createPopupMenu([])
const menu = createMenu([])

const defaultMenu: MenuItemConstructorOptions[] = [
{
Expand Down Expand Up @@ -151,18 +153,21 @@ export const subscribeToContextMenu = () => {
if (type === 'folder' || type === 'all' || type === 'inbox') {
defaultMenu.forEach(i => {
menu.append(new MenuItem(i))
menu.popup({ window: BrowserWindow.getFocusedWindow()! })
})
}

if (type === 'favorites') {
favoritesMenu.forEach(i => {
menu.append(new MenuItem(i))
menu.popup({ window: BrowserWindow.getFocusedWindow()! })
})
}

if (type === 'trash') {
trashMenu.forEach(i => {
menu.append(new MenuItem(i))
menu.popup({ window: BrowserWindow.getFocusedWindow()! })
})
}

Expand All @@ -181,7 +186,7 @@ export const subscribeToContextMenu = () => {
const { name, type, data } = payload

return new Promise(resolve => {
const menu = createPopupMenu([])
const menu = createMenu([])

const createLanguageMenu = () => {
return languages.map(i => {
Expand Down Expand Up @@ -308,18 +313,21 @@ export const subscribeToContextMenu = () => {
if (type === 'folder') {
folderMenu.forEach(i => {
menu.append(new MenuItem(i))
menu.popup({ window: BrowserWindow.getFocusedWindow()! })
})
}

if (type === 'tag') {
tagMenu.forEach(i => {
menu.append(new MenuItem(i))
menu.popup({ window: BrowserWindow.getFocusedWindow()! })
})
}

if (type === 'trash') {
trashMenu.forEach(i => {
menu.append(new MenuItem(i))
menu.popup({ window: BrowserWindow.getFocusedWindow()! })
})
}

Expand Down