Persist new Teams
This commit is contained in:
@@ -38,7 +38,8 @@ const MainPage = React.createClass({
|
||||
propTypes: {
|
||||
disablewebsecurity: React.PropTypes.bool.isRequired,
|
||||
onUnreadCountChange: React.PropTypes.func.isRequired,
|
||||
teams: React.PropTypes.array.isRequired
|
||||
teams: React.PropTypes.array.isRequired,
|
||||
onTeamConfigChange: React.PropTypes.func.isRequired
|
||||
},
|
||||
|
||||
getInitialState() {
|
||||
@@ -319,6 +320,7 @@ const MainPage = React.createClass({
|
||||
});
|
||||
this.props.teams.push(newTeam);
|
||||
this.render();
|
||||
this.props.onTeamConfigChange(this.props.teams);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
|
@@ -1,12 +1,22 @@
|
||||
const settings = require('../../common/settings');
|
||||
const {remote} = require('electron');
|
||||
|
||||
var config;
|
||||
try {
|
||||
const configFile = remote.app.getPath('userData') + '/config.json';
|
||||
config = settings.readFileSync(configFile);
|
||||
} catch (e) {
|
||||
config = {};
|
||||
class AppConfig {
|
||||
constructor(file) {
|
||||
this.fileName = file;
|
||||
try {
|
||||
this.data = settings.readFileSync(file);
|
||||
} catch (e) {
|
||||
this.data = {
|
||||
teams: []
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
set(key, value) {
|
||||
this.data[key] = value;
|
||||
settings.writeFileSync(this.fileName, this.data);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = config;
|
||||
module.exports = new AppConfig(remote.app.getPath('userData') + '/config.json');
|
||||
|
@@ -14,7 +14,7 @@ const badge = require('./js/badge');
|
||||
|
||||
remote.getCurrentWindow().removeAllListeners('focus');
|
||||
|
||||
if (AppConfig.teams.length === 0) {
|
||||
if (AppConfig.data.teams.length === 0) {
|
||||
window.location = 'settings.html';
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ function showUnreadBadgeWindows(unreadCount, mentionCount) {
|
||||
if (mentionCount > 0) {
|
||||
const dataURL = badge.createDataURL(mentionCount.toString());
|
||||
sendBadge(dataURL, 'You have unread mentions (' + mentionCount + ')');
|
||||
} else if (unreadCount > 0 && config.showUnreadBadge) {
|
||||
} else if (unreadCount > 0 && AppConfig.data.showUnreadBadge) {
|
||||
const dataURL = badge.createDataURL('•');
|
||||
sendBadge(dataURL, 'You have unread channels (' + unreadCount + ')');
|
||||
} else {
|
||||
@@ -44,7 +44,7 @@ function showUnreadBadgeWindows(unreadCount, mentionCount) {
|
||||
function showUnreadBadgeOSX(unreadCount, mentionCount) {
|
||||
if (mentionCount > 0) {
|
||||
remote.app.dock.setBadge(mentionCount.toString());
|
||||
} else if (unreadCount > 0 && config.showUnreadBadge) {
|
||||
} else if (unreadCount > 0 && AppConfig.data.showUnreadBadge) {
|
||||
remote.app.dock.setBadge('•');
|
||||
} else {
|
||||
remote.app.dock.setBadge('');
|
||||
@@ -82,11 +82,16 @@ function showUnreadBadge(unreadCount, mentionCount) {
|
||||
}
|
||||
}
|
||||
|
||||
function teamConfigChange(teams) {
|
||||
AppConfig.set('teams', teams);
|
||||
}
|
||||
|
||||
ReactDOM.render(
|
||||
<MainPage
|
||||
disablewebsecurity={config.disablewebsecurity}
|
||||
teams={config.teams}
|
||||
disablewebsecurity={AppConfig.data.disablewebsecurity}
|
||||
teams={AppConfig.data.teams}
|
||||
onUnreadCountChange={showUnreadBadge}
|
||||
onTeamConfigChange={teamConfigChange}
|
||||
/>,
|
||||
document.getElementById('content')
|
||||
);
|
||||
|
Reference in New Issue
Block a user