From 5df0fd9dc81ffd7107aa4447eff7aa925c9aab9e Mon Sep 17 00:00:00 2001 From: Didier Roche Date: Mon, 14 May 2018 11:00:41 +0200 Subject: [PATCH] fix: more scalable code by factorizing appindicator support - introduce a currentPlatformSupportsAppIndicator() function determining if app indicators are supported here. - handle undefined process.env.XDG_CURRENT_DESKTOP - added some comments to ensure that the intents are clear Thanks MarshallOfSound --- lib/browser/init.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/browser/init.js b/lib/browser/init.js index 0234d8f99de5..a6f5803a524b 100644 --- a/lib/browser/init.js +++ b/lib/browser/init.js @@ -162,11 +162,24 @@ require('./api/protocol') // Set main startup script of the app. const mainStartupScript = packageJson.main || 'index.js' +const KNOWN_XDG_DESKTOP_VALUES = ['Pantheon', 'Unity:Unity7', 'pop:GNOME'] + +function currentPlatformSupportsAppIndicator() { + if (process.platform !== 'linux') return false + const currentDesktop = process.env.XDG_CURRENT_DESKTOP + + if (!currentDesktop) return false + if (KNOWN_XDG_DESKTOP_VALUES.includes(currentDesktop)) return true + // ubuntu based or derived session (default ubuntu one, communitheme…) supports + // indicator too. + if (/ubuntu/ig.test(currentDesktop)) return true + + return false +} + // Workaround for electron/electron#5050 and electron/electron#9046 -if (process.platform === 'linux') { - if (['Pantheon', 'Unity:Unity7', 'pop:GNOME'].includes(process.env.XDG_CURRENT_DESKTOP) || process.env.XDG_CURRENT_DESKTOP.includes('ubuntu')) { - process.env.XDG_CURRENT_DESKTOP = 'Unity' - } +if (currentPlatformSupportsAppIndicator()) { + process.env.XDG_CURRENT_DESKTOP = 'Unity' } // Finally load app's main.js and transfer control to C++.