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