diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2021-09-09 21:03:40 +0200 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2021-09-10 09:51:38 +0200 |
| commit | 5814461b5918f63fb834231366eeff5d05bee6bd (patch) | |
| tree | 3f97e21a37b69a38364eadb84f1e6deeea29970b | |
| parent | f61e0ea1297bb22454e6a8281661b990288fbcce (diff) | |
| download | mullvadvpn-5814461b5918f63fb834231366eeff5d05bee6bd.tar.xz mullvadvpn-5814461b5918f63fb834231366eeff5d05bee6bd.zip | |
Read macOS scrollbar visibility setting
| -rw-r--r-- | gui/src/main/index.ts | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts index fc9170bf24..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(); @@ -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(); |
