Skip to content

Commit f09908a

Browse files
authored
Merge pull request #17 from misterpancn/feature-develop-buck
Release v1.1.1
2 parents 78caf3a + fe734f2 commit f09908a

27 files changed

+822
-321
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "VueChat",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"author": "[email protected]",
55
"description": "An electron-vue project",
66
"private": true,

src/main/index.js

Lines changed: 25 additions & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
'use strict'
22

3-
import { app, BrowserWindow, ipcMain, dialog } from 'electron'
4-
import { autoUpdater } from 'electron-updater'
5-
import config from '../renderer/store/config/config'
3+
import { app, ipcMain } from 'electron'
4+
import mainWin from '../renderer/lib/window/mainWindow'
5+
import chatImgWin from '../renderer/lib/window/chatImgWindow'
6+
import chatVideoWin from '../renderer/lib/window/chatVideoWindow'
67

78
/**
89
* Set `__static` path to static files in production
@@ -13,85 +14,14 @@ if (process.env.NODE_ENV !== 'development') {
1314
}
1415

1516
let mainWindow
16-
let exit = false
17-
let winModal
18-
let videoModal
19-
const winURL = process.env.NODE_ENV === 'development'
20-
? `http://localhost:9080`
21-
: `file://${__dirname}/index.html`
22-
const winModalURL = process.env.NODE_ENV === 'development'
23-
? `http://localhost:9080/#/modelWindow`
24-
: `file://${__dirname}/index.html#modelWindow`
25-
const videoModalURl = process.env.NODE_ENV === 'development'
26-
? `http://localhost:9080/#/videoModal`
27-
: `file://${__dirname}/index.html#videoModal`
17+
let downloadItems = []
2818

29-
function createWindow () {
30-
/**
31-
* Initial window options
32-
*/
33-
mainWindow = new BrowserWindow({
34-
height: config.windowSize.login.height,
35-
// useContentSize: true,
36-
width: config.windowSize.login.width,
37-
show: false
38-
})
39-
40-
mainWindow.loadURL(winURL)
41-
42-
mainWindow.on('closed', () => {
43-
mainWindow = null
44-
exit = false
45-
})
46-
mainWindow.on('focus', () => mainWindow.flashFrame(false))
47-
mainWindow.once('ready-to-show', () => {
48-
mainWindow.show()
49-
})
50-
winModal = new BrowserWindow({
51-
parent: mainWindow,
52-
modal: true,
53-
useContentSize: true,
54-
frame: false,
55-
show: false
56-
})
57-
winModal.loadURL(winModalURL)
58-
winModal.on('closed', () => {
59-
winModal = null
60-
})
61-
mainWindow.on('close', (e) => {
62-
if (!exit && isShowExitNotify()) {
63-
e.preventDefault()
64-
dialog.showMessageBox(mainWindow, {
65-
type: 'warning',
66-
title: 'info tips',
67-
message: 'Do you want to close the application?',
68-
buttons: ['Cancel', 'Ok']
69-
}, (idx) => {
70-
if (idx === 0) {
71-
e.preventDefault()
72-
} else {
73-
mainWindow.webContents.send('close-window')
74-
exit = true
75-
app.quit()
76-
}
77-
})
78-
}
79-
})
80-
const { session } = require('electron')
81-
82-
session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
83-
let c = {
84-
responseHeaders: {
85-
...details.responseHeaders,
86-
'Content-Security-Policy': config.contentSecurityPolicy ? config.contentSecurityPolicy : ['default-src \'self\' \'unsafe-inline\' \'unsafe-eval\' data:']
87-
}
88-
}
89-
callback(c)
90-
})
91-
handleUpdate()
19+
function init () {
20+
mainWindow = mainWin(downloadItem)
21+
// chatImgWin(mainWindow)
9222
}
9323

94-
app.on('ready', createWindow)
24+
app.on('ready', init)
9525

