From 15aa8026b166a67719959fcad020666b7d486870 Mon Sep 17 00:00:00 2001 From: Matt Holtzman Date: Fri, 31 Jan 2025 16:04:55 -0500 Subject: [PATCH 1/4] add debug logging for context menu --- main/windows/index.ts | 1 + main/windows/systemTray.ts | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/main/windows/index.ts b/main/windows/index.ts index a382ace55..945a411a1 100644 --- a/main/windows/index.ts +++ b/main/windows/index.ts @@ -149,6 +149,7 @@ function initTrayWindow() { windows.tray.setPosition(width + x, height + y) windows.tray.on('show', () => { + console.log('---> Tray show') if (process.platform === 'win32') { systemTray.closeContextMenu() } diff --git a/main/windows/systemTray.ts b/main/windows/systemTray.ts index d6f92826d..f944920df 100644 --- a/main/windows/systemTray.ts +++ b/main/windows/systemTray.ts @@ -22,9 +22,16 @@ export class SystemTray { // Electron Tray can only be instantiated when the app is ready this.electronTray = new ElectronTray(path.join(__dirname, isMacOS ? './IconTemplate.png' : './Icon.png')) this.electronTray.on('click', (_event: KeyboardEvent, bounds: Rectangle) => { + console.log('---> Received click on tray', { bounds}) const mainWindowBounds = mainWindow.getBounds() + console.log('---> Main window bounds', mainWindowBounds) const currentDisplay = screen.getDisplayMatching(bounds) + console.log('---> Current display', currentDisplay) const trayClickDisplay = screen.getDisplayMatching(mainWindowBounds) + console.log('---> Tray click display', trayClickDisplay) + + console.log('---> Tray click display id', trayClickDisplay.id) + console.log('---> Current display id', currentDisplay.id) if (trayClickDisplay.id !== currentDisplay.id) { this.setContextMenu('show', { switchScreen: true }) } @@ -36,6 +43,7 @@ export class SystemTray { type: string, { displaySummonShortcut = false, accelerator = 'Alt+/', switchScreen = false } ) { + //console.log('---> Setting context menu', { type, displaySummonShortcut, accelerator, switchScreen }) const separatorMenuItem = { label: 'Frame', click: () => {}, From fc55851f250b18b2c98ace6e6f41cf2789505a16 Mon Sep 17 00:00:00 2001 From: Matt Holtzman Date: Fri, 31 Jan 2025 17:17:52 -0500 Subject: [PATCH 2/4] add check for ubuntu version --- main/windows/systemTray.ts | 35 +++++++++++++++++++++++++---------- package-lock.json | 17 +++++++++++++++++ package.json | 1 + 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/main/windows/systemTray.ts b/main/windows/systemTray.ts index f944920df..1446b1f24 100644 --- a/main/windows/systemTray.ts +++ b/main/windows/systemTray.ts @@ -1,8 +1,31 @@ -import { app, screen, BrowserWindow, Menu, KeyboardEvent, Rectangle, Tray as ElectronTray } from 'electron' +// @ts-ignore +import getos from 'getos' import path from 'path' +import { app, screen, BrowserWindow, Menu, KeyboardEvent, Rectangle, Tray as ElectronTray } from 'electron' + import { capitalize } from '../../resources/utils' const isMacOS = process.platform === 'darwin' +let isUbuntu23OrGreater = false + +if (process.platform === 'linux') { + try { + getos((error: Error, osInfo: any) => { + if (error) { + console.error('Could not determine Linux version', error) + } else { + if (osInfo.dist === 'Ubuntu' && osInfo.release) { + const majorVersion = parseInt(osInfo.release.split('.')[0], 10) + isUbuntu23OrGreater = majorVersion >= 23 + } + } + }) + } catch (error) { + console.error('Could not determine Linux version', error) + } +} + +const delaySettingContextMenu = () => !isMacOS && !isUbuntu23OrGreater export type SystemTrayEventHandlers = { click: () => void @@ -22,16 +45,9 @@ export class SystemTray { // Electron Tray can only be instantiated when the app is ready this.electronTray = new ElectronTray(path.join(__dirname, isMacOS ? './IconTemplate.png' : './Icon.png')) this.electronTray.on('click', (_event: KeyboardEvent, bounds: Rectangle) => { - console.log('---> Received click on tray', { bounds}) const mainWindowBounds = mainWindow.getBounds() - console.log('---> Main window bounds', mainWindowBounds) const currentDisplay = screen.getDisplayMatching(bounds) - console.log('---> Current display', currentDisplay) const trayClickDisplay = screen.getDisplayMatching(mainWindowBounds) - console.log('---> Tray click display', trayClickDisplay) - - console.log('---> Tray click display id', trayClickDisplay.id) - console.log('---> Current display id', currentDisplay.id) if (trayClickDisplay.id !== currentDisplay.id) { this.setContextMenu('show', { switchScreen: true }) } @@ -43,7 +59,6 @@ export class SystemTray { type: string, { displaySummonShortcut = false, accelerator = 'Alt+/', switchScreen = false } ) { - //console.log('---> Setting context menu', { type, displaySummonShortcut, accelerator, switchScreen }) const separatorMenuItem = { label: 'Frame', click: () => {}, @@ -75,7 +90,7 @@ export class SystemTray { if (switchScreen) { this.electronTray?.setContextMenu(menu) } else { - setTimeout(() => this.electronTray?.setContextMenu(menu), isMacOS ? 0 : 200) + setTimeout(() => this.electronTray?.setContextMenu(menu), delaySettingContextMenu() ? 200 : 0) } } diff --git a/package-lock.json b/package-lock.json index 9276ad425..29f1c9b04 100644 --- a/package-lock.json +++ b/package-lock.json @@ -42,6 +42,7 @@ "extract-zip": "2.0.1", "fs-extra": "11.1.0", "get-pixels": "3.3.3", + "getos": "3.2.1", "gridplus-sdk": "3.2.0", "hdkey": "2.1.0", "hotkeys-js": "3.10.1", @@ -16370,6 +16371,14 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/getos": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/getos/-/getos-3.2.1.tgz", + "integrity": "sha512-U56CfOK17OKgTVqozZjUKNdkfEv6jk5WISBJ8SHoagjE6L69zOwl3Z+O8myjY9MEW3i2HPWQBt/LTbCgcC973Q==", + "dependencies": { + "async": "^3.2.0" + } + }, "node_modules/getpass": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", @@ -39972,6 +39981,14 @@ "get-intrinsic": "^1.2.6" } }, + "getos": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/getos/-/getos-3.2.1.tgz", + "integrity": "sha512-U56CfOK17OKgTVqozZjUKNdkfEv6jk5WISBJ8SHoagjE6L69zOwl3Z+O8myjY9MEW3i2HPWQBt/LTbCgcC973Q==", + "requires": { + "async": "^3.2.0" + } + }, "getpass": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", diff --git a/package.json b/package.json index 4e2fce13c..dbeb5ce08 100644 --- a/package.json +++ b/package.json @@ -93,6 +93,7 @@ "extract-zip": "2.0.1", "fs-extra": "11.1.0", "get-pixels": "3.3.3", + "getos": "3.2.1", "gridplus-sdk": "3.2.0", "hdkey": "2.1.0", "hotkeys-js": "3.10.1", From b853fe9bd636746f70152cdb9dfd897d407fd02d Mon Sep 17 00:00:00 2001 From: Matt Holtzman Date: Fri, 31 Jan 2025 17:20:46 -0500 Subject: [PATCH 3/4] cleanup --- main/windows/index.ts | 1 - main/windows/systemTray.ts | 19 ++++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/main/windows/index.ts b/main/windows/index.ts index 945a411a1..a382ace55 100644 --- a/main/windows/index.ts +++ b/main/windows/index.ts @@ -149,7 +149,6 @@ function initTrayWindow() { windows.tray.setPosition(width + x, height + y) windows.tray.on('show', () => { - console.log('---> Tray show') if (process.platform === 'win32') { systemTray.closeContextMenu() } diff --git a/main/windows/systemTray.ts b/main/windows/systemTray.ts index 1446b1f24..153b264d6 100644 --- a/main/windows/systemTray.ts +++ b/main/windows/systemTray.ts @@ -10,16 +10,17 @@ let isUbuntu23OrGreater = false if (process.platform === 'linux') { try { - getos((error: Error, osInfo: any) => { - if (error) { - console.error('Could not determine Linux version', error) - } else { - if (osInfo.dist === 'Ubuntu' && osInfo.release) { - const majorVersion = parseInt(osInfo.release.split('.')[0], 10) - isUbuntu23OrGreater = majorVersion >= 23 + getos((error: Error, osInfo: any) => { + if (error) { + console.error('Could not determine Linux version', error) + } else { + if (osInfo.dist === 'Ubuntu' && osInfo.release) { + const majorVersion = parseInt(osInfo.release.split('.')[0], 10) + isUbuntu23OrGreater = majorVersion >= 23 + } + } } - } - }) + ) } catch (error) { console.error('Could not determine Linux version', error) } From 41747691c1570c8deecf50d81cde9aafc986c744 Mon Sep 17 00:00:00 2001 From: Matt Holtzman Date: Fri, 31 Jan 2025 17:21:25 -0500 Subject: [PATCH 4/4] fix formatting --- main/windows/systemTray.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/main/windows/systemTray.ts b/main/windows/systemTray.ts index 153b264d6..4dd48bf43 100644 --- a/main/windows/systemTray.ts +++ b/main/windows/systemTray.ts @@ -17,10 +17,9 @@ if (process.platform === 'linux') { if (osInfo.dist === 'Ubuntu' && osInfo.release) { const majorVersion = parseInt(osInfo.release.split('.')[0], 10) isUbuntu23OrGreater = majorVersion >= 23 - } } } - ) + }) } catch (error) { console.error('Could not determine Linux version', error) }