diff options
| author | Andrej Mihajlov <and@codeispoetry.ru> | 2017-03-03 13:13:12 +0000 |
|---|---|---|
| committer | Andrej Mihajlov <and@codeispoetry.ru> | 2017-03-03 13:13:12 +0000 |
| commit | 94496a26d622c58d6f4e923f51754bbad42f6e23 (patch) | |
| tree | 49db1104b0c86de0191170e7bec0ed9664a55c43 | |
| parent | 9215e563123546c6ab219e6f3f904954a48912fa (diff) | |
| download | mullvadvpn-94496a26d622c58d6f4e923f51754bbad42f6e23.tar.xz mullvadvpn-94496a26d622c58d6f4e923f51754bbad42f6e23.zip | |
Make sure we only require NSEventMonitor on macOS
| -rw-r--r-- | app/main.js | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/app/main.js b/app/main.js index f3d5f079db..3708442e05 100644 --- a/app/main.js +++ b/app/main.js @@ -1,6 +1,5 @@ import path from 'path'; import { app, crashReporter, BrowserWindow, ipcMain, Tray, Menu, nativeImage } from 'electron'; -import NSEventMonitor from 'nseventmonitor'; // Override appData path to avoid collisions with old client // New userData path, i.e on macOS: ~/Library/Application Support/mullvad.vpn @@ -12,7 +11,23 @@ const isDevelopment = (process.env.NODE_ENV === 'development'); let window = null; let tray = null; -let macEventMonitor = new NSEventMonitor(); +let macEventMonitor = null; + +const startTrayEventMonitor = (win) => { + if(process.platform === 'darwin') { + if(macEventMonitor === null) { + const NSEventMonitor = require('nseventmonitor'); + macEventMonitor = new NSEventMonitor(); + } + macEventMonitor.start(() => win.hide()); + } +}; + +const stopTrayEventMonitor = () => { + if(process.platform === 'darwin') { + macEventMonitor.stop(); + } +}; ipcMain.on('changeTrayIcon', (event, name) => { const iconPath = path.join(__dirname, './assets/images/tray-icon-' + name + '.png'); @@ -114,16 +129,12 @@ const createWindow = () => { window.on('show', () => { tray.setHighlightMode('always'); - - macEventMonitor.start(() => { - window.hide(); - }); + startTrayEventMonitor(window); }); window.on('hide', () => { tray.setHighlightMode('never'); - - macEventMonitor.stop(); + stopTrayEventMonitor(); }); }; |
