From ad7f63127fcebb900b65d3552885c72cf93b8bde Mon Sep 17 00:00:00 2001 From: Yuya Ochiai Date: Tue, 5 Jul 2016 23:49:10 +0900 Subject: [PATCH] Add feature to hide window into system tray in Linux --- src/browser/settings.jsx | 20 +++++++------------- src/main.js | 10 ++++++++-- test/specs/browser/settings_test.js | 4 ++-- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/browser/settings.jsx b/src/browser/settings.jsx index 252131c1..3cfe5282 100644 --- a/src/browser/settings.jsx +++ b/src/browser/settings.jsx @@ -27,16 +27,17 @@ function backToIndex() { var SettingsPage = React.createClass({ getInitialState: function() { - var config; + var initialState; try { - config = settings.readFileSync(this.props.configFile); + initialState = settings.readFileSync(this.props.configFile); } catch (e) { - config = settings.loadDefault(); + initialState = settings.loadDefault(); } - config.showAddTeamForm = false; + initialState.showAddTeamForm = false; + initialState.trayWasVisible = remote.getCurrentWindow().trayWasVisible; - return config; + return initialState; }, componentDidMount: function() { if (process.platform === 'win32' || process.platform === 'linux') { @@ -47,13 +48,6 @@ var SettingsPage = React.createClass({ }); }); } - - if (process.platform === 'darwin') { - var currentWindow = remote.getCurrentWindow(); - this.setState({ - trayWasVisible: currentWindow.trayWasVisible - }); - } }, handleTeamsChange: function(teams) { this.setState({ @@ -188,7 +182,7 @@ var SettingsPage = React.createClass({ />); } - if (process.platform === 'darwin') { + if (process.platform === 'darwin' || process.platform === 'linux') { options.push(); } diff --git a/src/main.js b/src/main.js index cb458770..1d5aaf3f 100644 --- a/src/main.js +++ b/src/main.js @@ -232,7 +232,7 @@ app.on('ready', function() { trayIcon.setToolTip(app.getName()); trayIcon.on('click', function() { - if (process.platform === 'win32') { + if (process.platform === 'win32' || process.platform === 'linux') { if (mainWindow.isHidden || mainWindow.isMinimized()) { mainWindow.show(); mainWindow.isHidden = false; @@ -407,7 +407,13 @@ app.on('ready', function() { mainWindow.isHidden = true; break; case 'linux': - mainWindow.minimize(); + if (config.minimizeToTray) { + mainWindow.hide(); + mainWindow.isHidden = true; + } + else { + mainWindow.minimize(); + } break; case 'darwin': mainWindow.hide(); diff --git a/test/specs/browser/settings_test.js b/test/specs/browser/settings_test.js index 92229e7e..17e3969e 100644 --- a/test/specs/browser/settings_test.js +++ b/test/specs/browser/settings_test.js @@ -152,8 +152,8 @@ describe('browser/settings.html', function() { }); describe('Minimize to tray', function() { - it('should appear on darwin', function() { - const expected = (process.platform === 'darwin'); + it('should appear on darwin or linux', function() { + const expected = (process.platform === 'darwin' || process.platform === 'linux'); env.addClientCommands(this.app.client); return this.app.client .loadSettingsPage()