2
2
* @file app
3
3
*/
4
4
import path from 'path' ;
5
- import { app , BrowserWindow } from 'electron' ;
6
- import logoIcon from '../assets/png/logo.svg' ;
7
- import pkg from '../package.json' ;
8
- import { DEVELOP_PORT } from '../../shared/common/constant' ;
5
+ import { app , BrowserWindow , ipcMain , Menu } from 'electron' ;
6
+ import { DEVELOP_PORT } from 'shared/common/constant' ;
9
7
10
8
import { registerContextMenuListener } from './contextmenu/electron-main/contextmenu' ;
11
- import { Menubar } from './menu/menubar ' ;
9
+ import { CodeMain } from './editor/editorMain ' ;
12
10
13
- import { Injector } from 'core/base/dependency-inject' ;
14
- import CodeApplication from './initService' ;
15
- import { IFileService } from 'services/files/files' ;
16
- import { FileService } from 'services/files/fileService' ;
17
- import { IDialogService , DialogService } from 'services/dialog/dialog' ;
18
- import { INativeService , NativeService } from 'services/native/native' ;
19
- import { ICommandService , CommandService } from 'services/command' ;
20
-
21
- // single service
22
- import 'services/search/electron-browser/searchServices' ;
11
+ /// #if IS_DEV
12
+ import installExtension , { REACT_DEVELOPER_TOOLS } from 'electron-devtools-installer' ;
13
+ /// #endif
23
14
24
15
let splashWindow : BrowserWindow | null = null ;
25
16
26
17
const MODE = process . env . NODE_ENV === 'production' ;
27
18
28
- // eslint-disable-next-line
29
- function createSplashWindow ( ) {
30
- return new Promise ( resolve => {
31
- const html = `
32
- <!DOCTYPE html>
33
- <html>
34
- <head>
35
- <meta charset="utf-8">
36
- <style>
37
- html {
38
- background-color: rgb(24,24,24,0.9);
39
- }
40
- body,
41
- html {
42
- width: 100%;
43
- height: 100%;
44
- margin: 0;
45
- overflow: hidden;
46
- position: relative;
47
- background-repeat: no-repeat;
48
- -webkit-user-select: none;
49
- }
50
- .logo {
51
- width: 90px;
52
- height: 90px;
53
- margin-right: 20px;
54
- }
55
- h1 {
56
- margin: 0;
57
- padding: 0;
58
- line-height: 48px;
59
- font-size: 48px;
60
- text-align: center;
61
- color: #f1f1f1;
62
- }
63
- .top {
64
- display: flex;
65
- align-items: center;
66
- justify-content: center;
67
- margin-top: 150px;
68
- }
69
- .version {
70
- margin-top: 50px;
71
- text-align: center;
72
- font-weight: bold;
73
- color: #ddd;
74
- }
75
- .tip {
76
- position: absolute;
77
- right: 20px;
78
- bottom: 20px;
79
- margin: 0;
80
- color: #999;
81
- }
82
- .animate__rubberBand {
83
- -webkit-animation-name: rubberBand;
84
- animation-name: rubberBand;
85
- }
86
- .animate__animated {
87
- -webkit-animation-duration: 1s;
88
- animation-duration: 1s;
89
- -webkit-animation-duration: var(--animate-duration);
90
- animation-duration: var(--animate-duration);
91
- -webkit-animation-fill-mode: both;
92
- animation-fill-mode: both;
93
- animation-delay: 150ms;
94
- }
95
- :root {
96
- --animate-duration: 1s;
97
- --animate-delay: 1s;
98
- --animate-repeat: 1;
99
- }
100
- @keyframes rubberBand {
101
- from {
102
- -webkit-transform: scale3d(1, 1, 1);
103
- transform: scale3d(1, 1, 1);
104
- }
105
-
106
- 30% {
107
- -webkit-transform: scale3d(1.25, 0.75, 1);
108
- transform: scale3d(1.25, 0.75, 1);
109
- }
110
-
111
- 40% {
112
- -webkit-transform: scale3d(0.75, 1.25, 1);
113
- transform: scale3d(0.75, 1.25, 1);
114
- }
115
-
116
- 50% {
117
- -webkit-transform: scale3d(1.15, 0.85, 1);
118
- transform: scale3d(1.15, 0.85, 1);
119
- }
120
-
121
- 65% {
122
- -webkit-transform: scale3d(0.95, 1.05, 1);
123
- transform: scale3d(0.95, 1.05, 1);
124
- }
125
-
126
- 75% {
127
- -webkit-transform: scale3d(1.05, 0.95, 1);
128
- transform: scale3d(1.05, 0.95, 1);
129
- }
130
-
131
- to {
132
- -webkit-transform: scale3d(1, 1, 1);
133
- transform: scale3d(1, 1, 1);
134
- }
135
- }
136
- </style>
137
- </head>
138
- <body>
139
- <div class="top">
140
- <img class="logo" src="${ logoIcon } "/>
141
- <h1 id="name" class="animate__rubberBand animate__animated">${ pkg . productName } </h1>
142
- </div>
143
- <p class="version">Version ${ pkg . version } </p>
144
- </body>
145
- </html>
146
- ` ;
147
- splashWindow = new BrowserWindow ( {
148
- width : 600 ,
149
- height : 400 ,
150
- show : false ,
151
- frame : false ,
152
- movable : true ,
153
- resizable : false ,
154
- autoHideMenuBar : true ,
155
- transparent : true
156
- } ) ;
157
- splashWindow
158
- . loadURL ( 'data:text/html;charset=UTF-8,' + encodeURIComponent ( html ) )
159
- . then ( ( ) => splashWindow ?. show ( ) ) ;
160
- splashWindow . webContents . on ( 'did-finish-load' , ( ) => {
161
- setTimeout ( ( ) => {
162
- resolve ( '' ) ;
163
- } , 1500 ) ;
164
- } ) ;
165
- } ) ;
166
- }
167
-
168
- function createWindow ( ) {
19
+ function createHome ( ) {
169
20
const html = MODE
170
- ? `file://${ path . resolve ( app . getAppPath ( ) , './dist/index .html' ) } `
171
- : `http://localhost:${ DEVELOP_PORT } /index .html` ;
21
+ ? `file://${ path . resolve ( app . getAppPath ( ) , './dist/home .html' ) } `
22
+ : `http://localhost:${ DEVELOP_PORT } /home .html` ;
172
23
const preload = MODE
173
24
? path . resolve ( app . getAppPath ( ) , './dist/preload.js' )
174
25
: path . resolve ( app . getAppPath ( ) , './preload.js' ) ;
175
26
const win = new BrowserWindow ( {
176
27
minWidth : 800 ,
177
28
minHeight : 600 ,
178
- width : 1350 ,
179
- height : 900 ,
29
+ width : 800 ,
30
+ height : 600 ,
180
31
title : '' ,
181
- backgroundColor : '#262626 ' ,
182
- // titleBarStyle: 'hidden',
183
- // trafficLightPosition: {
184
- // x: 0,
185
- // y: 0
186
- // },
32
+ backgroundColor : '#131419 ' ,
33
+ titleBarStyle : 'hidden' ,
34
+ trafficLightPosition : {
35
+ x : 0 ,
36
+ y : 0
37
+ } ,
187
38
webPreferences : {
188
39
preload,
189
40
nodeIntegration : true ,
@@ -198,21 +49,22 @@ function createWindow() {
198
49
} ) ;
199
50
}
200
51
201
- class CodeMain {
202
- constructor ( ) {
52
+ class Home {
53
+ constructor ( ) {
54
+ Menu . setApplicationMenu ( new Menu ( ) ) ;
203
55
this . registerListeners ( ) ;
204
56
}
205
- async startUp ( ) : Promise < void > {
206
- this . initServices ( ) ;
207
- }
208
- private registerListeners ( ) {
57
+ private registerListeners ( ) {
209
58
process . on ( 'uncaughtException' , err => this . onUnexpectedError ( err ) ) ;
210
- // TODO: 如何处理promise的错误
211
- // process.on('unhandledRejection', (reason: unknown) => onUnexpectedError(reason));
212
-
213
59
app . whenReady ( ) . then ( async ( ) => {
60
+ /// #if IS_DEV
61
+ installExtension ( REACT_DEVELOPER_TOOLS )
62
+ . then ( name => console . log ( `Added Extension: ${ name } ` ) )
63
+ . catch ( err => console . log ( 'An error occurred: ' , err ) ) ;
64
+ /// #endif
65
+
214
66
// await createSplashWindow();
215
- await createWindow ( ) ;
67
+ await createHome ( ) ;
216
68
registerContextMenuListener ( ) ;
217
69
} ) ;
218
70
@@ -224,10 +76,11 @@ class CodeMain {
224
76
225
77
app . on ( 'activate' , ( ) => {
226
78
if ( BrowserWindow . getAllWindows ( ) . length === 0 ) {
227
- createWindow ( ) ;
79
+ createHome ( ) ;
228
80
}
229
81
} ) ;
230
82
}
83
+
231
84
private onUnexpectedError ( err : Error ) : void {
232
85
if ( err ) {
233
86
// take only the message and stack property
@@ -243,29 +96,14 @@ class CodeMain {
243
96
// TODO: logService
244
97
}
245
98
246
- private initServices ( ) {
247
- const injector = new Injector ( ) ;
248
-
249
- injector . add ( IFileService , {
250
- useClass : FileService
99
+ startUp ( ) {
100
+ ipcMain . handle ( 'pandora:mdEditor' , async ( event , dirPath ) => {
101
+ const codeMain = new CodeMain ( ) ;
102
+ codeMain . startUp ( ) ;
103
+ return ;
251
104
} ) ;
252
-
253
- injector . add ( IDialogService , {
254
- useClass : DialogService
255
- } ) ;
256
-
257
- injector . add ( INativeService , {
258
- useClass : NativeService
259
- } ) ;
260
-
261
- injector . add ( ICommandService , {
262
- useClass : CommandService
263
- } ) ;
264
-
265
- injector . createInstance ( CodeApplication ) ;
266
- injector . createInstance ( Menubar ) ;
267
105
}
268
106
}
269
107
270
- const main = new CodeMain ( ) ;
271
- main . startUp ( ) ;
108
+ const home = new Home ( ) ;
109
+ home . startUp ( ) ;
0 commit comments