Skip to content

Commit

Permalink
macOS Dock Menu support (#4158)
Browse files Browse the repository at this point in the history
  • Loading branch information
LenaWil authored Dec 19, 2024
1 parent 2f428e7 commit a13af16
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/backend/tray_icon/tray_icon.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import { BrowserWindow, ipcMain, Menu, nativeImage, Tray } from 'electron'
import { app, BrowserWindow, ipcMain, Menu, nativeImage, Tray } from 'electron'
import i18next from 'i18next'
import { RecentGame } from 'common/types'
import { logInfo, LogPrefix } from '../logger/logger'
import { handleProtocol } from '../protocol'
import { getRecentGames, maxRecentGames } from '../recent_games/recent_games'
import { handleExit, showAboutWindow } from '../utils'
import { GlobalConfig } from '../config'
import { iconDark, iconLight } from '../constants'
import { iconDark, iconLight, isMac } from '../constants'
import { backendEvents } from '../backend_events'

export const initTrayIcon = async (mainWindow: BrowserWindow) => {
// create icon
const appIcon = new Tray(getIcon(process.platform))

// helper function to set/update the context menu
// helper function to set/update the context menu and on macOS the dock menu
const loadContextMenu = async (recentGames?: RecentGame[]) => {
if (!recentGames) {
recentGames = await getRecentGames({ limited: true })
}

appIcon.setContextMenu(contextMenu(mainWindow, recentGames))
recentGames ??= await getRecentGames({ limited: true })
const newContextMenu = contextMenu(mainWindow, recentGames)
appIcon.setContextMenu(newContextMenu)
if (isMac) app.dock.setMenu(newContextMenu)
}
await loadContextMenu()

Expand Down

0 comments on commit a13af16

Please sign in to comment.