|
1 |
| -import { app, screen, BrowserWindow, Menu, KeyboardEvent, Rectangle, Tray as ElectronTray } from 'electron' |
| 1 | +// @ts-ignore |
| 2 | +import getos from 'getos' |
2 | 3 | import path from 'path'
|
| 4 | +import { app, screen, BrowserWindow, Menu, KeyboardEvent, Rectangle, Tray as ElectronTray } from 'electron' |
| 5 | + |
3 | 6 | import { capitalize } from '../../resources/utils'
|
4 | 7 |
|
5 | 8 | 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 |
6 | 29 |
|
7 | 30 | export type SystemTrayEventHandlers = {
|
8 | 31 | click: () => void
|
@@ -67,7 +90,7 @@ export class SystemTray {
|
67 | 90 | if (switchScreen) {
|
68 | 91 | this.electronTray?.setContextMenu(menu)
|
69 | 92 | } else {
|
70 |
| - setTimeout(() => this.electronTray?.setContextMenu(menu), isMacOS ? 0 : 200) |
| 93 | + setTimeout(() => this.electronTray?.setContextMenu(menu), delaySettingContextMenu() ? 200 : 0) |
71 | 94 | }
|
72 | 95 | }
|
73 | 96 |
|
|
0 commit comments