1
- import { app , BrowserWindow , Tray , Menu , NativeImage , nativeImage , Notification } from 'electron' ;
1
+ import {
2
+ app ,
3
+ BrowserWindow ,
4
+ Tray ,
5
+ Menu ,
6
+ NativeImage ,
7
+ nativeImage ,
8
+ Notification ,
9
+ } from 'electron' ;
2
10
import * as path from 'path' ;
3
- import rpc from " ./lib/rpc" ;
11
+ import rpc from ' ./lib/rpc' ;
4
12
5
- import socket from " ./lib/socket" ;
13
+ import socket from ' ./lib/socket' ;
6
14
7
15
const WebSocket = socket ( ) ;
8
16
9
17
// Handle creating/removing shortcuts on Windows when installing/uninstalling.
10
18
if ( require ( 'electron-squirrel-startup' ) ) {
11
- // eslint-disable-line global-require
12
- app . quit ( ) ;
19
+ // eslint-disable-line global-require
20
+ app . quit ( ) ;
13
21
}
14
22
15
23
let stopped = false ;
@@ -19,34 +27,44 @@ let tray: Tray | null;
19
27
let mainWindow : BrowserWindow | null = null ;
20
28
21
29
const createWindow = ( ) : void => {
22
- // Create the browser window.
23
- if ( mainWindow ) {
24
- mainWindow . show ( ) ;
25
- return
26
- }
27
- mainWindow = new BrowserWindow ( {
28
- height : 600 ,
29
- width : 800 ,
30
- darkTheme : true ,
31
- backgroundColor : '#000000' ,
32
- } ) ;
33
-
34
- mainWindow . setMenu ( null ) ;
35
-
36
- mainWindow . on ( "close" , ( ) => {
37
- mainWindow = null ;
38
- if ( stopped == true ) return ;
39
- new Notification ( {
40
- title : "Mcat-Dc" ,
41
- body : "Mcat-Dc is still running in the background! Check your system tray to open it again or quit the app." ,
42
- silent : true ,
43
- timeoutType : "default" ,
44
- subtitle : "Info"
45
- } ) . show ( )
46
- } )
47
-
48
- // and load the index.html of the app.
49
- mainWindow . loadFile ( path . join ( __dirname , '../src/index.html' ) ) ;
30
+ // Create the browser window.
31
+ if ( mainWindow ) {
32
+ mainWindow . show ( ) ;
33
+ return ;
34
+ }
35
+ mainWindow = new BrowserWindow ( {
36
+ height : 600 ,
37
+ width : 800 ,
38
+ darkTheme : true ,
39
+ backgroundColor : '#000000' ,
40
+ } ) ;
41
+
42
+ mainWindow . setMenu ( null ) ;
43
+
44
+ mainWindow . on ( 'close' , ( ) => {
45
+ mainWindow = null ;
46
+ if ( stopped == true ) return ;
47
+ new Notification ( {
48
+ title : 'Mcat-Dc' ,
49
+ body :
50
+ 'Mcat-Dc is still running in the background! Check your system tray to open it again or quit the app.' ,
51
+ silent : true ,
52
+ timeoutType : 'default' ,
53
+ subtitle : 'Info' ,
54
+ icon : path . join ( __dirname , '../src/mcat.png' ) ,
55
+ } )
56
+ . on ( 'action' , ( event , i ) => {
57
+ if ( i == 0 ) {
58
+ createWindow ( ) ;
59
+ } else {
60
+ app . quit ( ) ;
61
+ }
62
+ } )
63
+ . show ( ) ;
64
+ } ) ;
65
+
66
+ // and load the index.html of the app.
67
+ mainWindow . loadFile ( path . join ( __dirname , '../src/index.html' ) ) ;
50
68
} ;
51
69
52
70
// This method will be called when Electron has finished
@@ -55,8 +73,8 @@ const createWindow = (): void => {
55
73
app . on ( 'ready' , createWindow ) ;
56
74
57
75
app . whenReady ( ) . then ( ( ) => {
58
- createWindow ( ) ;
59
- runTray ( ) ;
76
+ createWindow ( ) ;
77
+ runTray ( ) ;
60
78
} ) ;
61
79
62
80
// Quit when all windows are closed, except on macOS. There, it's common
@@ -67,34 +85,36 @@ app.on('window-all-closed', (e: any) => {
67
85
} ) ;
68
86
69
87
app . on ( 'activate' , ( ) => {
70
- // On OS X it's common to re-create a window in the app when the
71
- // dock icon is clicked and there are no other windows open.
72
- if ( BrowserWindow . getAllWindows ( ) . length === 0 ) {
73
- createWindow ( ) ;
74
- }
88
+ // On OS X it's common to re-create a window in the app when the
89
+ // dock icon is clicked and there are no other windows open.
90
+ if ( BrowserWindow . getAllWindows ( ) . length === 0 ) {
91
+ createWindow ( ) ;
92
+ }
75
93
} ) ;
76
94
77
95
// In this file you can include the rest of your app's specific main process
78
96
// code. You can also put them in separate files and import them here.
79
97
80
98
function runTray ( ) {
81
- const icon = nativeImage . createFromPath ( path . join ( __dirname , "../src/mcat.png" ) ) . resize ( { width : 32 , height : 32 } ) ;
99
+ const icon = nativeImage
100
+ . createFromPath ( path . join ( __dirname , '../src/mcat.png' ) )
101
+ . resize ( { width : 32 , height : 32 } ) ;
82
102
tray = new Tray ( icon ) ;
83
103
const contextMenu = Menu . buildFromTemplate ( [
84
104
{ label : 'Mcat-Dc' , type : 'normal' , enabled : false } ,
85
105
{
86
106
label : 'Quit' ,
87
107
type : 'normal' ,
88
108
click : ( ) => {
89
- stopped = true ;
109
+ stopped = true ;
90
110
app . quit ( ) ;
91
- }
92
- }
111
+ } ,
112
+ } ,
93
113
] ) ;
94
114
95
- tray . on ( " click" , ( ) => {
96
- createWindow ( ) ;
97
- } )
115
+ tray . on ( ' click' , ( ) => {
116
+ createWindow ( ) ;
117
+ } ) ;
98
118
99
- tray . setContextMenu ( contextMenu ) ;
100
- }
119
+ tray . setContextMenu ( contextMenu ) ;
120
+ }
0 commit comments