From cc536c1268370e7abdfc089e3a5868b93cb5bd08 Mon Sep 17 00:00:00 2001 From: Juan Tejada Date: Sat, 21 Nov 2015 19:05:29 -0800 Subject: [PATCH] fix(tray): Prevent system tray from being initialized more than once - Makes sure the tray is deactivated before activating --- internal_packages/system-tray/lib/main.es6 | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/internal_packages/system-tray/lib/main.es6 b/internal_packages/system-tray/lib/main.es6 index 4ae4f79c0..29dc2f2df 100644 --- a/internal_packages/system-tray/lib/main.es6 +++ b/internal_packages/system-tray/lib/main.es6 @@ -2,7 +2,7 @@ import SystemTray from './system-tray'; const platform = process.platform; let systemTray; -let unsubConfig; +let unsubConfig = ()=>{}; const onSystemTrayToggle = (showSystemTray)=> { if (showSystemTray.newValue) { systemTray = new SystemTray(platform); @@ -12,13 +12,6 @@ const onSystemTrayToggle = (showSystemTray)=> { } }; -export function activate() { - unsubConfig = NylasEnv.config.onDidChange('core.showSystemTray', onSystemTrayToggle).dispose; - if (NylasEnv.config.get('core.showSystemTray')) { - systemTray = new SystemTray(platform); - } -} - export function deactivate() { if (systemTray) { systemTray.destroy(); @@ -27,6 +20,14 @@ export function deactivate() { unsubConfig(); } +export function activate() { + deactivate(); + unsubConfig = NylasEnv.config.onDidChange('core.showSystemTray', onSystemTrayToggle).dispose; + if (NylasEnv.config.get('core.showSystemTray')) { + systemTray = new SystemTray(platform); + } +} + export function serialize() { }