2017-06-08_509bba0/509bba0_unpacked_with_node_modules/discord_app/components/AppBadge.js
2022-07-26 10:06:20 -07:00

96 lines
2.7 KiB
JavaScript
Executable file

import React from 'react';
import platform from 'platform';
import PureRenderMixin from 'react-addons-pure-render-mixin';
import Flux from '../lib/flux';
import NativeUtils from '../utils/NativeUtils';
import GuildReadStateStore from '../stores/GuildReadStateStore';
import IncomingCallStore from '../stores/IncomingCallStore';
import RelationshipStore from '../stores/RelationshipStore';
import FriendSuggestionStore from '../stores/FriendSuggestionStore';
import NotificationStore from '../stores/NotificationStore';
import Favico from 'favico.js';
const SUPPORTED_LAYOUT_ENGINES = new Set(['Blink', 'Gecko', 'WebKit']);
let setBadge;
if (NativeUtils.embedded) {
setBadge = badge => NativeUtils.setBadge(badge === 0 ? '' : badge.toString());
} else if (SUPPORTED_LAYOUT_ENGINES.has(platform.layout)) {
const favico = new Favico({
animation: 'none',
});
setBadge = badge => {
try {
favico.badge(badge);
} catch (e) {}
};
} else {
// Favico does not work properly on IE based browsers.
// https://sentry.io/discord/discord-web/issues/224657745/
setBadge = _badge => {};
}
const AppBadge = React.createClass({
mixins: [
Flux.StoreListenerMixin(
GuildReadStateStore,
IncomingCallStore,
RelationshipStore,
FriendSuggestionStore,
NotificationStore
),
PureRenderMixin,
],
getStateFromStores() {
return {
mentionCount: GuildReadStateStore.getTotalMentionCount(),
hasUnread: GuildReadStateStore.hasAnyUnread(),
pendingRelationshipCount: RelationshipStore.getPendingCount(),
friendSuggestionCount: FriendSuggestionStore.getSuggestionCount(),
hasIncomingCalls: IncomingCallStore.hasIncomingCalls(),
disableUnreadIndicator: NotificationStore.getDisableUnreadBadge(),
};
},
componentDidMount() {
this.componentDidUpdate();
},
componentDidUpdate() {
let badge = this.state.mentionCount + this.state.pendingRelationshipCount + this.state.friendSuggestionCount;
if (badge === 0 && this.state.hasUnread) {
if (this.state.disableUnreadIndicator) {
badge = '';
} else {
badge = '\u2022'; // http://www.fileformat.info/info/unicode/char/2022/index.htm
}
}
setBadge(badge);
if (this.state.hasIncomingCalls && !this.cancelBounce) {
this.cancelBounce = NativeUtils.bounceDock('critical');
} else if (!this.state.hasIncomingCalls && this.cancelBounce) {
this.cancelBounce();
this.cancelBounce = null;
}
},
componentWillUnmount() {
setBadge(0);
if (this.cancelBounce) {
this.cancelBounce();
this.cancelBounce = null;
}
},
render() {
return null;
},
});
export default AppBadge;
// WEBPACK FOOTER //
// ./discord_app/components/AppBadge.js