diff --git a/main/windows/systemTray.ts b/main/windows/systemTray.ts index d6f92826d9..4dd48bf433 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 @@ -67,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 9276ad425a..29f1c9b045 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 4e2fce13c6..dbeb5ce08e 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",