OSX: Added Option to hide Window from dock on close

This commit is contained in:
Martin Gondermann
2016-06-30 22:17:31 +02:00
parent 0f6688b4cf
commit 865b08105a
6 changed files with 49 additions and 7 deletions

View File

@@ -15,6 +15,7 @@
#### OS X
- Fixed that two icons appear on a notification.
- Added Option to hide Window from dock on close
### Improvements
- Added shortcuts

View File

@@ -124,7 +124,7 @@ The Settings Page is available from the **File** menu under **Settings** (Click
This option allows such images to be rendered, but please be careful for security.
- **Start app on login** (Windows, Linux)
- This option starts the application when you login.
- **Leave app running in notification area when the window is closed** (Windows)
- **Leave app running in notification area when the window is closed** (Windows, OS X)
- This option hides the window to the system tray, if the window is closed
- **Toggle window visibility when clicking on the tray icon** (Windows)
- If checked, then a click on the system tray icon leads to a toggling of the minimized/maximized state of the window

View File

@@ -102,9 +102,16 @@ var SettingsPage = React.createClass({
});
},
handleChangeShowTrayIcon: function() {
var shouldShowTrayIcon = this.refs.showTrayIcon.getChecked();
this.setState({
showTrayIcon: this.refs.showTrayIcon.getChecked()
showTrayIcon: shouldShowTrayIcon
});
if (process.platform === 'darwin' && !shouldShowTrayIcon) {
this.setState({
minimizeToTray: false
});
}
},
handleChangeTrayIconTheme: function() {
this.setState({
@@ -117,8 +124,11 @@ var SettingsPage = React.createClass({
});
},
handleChangeMinimizeToTray: function() {
var shouldMinimizeToTray = (process.platform !== 'darwin' || this.refs.showTrayIcon.getChecked())
&& this.refs.minimizeToTray.getChecked();
this.setState({
minimizeToTray: this.refs.minimizeToTray.getChecked()
minimizeToTray: shouldMinimizeToTray
});
},
handleChangeToggleWindowOnTrayIconClick: function() {
@@ -172,6 +182,12 @@ var SettingsPage = React.createClass({
if (process.platform === 'win32') {
options.push(<Input key="inputMinimizeToTray" id="inputMinimizeToTray" ref="minimizeToTray" type="checkbox" label="Leave app running in notification area when the window is closed"
checked={ this.state.minimizeToTray } onChange={ this.handleChangeMinimizeToTray } />);
} else if (process.platform === 'darwin') {
options.push(<Input key="inputMinimizeToTray" id="inputMinimizeToTray" ref="minimizeToTray" type="checkbox" label="Leave app running in notification area when the window is closed"
disabled={ !this.state.showTrayIcon } checked={ this.state.minimizeToTray } onChange={ this.handleChangeMinimizeToTray } />);
}
if (process.platform === 'win32') {
options.push(<Input key="inputToggleWindowOnTrayIconClick" id="inputToggleWindowOnTrayIconClick" ref="toggleWindowOnTrayIconClick" type="checkbox" label="Toggle window visibility when clicking on the tray icon."
checked={ this.state.toggleWindowOnTrayIconClick } onChange={ this.handleChangeToggleWindowOnTrayIconClick } />);
}

View File

@@ -241,10 +241,22 @@ app.on('ready', function() {
mainWindow.focus();
}
}
else if (process.platform === 'darwin') {
if (mainWindow.isHidden || mainWindow.isMinimized()) {
mainWindow.show();
mainWindow.isHidden = false;
mainWindow.focus();
app.dock.show();
}
else {
mainWindow.focus();
}
}
else {
mainWindow.focus();
}
});
trayIcon.on('right-click', () => {
trayIcon.popUpContextMenu();
});
@@ -380,7 +392,14 @@ app.on('ready', function() {
mainWindow.minimize();
break;
case 'darwin':
if (config.minimizeToTray) {
mainWindow.hide();
app.dock.hide();
mainWindow.isHidden = true;
}
else {
mainWindow.minimize();
}
break;
default:
}

View File

@@ -11,6 +11,12 @@ function createDefault(mainWindow) {
label: `Open ${app.getName()}`,
click: () => {
mainWindow.show();
mainWindow.isHidden = false;
if (process.platform === 'darwin') {
app.dock.show();
mainWindow.focus();
}
}
}, {
type: 'separator'

View File

@@ -152,8 +152,8 @@ describe('browser/settings.html', function() {
});
describe('Minimize to tray', function() {
it('should appear win32', function() {
const expected = (process.platform === 'win32');
it('should appear on win32 and darwin', function() {
const expected = (process.platform === 'win32' || process.platform === 'darwin');
env.addClientCommands(this.app.client);
return this.app.client
.loadSettingsPage()
@@ -162,7 +162,7 @@ describe('browser/settings.html', function() {
});
describe('Toggle window visibility when clicking on the tray icon', function() {
it('should appear win32', function() {
it('should appear on win32', function() {
const expected = (process.platform === 'win32');
env.addClientCommands(this.app.client);
return this.app.client