From d611050d4688bdf5d25b2130ba3e0af1672c8ba7 Mon Sep 17 00:00:00 2001 From: Ramiro Saenz Date: Wed, 26 Apr 2017 15:58:30 -0300 Subject: [PATCH] Added new preference "Display behaviour" To select Show in Taskbar, Show Tray Icon or both. Fixes #646 --- app/view/preferences/Preferences.js | 68 ++++++++++++++++++----------- electron/main.js | 23 ++++++++-- electron/tray.js | 9 ++-- 3 files changed, 67 insertions(+), 33 deletions(-) diff --git a/app/view/preferences/Preferences.js b/app/view/preferences/Preferences.js index f24d77dc..4d5733d8 100644 --- a/app/view/preferences/Preferences.js +++ b/app/view/preferences/Preferences.js @@ -15,12 +15,13 @@ Ext.define('Rambox.view.preferences.Preferences',{ } ,title: 'Preferences' - ,width: 400 + ,width: 420 ,modal: true ,closable: true ,minimizable: false ,maximizable: false ,draggable: true + ,resizable: false ,buttons: [ { text: 'Cancel' @@ -62,33 +63,48 @@ Ext.define('Rambox.view.preferences.Preferences',{ ,hidden: process.platform !== 'win32' } ,{ - xtype: 'checkbox' - ,name: 'skip_taskbar' - ,boxLabel: 'Show in Taskbar' - ,value: config.skip_taskbar - ,reference: 'skipTaskbar' + xtype: 'combo' + ,name: 'window_display_behavior' + ,fieldLabel: 'Display behaviour' + ,labelAlign: 'left' + ,width: 380 + ,labelWidth: 105 + ,value: config.window_display_behavior + ,displayField: 'label' + ,valueField: 'value' + ,editable: false + ,store: Ext.create('Ext.data.Store', { + fields: ['value', 'label'] + ,data: [ + { 'value': 'show_taskbar', 'label': 'Show in Taskbar' } + ,{ 'value': 'show_trayIcon', 'label': 'Show Tray Icon' } + ,{ 'value': 'taskbar_tray', 'label': 'Show in Taskbar and Tray Icon' } + ] + }) ,hidden: process.platform === 'darwin' - }, - { - xtype: 'combo', - name: 'window_close_behavior', - fieldLabel: 'When closing the main window', - labelAlign: 'top', - value: config.window_close_behavior, - displayField: 'label', - valueField: 'value', - editable: false, - store: Ext.create('Ext.data.Store', { - fields: ['value', 'label'], - data : [ - { 'value': 'keep_in_tray', 'label': 'Keep in tray' }, - { 'value': 'keep_in_tray_and_taskbar', 'label': 'Keep in tray and taskbar' }, - { 'value': 'quit', 'label': 'Quit' } + } + ,{ + xtype: 'combo' + ,name: 'window_close_behavior' + ,fieldLabel: 'When closing the main window' + ,labelAlign: 'left' + ,width: 380 + ,labelWidth: 180 + ,value: config.window_close_behavior + ,displayField: 'label' + ,valueField: 'value' + ,editable: false + ,store: Ext.create('Ext.data.Store', { + fields: ['value', 'label'] + ,data: [ + { 'value': 'keep_in_tray', 'label': 'Keep in tray' } + ,{ 'value': 'keep_in_tray_and_taskbar', 'label': 'Keep in tray and taskbar' } + ,{ 'value': 'quit', 'label': 'Quit' } ] - }), - hidden: process.platform === 'darwin' - }, - { + }) + ,hidden: process.platform === 'darwin' + } + ,{ xtype: 'checkbox' ,name: 'always_on_top' ,boxLabel: 'Always on top' diff --git a/electron/main.js b/electron/main.js index 1e66fd28..2129be23 100644 --- a/electron/main.js +++ b/electron/main.js @@ -22,7 +22,7 @@ const config = new Config({ defaults: { always_on_top: false ,hide_menu_bar: false - ,skip_taskbar: true + ,window_display_behavior: 'taskbar_tray' ,auto_launch: !isDev ,window_close_behavior: 'keep_in_tray' ,start_minimized: false @@ -132,7 +132,7 @@ function createWindow () { ,height: config.get('height') ,alwaysOnTop: config.get('always_on_top') ,autoHideMenuBar: config.get('hide_menu_bar') - ,skipTaskbar: !config.get('skip_taskbar') + ,skipTaskbar: config.get('window_display_behavior') === 'show_trayIcon' ,show: !config.get('start_minimized') ,webPreferences: { webSecurity: false @@ -262,14 +262,29 @@ ipcMain.on('setConfig', function(event, values) { // hide_menu_bar mainWindow.setAutoHideMenuBar(values.hide_menu_bar); if ( !values.hide_menu_bar ) mainWindow.setMenuBarVisibility(true); - // skip_taskbar - mainWindow.setSkipTaskbar(!values.skip_taskbar); // always_on_top mainWindow.setAlwaysOnTop(values.always_on_top); // auto_launch values.auto_launch ? appLauncher.enable() : appLauncher.disable(); // systemtray_indicator updateBadge(mainWindow.getTitle()); + + switch ( values.window_display_behavior ) { + case 'show_taskbar': + mainWindow.setSkipTaskbar(false); + tray.destroy(); + break; + case 'show_trayIcon': + mainWindow.setSkipTaskbar(true); + tray.create(mainWindow, config); + break; + case 'taskbar_tray': + mainWindow.setSkipTaskbar(false); + tray.create(mainWindow, config); + break; + default: + break; + } }); ipcMain.on('validateMasterPassword', function(event, pass) { diff --git a/electron/tray.js b/electron/tray.js index 4b02838c..c122e652 100644 --- a/electron/tray.js +++ b/electron/tray.js @@ -8,9 +8,7 @@ const MenuItem = electron.MenuItem; var appIcon = null; exports.create = function(win, config) { - if (process.platform === 'darwin' || appIcon) { - return; - } + if (process.platform === 'darwin' || appIcon || config.get('window_display_behavior') === 'show_taskbar' ) return; const icon = process.platform === 'linux' || process.platform === 'darwin' ? 'IconTray.png' : 'Icon.ico'; const iconPath = path.join(__dirname, `../resources/${icon}`); @@ -41,6 +39,11 @@ exports.create = function(win, config) { }); }; +exports.destroy = function() { + appIcon.destroy(); + appIcon = null; +}; + exports.setBadge = function(messageCount, showUnreadTray) { if (process.platform === 'darwin' || !appIcon) return;