1
1
'use strict'
2
2
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'
6
7
7
8
/**
8
9
* Set `__static` path to static files in production
@@ -13,85 +14,14 @@ if (process.env.NODE_ENV !== 'development') {
13
14
}
14
15
15
16
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 = [ ]
28
18
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)
92
22
}
93
23
94
- app . on ( 'ready' , createWindow )
24
+ app . on ( 'ready' , init )
95
25
96
26
app . on ( 'window-all-closed' , ( ) => {
97
27
if ( process . platform !== 'darwin' ) {
@@ -101,114 +31,28 @@ app.on('window-all-closed', () => {
101
31
102
32
app . on ( 'activate' , ( ) => {
103
33
if ( mainWindow === null ) {
104
- createWindow ( )
34
+ init ( )
105
35
}
106
36
} )
107
37
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
+ // 显示窗口
117
39
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 )
169
42
}
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 )
199
45
}
200
46
} )
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 ] ;
212
52
}
53
+ downloadItems . push ( item )
213
54
}
214
- } )
55
+ if ( item . type === 'remove' ) {
56
+ downloadItems = [ ]
57
+ }
58
+ }
0 commit comments