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 Grid = ReactBootstrap.Grid;
const Row = ReactBootstrap.Row; const Row = ReactBootstrap.Row;
const Col = ReactBootstrap.Col; const Col = ReactBootstrap.Col;
const Input = ReactBootstrap.Input;
const Button = ReactBootstrap.Button; const Button = ReactBootstrap.Button;
const ListGroup = ReactBootstrap.ListGroup; const ListGroup = ReactBootstrap.ListGroup;
const ListGroupItem = ReactBootstrap.ListGroupItem; const ListGroupItem = ReactBootstrap.ListGroupItem;
@@ -13,15 +14,11 @@ const Glyphicon = ReactBootstrap.Glyphicon;
var SettingsPage = React.createClass({ var SettingsPage = React.createClass({
getInitialState: function() { getInitialState: function() {
return {
teams: []
};
},
componentDidMount: function() {
var config = settings.readFileSync(this.props.configFile); var config = settings.readFileSync(this.props.configFile);
this.setState({ return {
teams: config.teams teams: config.teams,
}) hideMenuBar: config.hideMenuBar
};
}, },
handleTeamsChange: function(teams) { handleTeamsChange: function(teams) {
this.setState({ this.setState({
@@ -31,23 +28,50 @@ var SettingsPage = React.createClass({
handleSave: function() { handleSave: function() {
var config = { var config = {
teams: this.state.teams, teams: this.state.teams,
version: 1 hideMenuBar: this.refs.hideMenuBar.getChecked(),
version: settings.version
}; };
settings.writeFileSync(this.props.configFile, config); settings.writeFileSync(this.props.configFile, config);
var currentWindow = remote.getCurrentWindow();
currentWindow.setAutoHideMenuBar(config.hideMenuBar);
currentWindow.setMenuBarVisibility(!config.hideMenuBar);
window.location = './index.html'; window.location = './index.html';
}, },
handleCancel: function() { handleCancel: function() {
window.location = './index.html'; window.location = './index.html';
}, },
handleChangeHideMenuBar: function() {
this.setState({
hideMenuBar: this.refs.hideMenuBar.getChecked()
});
},
render: function() { 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 ( return (
<Grid className="settingsPage"> <Grid className="settingsPage">
<Row> { teams_row }
<Col md={ 12 }> { options_row }
<h2>Teams</h2>
<TeamList teams={ this.state.teams } onTeamsChange={ this.handleTeamsChange } />
</Col>
</Row>
<Row> <Row>
<Col md={ 12 }> <Col md={ 12 }>
<Button id="btnCancel" onClick={ this.handleCancel }>Cancel</Button> <Button id="btnCancel" onClick={ this.handleCancel }>Cancel</Button>

View File

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