Add feature to hide window into system tray in Linux

This commit is contained in:
Yuya Ochiai 2016-07-05 23:49:10 +09:00
parent d235eeb8b3
commit ad7f63127f
3 changed files with 17 additions and 17 deletions

View file

@ -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(<Input key="inputMinimizeToTray" id="inputMinimizeToTray" ref="minimizeToTray" type="checkbox" label={ this.state.trayWasVisible || !this.state.showTrayIcon ? "Leave app running in notification area when the window is closed" : "Leave app running in notification area when the window is closed (available on next restart)" } disabled={ !this.state.showTrayIcon || !this.state.trayWasVisible } checked={ this.state.minimizeToTray }
onChange={ this.handleChangeMinimizeToTray } />);
}

View file

@ -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();

View file

@ -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()