forked from trazyn/weweChat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
143 lines (118 loc) · 4.07 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import React, { Component } from 'react';
import { render } from 'react-dom';
import { Provider } from 'mobx-react';
import { HashRouter } from 'react-router-dom';
import { ipcRenderer } from 'electron';
import './global.css';
import './assets/fonts/icomoon/style.css';
import 'utils/albumcolors';
import getRoutes from './js/routes';
import stores from './js/stores';
class App extends Component {
async componentWillMount() {
if (window.navigator.onLine) {
await stores.session.hasLogin();
await stores.settings.init();
await stores.search.getHistory();
}
}
canisend() {
return this.refs.navigator.history.location.pathname === '/'
&& stores.chat.user;
}
componentDidMount() {
var navigator = this.refs.navigator;
// Hide the tray icon
ipcRenderer.on('hide-tray', () => {
stores.settings.setShowOnTray(false);
});
// Chat with user
ipcRenderer.on('message-chatto', (event, args) => {
var user = stores.contacts.memberList.find(e => e.UserName === args.id);
navigator.history.push('/');
setTimeout(stores.chat.chatTo(user));
});
// Show the user info
ipcRenderer.on('show-userinfo', (event, args) => {
var user = stores.contacts.memberList.find(e => e.UserName === args.id);
stores.userinfo.toggle(true, user);
});
// Shwo the settings page
ipcRenderer.on('show-settings', () => {
navigator.history.push('/settings');
});
// Show a modal to create a new conversation
ipcRenderer.on('show-newchat', () => {
navigator.history.push('/');
stores.newchat.toggle(true);
});
// Show the conversation pane
ipcRenderer.on('show-conversations', () => {
if (this.canisend()) {
stores.chat.toggleConversation();
}
});
// Search in currently conversation list
ipcRenderer.on('show-search', () => {
navigator.history.push('/');
stores.chat.toggleConversation(true);
setTimeout(() => document.querySelector('#search').focus());
});
// Show the home page
ipcRenderer.on('show-messages', () => {
navigator.history.push('/');
stores.chat.toggleConversation(true);
});
// Batch send message
ipcRenderer.on('show-batchsend', () => {
stores.batchsend.toggle(true);
});
// Insert the qq emoji
ipcRenderer.on('show-emoji', () => {
if (this.canisend()) {
document.querySelector('#showEmoji').click();
}
});
// Show contacts page
ipcRenderer.on('show-contacts', () => {
navigator.history.push('/contacts');
});
// Go to next conversation
ipcRenderer.on('show-next', () => {
navigator.history.push('/');
stores.chat.toggleConversation(true);
setTimeout(stores.chat.chatToNext);
});
// Go to the previous conversation
ipcRenderer.on('show-previous', () => {
navigator.history.push('/');
stores.chat.toggleConversation(true);
setTimeout(stores.chat.chatToPrev);
});
// When the system resume reconnet to WeChat
ipcRenderer.on('os-resume', async() => {
var session = stores.session;
console.log('os-resume' + new Date());
setTimeout(() => {
session.checkTimeout(true);
}, 3000);
});
// Show the daemon error
ipcRenderer.on('show-errors', (event, args) => {
stores.snackbar.showMessage(args.message);
});
}
render() {
return (
<Provider {...stores}>
<HashRouter ref="navigator">
{getRoutes()}
</HashRouter>
</Provider>
);
}
}
render(
<App />,
document.getElementById('root')
);