diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2021-11-22 09:13:08 +0100 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2021-11-22 13:13:21 +0100 |
| commit | bcf34bb9fd27136305daeec88ee113324d7a9f09 (patch) | |
| tree | ced164384e00bd8d35a77dd45ca639ca4ab6fc5a | |
| parent | bde1bb119f09d43f11cb720916a54e84f717a685 (diff) | |
| download | mullvadvpn-bcf34bb9fd27136305daeec88ee113324d7a9f09.tar.xz mullvadvpn-bcf34bb9fd27136305daeec88ee113324d7a9f09.zip | |
Move platform version checks to it's own file
| -rw-r--r-- | gui/src/main/index.ts | 5 | ||||
| -rw-r--r-- | gui/src/main/platform-version.ts | 21 | ||||
| -rw-r--r-- | gui/src/main/window-controller.ts | 8 |
3 files changed, 26 insertions, 8 deletions
diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts index 0916a18166..8313fa73d9 100644 --- a/gui/src/main/index.ts +++ b/gui/src/main/index.ts @@ -13,7 +13,6 @@ import { systemPreferences, Tray, } from 'electron'; -import os from 'os'; import * as path from 'path'; import { sprintf } from 'sprintf-js'; import util from 'util'; @@ -71,6 +70,7 @@ import { } from './logging'; import { loadTranslations } from './load-translations'; import NotificationController from './notification-controller'; +import { isMacOs11OrNewer } from './platform-version'; import { resolveBin } from './proc'; import ReconnectionBackoff from './reconnection-backoff'; import TrayIconController, { TrayIconType } from './tray-icon-controller'; @@ -1947,8 +1947,7 @@ class ApplicationMain { if (event.metaKey) { setImmediate(() => this.windowController?.updatePosition()); } else { - const isBigSurOrNewer = parseInt(os.release(), 10) >= 20; - if (isBigSurOrNewer && !this.windowController?.isVisible()) { + if (isMacOs11OrNewer() && !this.windowController?.isVisible()) { // This is a workaround for this Electron issue, when it's resolved // `this.windowController?.toggle()` should do the trick on all platforms: // https://github.com/electron/electron/issues/28776 diff --git a/gui/src/main/platform-version.ts b/gui/src/main/platform-version.ts new file mode 100644 index 0000000000..51f73fe75b --- /dev/null +++ b/gui/src/main/platform-version.ts @@ -0,0 +1,21 @@ +import os from 'os'; + +export function isMacOs11OrNewer() { + const [major] = parseVersion(); + return process.platform === 'darwin' && major >= 20; +} + +// Windows 11 has the internal version 10.0.22000+. +export function isWindows11OrNewer() { + const [major, minor, patch] = parseVersion(); + return ( + process.platform === 'win32' && (major > 10 || (major === 10 && (minor > 0 || patch >= 22000))) + ); +} + +function parseVersion() { + return os + .release() + .split('.') + .map((value) => parseInt(value, 10)); +} diff --git a/gui/src/main/window-controller.ts b/gui/src/main/window-controller.ts index dff90de639..c4d6b47232 100644 --- a/gui/src/main/window-controller.ts +++ b/gui/src/main/window-controller.ts @@ -1,8 +1,8 @@ import { BrowserWindow, Display, screen, Tray, WebContents } from 'electron'; -import os from 'os'; import { IWindowShapeParameters } from '../shared/ipc-types'; import { Scheduler } from '../shared/scheduler'; import { IpcMainEventChannel } from './ipc-event-channel'; +import { isWindows11OrNewer } from './platform-version'; interface IPosition { x: number; @@ -14,10 +14,8 @@ interface IWindowPositioning { getWindowShapeParameters(window: BrowserWindow): IWindowShapeParameters; } -// Tray applications are positioned aproximately 10px from the tray in Windows 11. Windows 11 has -// the internal version 10.0.22000+. -const MARGIN = - process.platform === 'win32' && parseInt(os.release().split('.').at(-1)!) >= 22000 ? 10 : 0; +// Tray applications are positioned aproximately 10px from the tray in Windows 11. +const MARGIN = isWindows11OrNewer() ? 10 : 0; class StandaloneWindowPositioning implements IWindowPositioning { public getPosition(window: BrowserWindow): IPosition { |
