Show menubar in default setttings on Windows, and add the option to hide

This commit is contained in:
Yuya Ochiai
2016-01-14 22:50:12 +09:00
parent d6afda37f2
commit 267d0e3ded
2 changed files with 45 additions and 18 deletions

View File

@@ -6,6 +6,7 @@ const settings = require('../common/settings');
const Grid = ReactBootstrap.Grid;
const Row = ReactBootstrap.Row;
const Col = ReactBootstrap.Col;
const Input = ReactBootstrap.Input;
const Button = ReactBootstrap.Button;
const ListGroup = ReactBootstrap.ListGroup;
const ListGroupItem = ReactBootstrap.ListGroupItem;
@@ -13,15 +14,11 @@ const Glyphicon = ReactBootstrap.Glyphicon;
var SettingsPage = React.createClass({
getInitialState: function() {
return {
teams: []
};
},
componentDidMount: function() {
var config = settings.readFileSync(this.props.configFile);
this.setState({
teams: config.teams
})
return {
teams: config.teams,
hideMenuBar: config.hideMenuBar
};
},
handleTeamsChange: function(teams) {
this.setState({
@@ -31,23 +28,50 @@ var SettingsPage = React.createClass({
handleSave: function() {
var config = {
teams: this.state.teams,
version: 1
hideMenuBar: this.refs.hideMenuBar.getChecked(),
version: settings.version
};
settings.writeFileSync(this.props.configFile, config);
var currentWindow = remote.getCurrentWindow();
currentWindow.setAutoHideMenuBar(config.hideMenuBar);
currentWindow.setMenuBarVisibility(!config.hideMenuBar);
window.location = './index.html';
},
handleCancel: function() {
window.location = './index.html';
},
handleChangeHideMenuBar: function() {
this.setState({
hideMenuBar: this.refs.hideMenuBar.getChecked()
});
},
render: function() {
var teams_row = (
<Row>
<Col md={ 12 }>
<h2>Teams</h2>
<TeamList teams={ this.state.teams } onTeamsChange={ this.handleTeamsChange } />
</Col>
</Row>
);
var options = [];
if (process.platform === 'win32') {
options.push(<Input ref="hideMenuBar" type="checkbox" label="Hide menubar (Press Alt to show menubar)" checked={ this.state.hideMenuBar } onChange={ this.handleChangeHideMenuBar } />);
}
var options_row = (options.length > 0) ? (
<Row>
<Col md={ 12 }>
<h2>Options</h2>
{ options }
</Col>
</Row>
) : null;
return (
<Grid className="settingsPage">
<Row>
<Col md={ 12 }>
<h2>Teams</h2>
<TeamList teams={ this.state.teams } onTeamsChange={ this.handleTeamsChange } />
</Col>
</Row>
{ teams_row }
{ options_row }
<Row>
<Col md={ 12 }>
<Button id="btnCancel" onClick={ this.handleCancel }>Cancel</Button>

View File

@@ -28,9 +28,10 @@ else {
global['config-file'] = app.getPath('userData') + '/config.json'
}
var config = {};
try {
var configFile = global['config-file'];
var config = settings.readFileSync(configFile);
config = settings.readFileSync(configFile);
if (config.version != settings.version) {
config = settings.upgrade(config);
settings.writeFileSync(configFile, config);
@@ -61,8 +62,10 @@ app.on('window-all-closed', function() {
// For win32, auto-hide menu bar.
app.on('browser-window-created', function(event, window) {
if (process.platform === 'win32') {
window.setAutoHideMenuBar(true);
window.setMenuBarVisibility(false);
if (config.hideMenuBar) {
window.setAutoHideMenuBar(true);
window.setMenuBarVisibility(false);
}
}
});