diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2021-09-13 13:33:54 +0200 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2021-09-13 13:33:54 +0200 |
| commit | 343fd4ff64150920f14de07c66385f5bb3fff9ed (patch) | |
| tree | 00cf12cabe0545acec7d9f457d8cdd30ffd2888f /gui/src/main | |
| parent | 8c7653b4f16d48d39154b149f9c49a0be5209caa (diff) | |
| parent | 6ab3a737364bfa5e593581d968081c5b86bdb372 (diff) | |
| download | mullvadvpn-343fd4ff64150920f14de07c66385f5bb3fff9ed.tar.xz mullvadvpn-343fd4ff64150920f14de07c66385f5bb3fff9ed.zip | |
Merge branch 'detect-macos-scrollbar-visibility'
Diffstat (limited to 'gui/src/main')
| -rw-r--r-- | gui/src/main/index.ts | 47 | ||||
| -rw-r--r-- | gui/src/main/window-controller.ts | 2 |
2 files changed, 44 insertions, 5 deletions
diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts index 8fa09576c7..ff7e9e64a7 100644 --- a/gui/src/main/index.ts +++ b/gui/src/main/index.ts @@ -1,4 +1,4 @@ -import { execFile } from 'child_process'; +import { exec, execFile } from 'child_process'; import { app, BrowserWindow, @@ -8,11 +8,13 @@ import { screen, session, shell, + systemPreferences, Tray, } from 'electron'; import os from 'os'; import * as path from 'path'; import { sprintf } from 'sprintf-js'; +import util from 'util'; import * as uuid from 'uuid'; import config from '../config.json'; import { closeToExpiry, hasExpired } from '../shared/account-expiry'; @@ -72,7 +74,9 @@ import { resolveBin } from './proc'; import ReconnectionBackoff from './reconnection-backoff'; import TrayIconController, { TrayIconType } from './tray-icon-controller'; import WindowController from './window-controller'; -import { ITranslations } from '../shared/ipc-schema'; +import { ITranslations, MacOsScrollbarVisibility } from '../shared/ipc-schema'; + +const execAsync = util.promisify(exec); // Only import split tunneling library on correct OS. const linuxSplitTunneling = process.platform === 'linux' && require('./linux-split-tunneling'); @@ -235,6 +239,8 @@ class ApplicationMain { private windowsSplitTunnelingApplications?: IApplication[]; + private macOsScrollbarVisibility?: MacOsScrollbarVisibility; + public run() { // Remove window animations to combat window flickering when opening window. Can be removed when // this issue has been resolved: https://github.com/electron/electron/issues/12130 @@ -437,6 +443,13 @@ class ApplicationMain { ); this.connectToDaemon(); + if (process.platform === 'darwin') { + await this.updateMacOsScrollbarVisibility(); + systemPreferences.subscribeNotification('AppleShowScrollBarsSettingChanged', async () => { + await this.updateMacOsScrollbarVisibility(); + }); + } + const window = await this.createWindow(); const tray = this.createTray(); @@ -1032,7 +1045,7 @@ class ApplicationMain { private registerWindowListener(windowController: WindowController) { windowController.window?.on('focus', () => { - IpcMainEventChannel.windowFocus.notify(windowController.webContents, true); + IpcMainEventChannel.window.notifyFocus(windowController.webContents, true); this.blurNavigationResetScheduler.cancel(); @@ -1049,7 +1062,7 @@ class ApplicationMain { }); windowController.window?.on('blur', () => { - IpcMainEventChannel.windowFocus.notify(windowController.webContents, false); + IpcMainEventChannel.window.notifyFocus(windowController.webContents, false); // ensure notification guard is reset this.notificationController.resetTunnelStateAnnouncements(); @@ -1087,6 +1100,7 @@ class ApplicationMain { wireguardPublicKey: this.wireguardPublicKey, translations: this.translations, windowsSplitTunnelingApplications: this.windowsSplitTunnelingApplications, + macOsScrollbarVisibility: this.macOsScrollbarVisibility, })); IpcMainEventChannel.settings.handleSetAllowLan((allowLan: boolean) => @@ -1994,6 +2008,31 @@ class ApplicationMain { private getProblemReportPath(id: string): string { return path.join(app.getPath('temp'), `${id}.log`); } + + private async updateMacOsScrollbarVisibility(): Promise<void> { + const command = + 'defaults read kCFPreferencesAnyApplication AppleShowScrollBars || echo Automatic'; + const { stdout } = await execAsync(command); + switch (stdout.trim()) { + case 'WhenScrolling': + this.macOsScrollbarVisibility = MacOsScrollbarVisibility.whenScrolling; + break; + case 'Always': + this.macOsScrollbarVisibility = MacOsScrollbarVisibility.always; + break; + case 'Automatic': + default: + this.macOsScrollbarVisibility = MacOsScrollbarVisibility.automatic; + break; + } + + if (this.windowController?.webContents) { + IpcMainEventChannel.window.notifyMacOsScrollbarVisibility( + this.windowController.webContents, + this.macOsScrollbarVisibility, + ); + } + } } const applicationMain = new ApplicationMain(); diff --git a/gui/src/main/window-controller.ts b/gui/src/main/window-controller.ts index 50ceab01e4..298f767fb5 100644 --- a/gui/src/main/window-controller.ts +++ b/gui/src/main/window-controller.ts @@ -230,7 +230,7 @@ export default class WindowController { if (this.window) { const shapeParameters = this.windowPositioning.getWindowShapeParameters(this.window); - IpcMainEventChannel.windowShape.notify(this.webContentsValue, shapeParameters); + IpcMainEventChannel.window.notifyShape(this.webContentsValue, shapeParameters); } } |
