Merge branch 'master' of https://github.com/yuya-oc/electron-mattermost into topic-active-channel-badge

This commit is contained in:
mid0111
2016-01-19 12:36:33 +09:00
9 changed files with 188 additions and 59 deletions

View File

@@ -17,6 +17,8 @@ const path = require('path');
const settings = require('../common/settings');
remote.getCurrentWindow().removeAllListeners('focus');
var MainPage = React.createClass({
getInitialState: function() {
return {
@@ -24,6 +26,19 @@ var MainPage = React.createClass({
unreadCounts: new Array(this.props.teams.length)
};
},
componentDidMount: function() {
var thisObj = this;
var focusListener = function() {
var webview = document.getElementById('mattermostView' + thisObj.state.key);
webview.focus();
};
var currentWindow = remote.getCurrentWindow();
currentWindow.on('focus', focusListener);
window.addEventListener('beforeunload', function() {
currentWindow.removeListener('focus', focusListener);
});
},
handleSelect: function(key) {
this.setState({
key: key
@@ -46,7 +61,7 @@ var MainPage = React.createClass({
var visibility = visible ? 'visible' : 'hidden';
return {
position: 'absolute',
top: 42,
top: (this.props.teams.length > 1) ? 42 : 0,
right: 0,
bottom: 0,
left: 0,
@@ -55,19 +70,16 @@ var MainPage = React.createClass({
},
render: function() {
var thisObj = this;
var tabs = this.props.teams.map(function(team, index) {
var badge;
if (thisObj.state.unreadCounts[index] != 0) {
badge = (<Badge>
{ thisObj.state.unreadCounts[index] }
</Badge>);
}
return (<NavItem className="teamTabItem" id={ 'teamTabItem' + index } eventKey={ index }>
{ team.name }
{ ' ' }
{ badge }
</NavItem>);
});
var tabs_row;
if (this.props.teams.length > 1) {
tabs_row = (
<Row>
<TabBar id="tabBar" teams={ this.props.teams } unreadCounts={ this.state.unreadCounts } activeKey={ this.state.key } onSelect={ this.handleSelect }></TabBar>
</Row>
);
}
var views = this.props.teams.map(function(team, index) {
var handleUnreadCountChange = function(count) {
thisObj.handleUnreadCountChange(index, count);
@@ -78,21 +90,41 @@ var MainPage = React.createClass({
return (<MattermostView id={ 'mattermostView' + index } style={ thisObj.visibleStyle(thisObj.state.key === index) } src={ team.url } onUnreadCountChange={ handleUnreadCountChange } onNotificationClick={ handleNotificationClick }
/>)
});
var views_row = (<Row>
{ views }
</Row>);
return (
<Grid fluid>
<Row>
<Nav bsStyle="tabs" activeKey={ this.state.key } onSelect={ this.handleSelect }>
{ tabs }
</Nav>
</Row>
<Row>
{ views }
</Row>
{ tabs_row }
{ views_row }
</Grid>
);
}
});
var TabBar = React.createClass({
render: function() {
var thisObj = this;
var tabs = this.props.teams.map(function(team, index) {
var badge;
if (thisObj.props.unreadCounts[index] != 0) {
badge = (<Badge>
{ thisObj.props.unreadCounts[index] }
</Badge>);
}
return (<NavItem className="teamTabItem" id={ 'teamTabItem' + index } eventKey={ index }>
{ team.name }
{ ' ' }
{ badge }
</NavItem>);
});
return (
<Nav id={ this.props.id } bsStyle="tabs" activeKey={ this.props.activeKey } onSelect={ this.props.onSelect }>
{ tabs }
</Nav>
);
}
});
var MattermostView = React.createClass({
getInitialState: function() {
@@ -178,6 +210,9 @@ try {
} catch (e) {
window.location = 'settings.html';
}
if (config.teams.length === 0) {
window.location = 'settings.html';
}
var contextMenu = require('./menus/context');
var menu = contextMenu.createDefault();

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,16 +14,17 @@ const Glyphicon = ReactBootstrap.Glyphicon;
var SettingsPage = React.createClass({
getInitialState: function() {
var config;
try {
config = settings.readFileSync(this.props.configFile);
} catch (e) {
config = settings.loadDefault();
}
return {
teams: []
teams: config.teams,
hideMenuBar: config.hideMenuBar
};
},
componentDidMount: function() {
var config = settings.readFileSync(this.props.configFile);
this.setState({
teams: config.teams
})
},
handleTeamsChange: function(teams) {
this.setState({
teams: teams
@@ -31,28 +33,57 @@ var SettingsPage = React.createClass({
handleSave: function() {
var config = {
teams: this.state.teams,
version: 1
hideMenuBar: this.state.hideMenuBar,
version: settings.version
};
settings.writeFileSync(this.props.configFile, config);
if (process.platform === 'win32') {
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>
{ ' ' }
<Button id="btnSave" bsStyle="primary" onClick={ this.handleSave }>Save</Button>
<Button id="btnSave" bsStyle="primary" onClick={ this.handleSave } disabled={ this.state.teams.length === 0 }>Save</Button>
</Col>
</Row>
</Grid>