Skip to content

Commit dac4378

Browse files
authored
Fix context menu issues on Ubuntu 23+ (#1733)
1 parent a1f65e8 commit dac4378

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

main/windows/systemTray.ts

+25-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,31 @@
1-
import { app, screen, BrowserWindow, Menu, KeyboardEvent, Rectangle, Tray as ElectronTray } from 'electron'
1+
// @ts-ignore
2+
import getos from 'getos'
23
import path from 'path'
4+
import { app, screen, BrowserWindow, Menu, KeyboardEvent, Rectangle, Tray as ElectronTray } from 'electron'
5+
36
import { capitalize } from '../../resources/utils'
47

58
const isMacOS = process.platform === 'darwin'
9+
let isUbuntu23OrGreater = false
10+
11+
if (process.platform === 'linux') {
12+
try {
13+
getos((error: Error, osInfo: any) => {
14+
if (error) {
15+
console.error('Could not determine Linux version', error)
16+
} else {
17+
if (osInfo.dist === 'Ubuntu' && osInfo.release) {
18+
const majorVersion = parseInt(osInfo.release.split('.')[0], 10)
19+
isUbuntu23OrGreater = majorVersion >= 23
20+
}
21+
}
22+
})
23+
} catch (error) {
24+
console.error('Could not determine Linux version', error)
25+
}
26+
}
27+
28+
const delaySettingContextMenu = () => !isMacOS && !isUbuntu23OrGreater
629

730
export type SystemTrayEventHandlers = {
831
click: () => void
@@ -67,7 +90,7 @@ export class SystemTray {
6790
if (switchScreen) {
6891
this.electronTray?.setContextMenu(menu)
6992
} else {
70-
setTimeout(() => this.electronTray?.setContextMenu(menu), isMacOS ? 0 : 200)
93+
setTimeout(() => this.electronTray?.setContextMenu(menu), delaySettingContextMenu() ? 200 : 0)
7194
}
7295
}
7396

package-lock.json

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
"extract-zip": "2.0.1",
9494
"fs-extra": "11.1.0",
9595
"get-pixels": "3.3.3",
96+
"getos": "3.2.1",
9697
"gridplus-sdk": "3.2.0",
9798
"hdkey": "2.1.0",
9899
"hotkeys-js": "3.10.1",

0 commit comments

Comments
 (0)