From 1db0f58be666fcfe6d38f24cb95d27c4be9eac42 Mon Sep 17 00:00:00 2001 From: Lena Wildervanck Date: Thu, 5 Dec 2024 22:23:30 +0100 Subject: [PATCH 1/7] Add a terrible two liner to make the menu appear in the dock too --- src/backend/tray_icon/tray_icon.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/backend/tray_icon/tray_icon.ts b/src/backend/tray_icon/tray_icon.ts index 77d252b27d..a3890cd0e8 100644 --- a/src/backend/tray_icon/tray_icon.ts +++ b/src/backend/tray_icon/tray_icon.ts @@ -20,6 +20,9 @@ export const initTrayIcon = async (mainWindow: BrowserWindow) => { } appIcon.setContextMenu(contextMenu(mainWindow, recentGames)) + //terrible two liner to make the tray icon menu appear in the dock too on macOS + if (process.platform === 'darwin') + require('electron').app.dock.setMenu(contextMenu(mainWindow, recentGames)) } await loadContextMenu() From f98a223edea435e5a4d80a9d36139a6a42a99d54 Mon Sep 17 00:00:00 2001 From: Lena Wildervanck Date: Fri, 6 Dec 2024 00:14:35 +0100 Subject: [PATCH 2/7] Make the linting pass (I should have looked at that import statement) --- src/backend/tray_icon/tray_icon.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/tray_icon/tray_icon.ts b/src/backend/tray_icon/tray_icon.ts index a3890cd0e8..b92a403bca 100644 --- a/src/backend/tray_icon/tray_icon.ts +++ b/src/backend/tray_icon/tray_icon.ts @@ -1,4 +1,4 @@ -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' @@ -22,7 +22,7 @@ export const initTrayIcon = async (mainWindow: BrowserWindow) => { appIcon.setContextMenu(contextMenu(mainWindow, recentGames)) //terrible two liner to make the tray icon menu appear in the dock too on macOS if (process.platform === 'darwin') - require('electron').app.dock.setMenu(contextMenu(mainWindow, recentGames)) + app.dock.setMenu(contextMenu(mainWindow, recentGames)) } await loadContextMenu() From 1c10459149a02d87055d8fb67012b38dc92bf1f6 Mon Sep 17 00:00:00 2001 From: Lena Wildervanck Date: Fri, 6 Dec 2024 01:22:53 +0100 Subject: [PATCH 3/7] Change the tray icon code after feedback in the Discord https://discord.com/channels/812703221789097985/812703424995000361/1314375931220988014 --- src/backend/tray_icon/tray_icon.ts | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/backend/tray_icon/tray_icon.ts b/src/backend/tray_icon/tray_icon.ts index b92a403bca..935fa845a3 100644 --- a/src/backend/tray_icon/tray_icon.ts +++ b/src/backend/tray_icon/tray_icon.ts @@ -6,7 +6,7 @@ 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) => { @@ -15,14 +15,11 @@ export const initTrayIcon = async (mainWindow: BrowserWindow) => { // helper function to set/update the context menu const loadContextMenu = async (recentGames?: RecentGame[]) => { - if (!recentGames) { - recentGames = await getRecentGames({ limited: true }) - } - - appIcon.setContextMenu(contextMenu(mainWindow, recentGames)) - //terrible two liner to make the tray icon menu appear in the dock too on macOS - if (process.platform === 'darwin') - app.dock.setMenu(contextMenu(mainWindow, recentGames)) + recentGames ??= await getRecentGames({ limited: true }) + const currentContextMenu = contextMenu(mainWindow, recentGames) + appIcon.setContextMenu(currentContextMenu) + // makes the tray icon menu appear in the dock too on macOS + if (isMac) app.dock.setMenu(currentContextMenu) } await loadContextMenu() @@ -112,7 +109,7 @@ const contextMenu = ( label: i18next.t('tray.about', 'About') }, { - accelerator: platform === 'darwin' ? 'Cmd+R' : 'Ctrl+R', + accelerator: isMac ? 'Cmd+R' : 'Ctrl+R', click: function () { mainWindow.reload() }, @@ -120,7 +117,7 @@ const contextMenu = ( }, { label: 'Debug', - accelerator: platform === 'darwin' ? 'Alt+Cmd+I' : 'Ctrl+Shift+I', + accelerator: isMac ? 'Alt+Cmd+I' : 'Ctrl+Shift+I', click: () => { mainWindow.webContents.openDevTools() } @@ -130,7 +127,7 @@ const contextMenu = ( handleExit() }, label: i18next.t('tray.quit', 'Quit'), - accelerator: platform === 'darwin' ? 'Cmd+Q' : 'Ctrl+Q' + accelerator: isMac ? 'Cmd+Q' : 'Ctrl+Q' } ]) } From 2ede1e0b2a782dc6213c5b6b074ac33a653d15ec Mon Sep 17 00:00:00 2001 From: Lena Wildervanck Date: Fri, 6 Dec 2024 01:25:14 +0100 Subject: [PATCH 4/7] Remove unused variable because linter was complaining --- src/backend/tray_icon/tray_icon.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/backend/tray_icon/tray_icon.ts b/src/backend/tray_icon/tray_icon.ts index 935fa845a3..7e72e539e6 100644 --- a/src/backend/tray_icon/tray_icon.ts +++ b/src/backend/tray_icon/tray_icon.ts @@ -79,11 +79,7 @@ const getIcon = (platform = process.platform) => { } // generate the context menu -const contextMenu = ( - mainWindow: BrowserWindow, - recentGames: RecentGame[], - platform = process.platform -) => { +const contextMenu = (mainWindow: BrowserWindow, recentGames: RecentGame[]) => { const recentsMenu = recentGames.map((game) => { return { click: function () { From 56ea3aee37d644e67a13a171bd8341ab41f40e9d Mon Sep 17 00:00:00 2001 From: Lena Wildervanck Date: Fri, 6 Dec 2024 01:28:08 +0100 Subject: [PATCH 5/7] And undo it because it made a test fail --- src/backend/tray_icon/tray_icon.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/backend/tray_icon/tray_icon.ts b/src/backend/tray_icon/tray_icon.ts index 7e72e539e6..b3d01f0447 100644 --- a/src/backend/tray_icon/tray_icon.ts +++ b/src/backend/tray_icon/tray_icon.ts @@ -79,7 +79,11 @@ const getIcon = (platform = process.platform) => { } // generate the context menu -const contextMenu = (mainWindow: BrowserWindow, recentGames: RecentGame[]) => { +const contextMenu = ( + mainWindow: BrowserWindow, + recentGames: RecentGame[], + platform = process.platform +) => { const recentsMenu = recentGames.map((game) => { return { click: function () { @@ -105,7 +109,7 @@ const contextMenu = (mainWindow: BrowserWindow, recentGames: RecentGame[]) => { label: i18next.t('tray.about', 'About') }, { - accelerator: isMac ? 'Cmd+R' : 'Ctrl+R', + accelerator: platform === 'darwin' ? 'Cmd+R' : 'Ctrl+R', click: function () { mainWindow.reload() }, @@ -113,7 +117,7 @@ const contextMenu = (mainWindow: BrowserWindow, recentGames: RecentGame[]) => { }, { label: 'Debug', - accelerator: isMac ? 'Alt+Cmd+I' : 'Ctrl+Shift+I', + accelerator: platform === 'darwin' ? 'Alt+Cmd+I' : 'Ctrl+Shift+I', click: () => { mainWindow.webContents.openDevTools() } @@ -123,7 +127,7 @@ const contextMenu = (mainWindow: BrowserWindow, recentGames: RecentGame[]) => { handleExit() }, label: i18next.t('tray.quit', 'Quit'), - accelerator: isMac ? 'Cmd+Q' : 'Ctrl+Q' + accelerator: platform === 'darwin' ? 'Cmd+Q' : 'Ctrl+Q' } ]) } From beec81c8134140317d073951473f288a7ccd2e82 Mon Sep 17 00:00:00 2001 From: Lena Wildervanck Date: Fri, 6 Dec 2024 01:42:12 +0100 Subject: [PATCH 6/7] Change variable name --- src/backend/tray_icon/tray_icon.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/backend/tray_icon/tray_icon.ts b/src/backend/tray_icon/tray_icon.ts index b3d01f0447..b3c38380aa 100644 --- a/src/backend/tray_icon/tray_icon.ts +++ b/src/backend/tray_icon/tray_icon.ts @@ -16,10 +16,10 @@ export const initTrayIcon = async (mainWindow: BrowserWindow) => { // helper function to set/update the context menu const loadContextMenu = async (recentGames?: RecentGame[]) => { recentGames ??= await getRecentGames({ limited: true }) - const currentContextMenu = contextMenu(mainWindow, recentGames) - appIcon.setContextMenu(currentContextMenu) + const newContextMenu = contextMenu(mainWindow, recentGames) + appIcon.setContextMenu(newContextMenu) // makes the tray icon menu appear in the dock too on macOS - if (isMac) app.dock.setMenu(currentContextMenu) + if (isMac) app.dock.setMenu(newContextMenu) } await loadContextMenu() From aad4341e58ee62a57577b8a27dffb5fb0b0fef35 Mon Sep 17 00:00:00 2001 From: Lena Wildervanck Date: Sat, 14 Dec 2024 13:35:29 +0100 Subject: [PATCH 7/7] change comments after feedback --- src/backend/tray_icon/tray_icon.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/backend/tray_icon/tray_icon.ts b/src/backend/tray_icon/tray_icon.ts index b3c38380aa..b17a861b92 100644 --- a/src/backend/tray_icon/tray_icon.ts +++ b/src/backend/tray_icon/tray_icon.ts @@ -13,12 +13,11 @@ 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[]) => { recentGames ??= await getRecentGames({ limited: true }) const newContextMenu = contextMenu(mainWindow, recentGames) appIcon.setContextMenu(newContextMenu) - // makes the tray icon menu appear in the dock too on macOS if (isMac) app.dock.setMenu(newContextMenu) } await loadContextMenu()