1
- var dev = true ;
2
-
3
- if ( typeof process === 'object' ) {
4
- if ( typeof process . versions === 'object' ) {
5
- if ( typeof process . versions [ 'electron' ] !== 'undefined' ) {
1
+ var dev = false ;
6
2
7
3
const { app, BrowserWindow, Menu, Tray} = require ( 'electron' )
8
4
const path = require ( 'path' )
9
5
const url = require ( 'url' )
10
- const fs = require ( 'fs' ) ;
6
+ const fs = require ( 'fs' )
11
7
12
8
// Keep a global reference of the window object, if you don't, the window will
13
9
// be closed automatically when the JavaScript object is garbage collected.
@@ -19,77 +15,46 @@ var appName = app.getName();
19
15
var appIcon = __dirname + '/logo_128.png' ;
20
16
var appPath = app . getAppPath ( ) ;
21
17
22
- if ( fs . existsSync ( appPath + "/dats/" ) ) {
23
- fs . mkdir ( appPath + "/dats/" ) ;
24
- }
25
-
26
- app . on ( 'ready' , ( ) => {
27
- tray = new Tray ( appIcon )
28
- const contextMenu = Menu . buildFromTemplate ( [
29
- { label : 'Show' , click : function ( ) { win . show ( ) ; } } ,
30
- { label : 'Quit' , click : function ( ) { app . isQuiting = true ; app . quit ( ) ; } }
31
- ] )
32
- tray . setToolTip ( appName + " v" + versionNumber )
33
- tray . setContextMenu ( contextMenu )
34
- tray . on ( 'click' , ( ) => {
35
- win . show ( )
36
- } )
37
-
38
- if ( app . isDefaultProtocolClient ( appName ) ) {
39
-
40
- } else {
41
- app . setAsDefaultProtocolClient ( appName )
42
- }
43
-
44
- /*
45
- if(app.isDefaultProtocolClient('dat')) {
46
-
47
- } else {
48
- app.setAsDefaultProtocolClient('dat')
18
+ if ( ! fs . existsSync ( __dirname + '/../../dats/' ) ) {
19
+ fs . mkdirSync ( __dirname + '/../../dats/' ) ;
49
20
}
50
- */
51
-
52
- process . argv . forEach ( function ( val , index , array ) {
53
- console . log ( index + ': ' + val ) ;
54
- } ) ;
55
-
56
- } )
57
-
58
- const isSecondInstance = app . makeSingleInstance ( ( commandLine , workingDirectory ) => {
59
- // Someone tried to run a second instance, we should focus our window.
60
- if ( win ) {
61
- if ( win . isMinimized ( ) ) win . restore ( )
62
- win . show ( )
63
- win . focus ( )
64
- }
65
- } )
66
-
67
- if ( isSecondInstance ) {
68
- app . quit ( )
69
- }
70
21
71
22
function createWindow ( ) {
72
23
// Create the browser window.
73
- win = new BrowserWindow (
74
- {
24
+ win = new BrowserWindow ( {
75
25
width : 800 ,
76
26
height : 600 ,
77
- icon : __dirname + '/logo_128.png' ,
27
+ icon : appIcon ,
78
28
backgroundColor : '#424242' ,
79
29
show : false
80
30
} )
81
31
82
- win . setMenu ( null )
83
-
84
- // and load the index.html of the app.
85
- win . loadURL ( 'file://' + __dirname + '/server_app.html' )
86
-
32
+ const devTopMenu = Menu . buildFromTemplate ( [
33
+ { label : appName + " v" + versionNumber + " dev mode" } ,
34
+ { label : 'Quit for real' , click : function ( ) { app . isQuiting = true ; app . quit ( ) ; } }
35
+ ] )
87
36
88
37
// Open the DevTools if dev is true.
89
38
if ( dev == true ) {
90
- win . webContents . openDevTools ( { mode :'detach' } )
39
+ win . setMenu ( devTopMenu )
40
+ win . setThumbnailToolTip ( appName + " v" + versionNumber + " dev mode" )
41
+ win . setTitle ( appName + " v" + versionNumber + " dev mode" )
42
+ win . webContents . openDevTools ( { mode :'detach' } )
43
+ } else if ( dev != true ) {
44
+ win . setMenu ( null )
45
+ win . setThumbnailToolTip ( appName + " v" + versionNumber )
46
+ win . setTitle ( appName + " v" + versionNumber )
91
47
}
92
48
49
+ win . on ( 'show' , ( ) => {
50
+ if ( dev == true ) {
51
+ win . webContents . openDevTools ( { mode :'detach' } )
52
+ }
53
+ } )
54
+
55
+ // and load the index.html of the app.
56
+ win . loadURL ( 'file://' + __dirname + '/server_app.html' )
57
+
93
58
win . on ( 'close' , function ( event ) {
94
59
if ( ! app . isQuiting ) {
95
60
event . preventDefault ( )
@@ -105,65 +70,68 @@ function createWindow () {
105
70
// when you should delete the corresponding element.
106
71
win = null
107
72
} )
108
-
73
+
109
74
}
110
75
111
- // This method will be called when Electron has finished
112
- // initialization and is ready to create browser windows.
113
- // Some APIs can only be used after this event occurs.
114
- app . on ( 'ready' , createWindow )
76
+ const isSecondInstance = app . makeSingleInstance ( ( commandLine , workingDirectory ) => {
77
+ // Someone tried to run a second instance, we should focus our window.
78
+ if ( win ) {
79
+ if ( win . isMinimized ( ) ) win . restore ( )
80
+ win . show ( )
81
+ win . focus ( )
82
+ }
83
+ } )
84
+
85
+ if ( isSecondInstance ) {
86
+ app . quit ( )
87
+ }
88
+
89
+ app . on ( 'ready' , ( ) => {
90
+ if ( ! fs . existsSync ( __dirname + '/../../dats/' ) ) {
91
+ fs . mkdirSync ( __dirname + '/../../dats/' ) ;
92
+ }
93
+
94
+ tray = new Tray ( appIcon )
95
+
96
+ const contextMenu = Menu . buildFromTemplate ( [
97
+ { label : 'Show' , click : function ( ) { win . show ( ) ; } } ,
98
+ { label : 'Quit' , click : function ( ) { app . isQuiting = true ; app . quit ( ) ; } }
99
+ ] )
100
+
101
+ const devContextMenu = Menu . buildFromTemplate ( [
102
+ { label : 'Show' , click : function ( ) { win . show ( ) ; } } ,
103
+ { label : 'Quit' , click : function ( ) { app . isQuiting = true ; app . quit ( ) ; } } ,
104
+ { label : appName + " v" + versionNumber + " dev mode" }
105
+ ] )
106
+
107
+ if ( dev == true ) {
108
+ tray . setContextMenu ( devContextMenu )
109
+ tray . setToolTip ( appName + " v" + versionNumber + " dev mode" )
110
+ } else if ( dev != true ) {
111
+ tray . setContextMenu ( contextMenu )
112
+ tray . setToolTip ( appName + " v" + versionNumber )
113
+ }
114
+
115
+ tray . on ( 'click' , ( ) => {
116
+ win . show ( )
117
+ } )
118
+
119
+ if ( app . isDefaultProtocolClient ( appName ) ) {
120
+
121
+ } else {
122
+ app . setAsDefaultProtocolClient ( appName )
123
+ }
124
+
125
+ //var openingNotification = new Notification({title: "ggggggggo", body: "lol"})
126
+ //openingNotification.show()
127
+
128
+ createWindow ( ) ;
129
+ } )
115
130
116
131
app . on ( 'activate' , ( ) => {
117
132
// On macOS it's common to re-create a window in the app when the
118
133
// dock icon is clicked and there are no other windows open.
119
134
if ( win === null ) {
120
135
createWindow ( )
121
136
}
122
- } )
123
-
124
- // In this file you can include the rest of your app's specific main process
125
- // code. You can also put them in separate files and require them here.
126
-
127
- } } } else if ( window && window . chrome && chrome . runtime && chrome . runtime . id ) {
128
-
129
- chrome . app . runtime . onLaunched . addListener ( function ( ) {
130
- chrome . app . window . create ( '/server_app.html?platform=chromeApp' , {
131
- 'innerBounds' : {
132
- 'width' : 800 ,
133
- 'height' : 600
134
- } ,
135
- 'minWidth' : 800 ,
136
- 'minHeight' : 400 ,
137
- 'frame' : {
138
- 'type' : 'chrome' ,
139
- 'color' : '#424242' ,
140
- 'activeColor' : '#ffffff' ,
141
- 'inactiveColor' : '#424242'
142
- } ,
143
- id : 'other_web_server'
144
- } ) ;
145
- } ) ;
146
-
147
- chrome . runtime . onMessageExternal . addListener ( function ( ) {
148
- if ( chrome . app . window . get ( 'other_web_server' ) ) {
149
- //Do Nothing
150
- } else {
151
- chrome . app . window . create ( '/server_app.html?platform=chromeApp' , {
152
- 'innerBounds' : {
153
- 'width' : 800 ,
154
- 'height' : 600
155
- } ,
156
- 'minWidth' : 800 ,
157
- 'minHeight' : 400 ,
158
- 'state' : 'minimized' ,
159
- 'frame' : {
160
- 'type' : 'chrome' ,
161
- 'color' : '#424242' ,
162
- 'activeColor' : '#ffffff' ,
163
- 'inactiveColor' : '#424242'
164
- } ,
165
- id : 'other_web_server'
166
- } ) ;
167
- }
168
- } ) ;
169
- }
137
+ } )
0 commit comments