9626
app.on('window-all-closed', () => {
9727
if (process.platform !== 'darwin') {
@@ -101,114 +31,28 @@ app.on('window-all-closed', () => {
10131

10232
app.on('activate', () => {
10333
if (mainWindow === null) {
104-
createWindow()
34+
init()
10535
}
10636
})
10737

108-
ipcMain.on('change-win-size', (e, args) => {
109-
mainWindow.setSize(args.width, args.height)
110-
mainWindow.center()
111-
})
112-
ipcMain.on('show-win-notify', (e, args) => {
113-
if (!mainWindow.isFocused()) {
114-
mainWindow.flashFrame(args.show)
115-
}
116-
})
38+
// 显示窗口
11739
ipcMain.on('show-win-model', (e, args) => {
118-
winModal.setSize(args.width, args.height)
119-
winModal.show()
120-
winModal.center()
121-
winModal.webContents.send('send-win-modal-img', args.src)
122-
})
123-
ipcMain.on('hide-win-modal', (e, args) => {
124-
winModal.hide()
125-
})
126-
127-
/**
128-
* Auto Updater
129-
*
130-
* Uncomment the following code below and install `electron-updater` to
131-
* support auto updating. Code Signing with a valid certificate is required.
132-
* https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-electron-builder.html#auto-updating
133-
*/
134-
135-
function handleUpdate () {
136-
autoUpdater.autoDownload = false
137-
autoUpdater.autoInstallOnAppQuit = false
138-
autoUpdater.setFeedURL(config.downloadAddress);
139-
autoUpdater.on('error', (err) => {
140-
if (mainWindow) mainWindow.webContents.send('update-error', String(err))
141-
})
142-
autoUpdater.on('update-available', (info) => {
143-
if (mainWindow) mainWindow.webContents.send('update-available', info)
144-
})
145-
autoUpdater.on('update-not-available', (info) => {
146-
if (mainWindow) mainWindow.webContents.send('update-not-available', info)
147-
})
148-
autoUpdater.on('download-progress', (progress) => {
149-
if (mainWindow) mainWindow.webContents.send('update-download-progress', progress)
150-
})
151-
autoUpdater.on('update-downloaded', (info) => {
152-
if (mainWindow) mainWindow.webContents.send('update-downloaded', info)
153-
})
154-
ipcMain.on('check-for-update', () => {
155-
autoUpdater.checkForUpdates()
156-
})
157-
ipcMain.on('update-download', () => {
158-
autoUpdater.downloadUpdate()
159-
})
160-
ipcMain.on('update-install', () => {
161-
autoUpdater.quitAndInstall()
162-
})
163-
}
164-
165-
function isShowExitNotify () {
166-
let size = mainWindow.getSize();
167-
if (size[0] === config.windowSize.login.width && size[1] === config.windowSize.login.height) {
168-
return false;
40+
if (args.type === 'video') {
41+
chatVideoWin(mainWindow, args)
16942
}
170-
if (size[0] === config.windowSize.register.width && size[1] === config.windowSize.register.height) {
171-
return false;
172-
}
173-
return true;
174-
}
175-
176-
function createVideoModal (data) {
177-
videoModal = new BrowserWindow({
178-
parent: mainWindow,
179-
modal: true,
180-
useContentSize: true,
181-
frame: false,
182-
show: false
183-
})
184-
videoModal.loadURL(videoModalURl)
185-
videoModal.on('closed', () => {
186-
videoModal = null
187-
})
188-
videoModal.once('ready-to-show', () => {
189-
videoModal.show()
190-
videoModal.webContents.send('video-modal-data', data)
191-
})
192-
}
193-
ipcMain.on('show-video-modal', (e, data) => {
194-
createVideoModal(data)
195-
})
196-
ipcMain.on('close-video-modal', () => {
197-
if (videoModal) {
198-
videoModal.close()
43+
if (args.type === 'img') {
44+
chatImgWin(mainWindow, args)
19945
}
20046
})
201-
ipcMain.on('forwarded-message-to-video', (e, data) => {
202-
if (videoModal) {
203-
videoModal.webContents.send('forwarded-message-to-video', data)
204-
}
205-
})
206-
ipcMain.on('video-modal-full-screen', () => {
207-
if (videoModal) {
208-
if (videoModal.isMaximized()) {
209-
videoModal.unmaximize()
210-
} else {
211-
videoModal.maximize()
47+
48+
function downloadItem (item) {
49+
if (item.type === 'add') {
50+
if (item.downloadUrl.indexOf('?') !== -1) {
51+
item.downloadUrl = item.downloadUrl.split('?')[0];
21252
}
53+
downloadItems.push(item)
21354
}
214-
})
55+
if (item.type === 'remove') {
56+
downloadItems = []
57+
}
58+
}

src/renderer/App.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
body {
2727
color: #4d4d4d;
2828
font: 14px/1.4em 'Helvetica Neue', Helvetica, 'Microsoft Yahei', Arial, sans-serif;
29-
background: #f5f5f5 url('./../../static/img/bg.jpg') no-repeat center;
30-
background-size: cover;
3129
font-smoothing: antialiased;
3230
}
3331
ul {

src/renderer/components/AppMenu.vue

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<style lang="less">
2+
.app-menu {
3+
width: 100%;
4+
height: 30px;
5+
line-height: 30px;
6+
text-align: center;
7+
font-size: 1.3em;
8+
-webkit-app-region: drag;
9+
border-bottom: solid 1px #e3e5e8;
10+
.app-menu-button {
11+
cursor: pointer;
12+
padding: 0 6px;
13+
display: inline-block;
14+
}
15+
.default-menu-bg:hover {
16+
background-color: #c5c8ce;
17+
}
18+
.error-menu-bg:hover {
19+
background-color: #dc6666;
20+
}
21+
}
22+
</style>
23+
<template>
24+
<div class="app-menu">
25+
<div style="float: left" v-if="showLogo">
26+
<img src="./../../../static/img/favicon.png" style="-webkit-app-region: no-drag;margin: 5px 0 0 10px;" width="20" height="20" />
27+
</div>
28+
<span v-if="selectUser" style="-webkit-app-region: no-drag;">{{ selectUser }}</span>
29+
<div style="float: right;-webkit-app-region: no-drag;">
30+
<span class="app-menu-button default-menu-bg" v-if="selectId" @click="show"><Icon type="md-menu" size="18" /></span>
31+
<span class="app-menu-button default-menu-bg" @click="minimize"><Icon type="md-remove" size="18" /></span>
32+
<span class="app-menu-button default-menu-bg" @click="screenCtrl"><Icon :type="screenIcon" size="18" /></span>
33+
<span class="app-menu-button error-menu-bg" @click="appExit"><Icon type="md-close" size="18" /></span>
34+
</div>
35+
<group-user v-if="selectUser"></group-user>
36+
<userInfoModal v-bind:isGroup="isGroup" v-if="selectUser"></userInfoModal>
37+
</div>
38+
</template>
39+
<script>
40+
import groupUser from '@/components/Chat/Modal/groupUser'
41+
import userInfoModal from '@/components/Chat/Modal/userInformation'
42+
import {ipcRenderer} from 'electron'
43+
export default {
44+
props: [ 'showLogo' ],
45+
data () {
46+
return {
47+
screenIcon: 'md-expand'
48+
}
49+
},
50+
components: { groupUser, userInfoModal },
51+
computed: {
52+
selectUser () {
53+
// let info = chat.getUserInfo(this.selectUserId, this.userList, this.groupList)
54+
let info = this.$store.getters.getSelectUser(this.selectId, this.isGroup)
55+
return info.name === undefined ? (info.group_name === undefined ? '' : info.group_name) : info.name
56+
},
57+
selectId () {
58+
return this.$store.getters.selectId
59+
},
60+
isGroup () {
61+
return this.$store.getters.isGroup
62+
}
63+
},
64+
filters: {
65+
selection (list, sear) {
66+
return list.filter(item => item.name.indexOf(sear) > -1)
67+
}
68+
},
69+
methods: {
70+
screenCtrl () {
71+
if (this.screenIcon === 'md-expand') {
72+
this.screenIcon = 'md-contract'
73+
ipcRenderer.send('winMaximize')
74+
} else {
75+
ipcRenderer.send('winUnMaximize')
76+
this.screenIcon = 'md-expand'
77+
}
78+
},
79+
appExit () {
80+
this.$Modal.confirm({
81+
title: 'Do you want to close the application?',
82+
loading: true,
83+
onOk: () => {
84+
ipcRenderer.send('exit')
85+
}
86+
})
87+
},
88+
minimize () {
89+
ipcRenderer.send('winMinimize')
90+
},
91+
show () {
92+
if (this.selectUser && this.isGroup) {
93+
this.$store.dispatch('setGroupUserShow', true)
94+
} else if (this.selectId && !this.isGroup) {
95+
this.$store.dispatch('upUserInfoShow', true)
96+
this.$store.dispatch('setUserInfo', this.selectId).catch((e) => {
97+
this.$Message.warning({
98+
content: this.$t('notifyTitle.errorOccurred'),
99+
duration: 3
100+
});
101+
this.$store.dispatch('upUserInfoShow', false)
102+
})
103+
}
104+
}
105+
}
106+
}
107+
</script>

src/renderer/components/Chat/Modal/modifyAvatar.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
handleMaxSize (file) {
5050
this.$Notice.warning({
5151
title: this.$t('notifyTitle.exceedingFileSizeLimit'),
52-
desc: this.$t('notify.imgFileFormatIsIncorrectMes', {fileName: file.name, size: '2M'})
52+
desc: this.$t('notify.exceedingImageFileSizeLimitMes', {fileName: file.name, size: '2M'})
5353
});
5454
},
5555
cancel () {

0 commit comments

Comments
 (0)