Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS Dock Menu support #4158

Merged
merged 7 commits into from
Dec 19, 2024
Merged
Changes from all commits
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
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
Loading