Skip to content

Commit

Permalink
add badge support
Browse files Browse the repository at this point in the history
  • Loading branch information
imndx committed Sep 26, 2020
1 parent 5f8b008 commit e5eee02
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 34 deletions.
5 changes: 5 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import i18n from 'i18n';
import proto from './marswrapper.node';

import pkg from './package.json';
import Badge from 'electron-windows-badge';


let Locales = {};
i18n.configure({
Expand Down Expand Up @@ -557,6 +559,8 @@ const createMainWindow = () => {
frame: !isWin,
icon
});
const badgeOptions = {}
new Badge(mainWindow, badgeOptions);

mainWindow.setSize(400, 480);
mainWindow.loadURL(
Expand Down Expand Up @@ -765,6 +769,7 @@ const createMainWindow = () => {
var counter = args.counter;
//if (settings.showOnTray) {
updateTray(counter);
app.setBadgeCount(counter);
//}
});

Expand Down
63 changes: 40 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
"electron-json-storage": "^4.0.2",
"electron-screenshots": "0.0.10",
"electron-window-state": "^4.1.1",
"electron-windows-badge": "^1.1.0",
"emoji-mart": "^2.11.1",
"file-saver": "^2.0.2",
"han": "^0.0.7",
Expand Down
4 changes: 2 additions & 2 deletions src/js/ui/pages/Footer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default class Footer extends Component {

return (
<footer className={clazz(classes.footer,{
[classes.winrleft]:this.props.isMac(),
[classes.winrleft]:this.props.isWin(),
})}>
<div className={classes.user} onClick= {()=>this.showUserCard()}>
<img src={user.portrait}/>
Expand Down Expand Up @@ -114,7 +114,7 @@ export default class Footer extends Component {

<div className={clazz(classes.right, {
[classes.hideConversation]: !showConversation,
[classes.winright]:this.props.isMac()
[classes.winright]:this.props.isWin()
})}>
{
component ? React.createElement(component) : ""
Expand Down
22 changes: 13 additions & 9 deletions src/js/ui/pages/Layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,16 @@ export default class Layout extends Component {
});
stores.sessions.setUnreadMessageCount(counter)
if (ipcRenderer) {
ipcRenderer.send(
'message-unread',
{
counter,
}
);
if(this.isWin()){
ipcRenderer.sendSync('update-badge', counter > 0 ? counter : null);
}else {
ipcRenderer.send(
'message-unread',
{
counter,
}
);
}
} else {
document.title = counter === 0 ? "野火IM" : (`野火IM(有${counter}条未读消息)`);
}
Expand Down Expand Up @@ -235,7 +239,7 @@ export default class Layout extends Component {
wfc.eventEmitter.removeListener(EventType.ConversationInfoUpdate, this.updateUnreadStatus);
wfc.eventEmitter.removeListener(EventType.SettingUpdate, this.updateUnreadStatus);
}
isMac(){
isWin(){
// var agent = navigator.userAgent.toLowerCase();
// var isMac = /macintosh|mac os x/i.test(navigator.userAgent);
// if(isMac){
Expand Down Expand Up @@ -270,15 +274,15 @@ export default class Layout extends Component {
<Loader show={loading} />
<div
className={clazz(classes.container,{
[classes.winContainer]:this.isMac()
[classes.winContainer]:this.isWin()
})}
ref="viewport">
{this.props.children}
</div>
<Footer
className={classes.footer}
location={location}
isMac={this.isMac}
isWin={this.isWin}
ref="footer" />
<UserInfo />
<AddFriend />
Expand Down

0 comments on commit e5eee02

Please sign in to comment.