@@ -12,11 +12,19 @@ var DEFAULT_URL = 'file://' + path.join(RESOURCES, 'index.html#connect');
12
12
var DEFAULT_WIDTH = 1024 ;
13
13
var DEFAULT_HEIGHT = 700 ;
14
14
15
+ var DEFAULT_HEIGHT_DIALOG ;
16
+
17
+ if ( process . platform === 'win32' ) {
18
+ DEFAULT_HEIGHT_DIALOG = 460 ;
19
+ } else if ( process . platform === 'linux' ) {
20
+ DEFAULT_HEIGHT_DIALOG = 430 ;
21
+ } else {
22
+ DEFAULT_HEIGHT_DIALOG = 400 ;
23
+ }
15
24
var DEFAULT_WIDTH_DIALOG = 600 ;
16
- var DEFAULT_HEIGHT_DIALOG = 400 ;
17
25
18
- var main = module . exports . main = null ;
19
- var childWindows = [ ] ;
26
+ var connectWindow ;
27
+ var windowsOpenCount = 0 ;
20
28
21
29
module . exports . create = function ( opts ) {
22
30
opts = _ . defaults ( opts || { } , {
@@ -36,41 +44,48 @@ module.exports.create = function(opts) {
36
44
} ) ;
37
45
attachMenu ( _window ) ;
38
46
_window . loadUrl ( opts . url ) ;
39
- if ( main ) {
40
- childWindows . push ( _window ) ;
41
- }
47
+
42
48
_window . webContents . on ( 'new-window' , function ( event , url , frameName , disposition ) {
43
49
debug ( 'got new-window event!' , event , url , frameName , disposition ) ;
44
50
event . preventDefault ( ) ;
45
51
module . exports . create ( {
46
52
url : 'file://' + RESOURCES + '/index.html' + url . replace ( 'file://' , '' )
47
53
} ) ;
48
54
} ) ;
55
+
56
+ if ( opts . url === DEFAULT_URL ) {
57
+ connectWindow = _window ;
58
+ connectWindow . on ( 'closed' , function ( ) {
59
+ debug ( 'connect window closed.' ) ;
60
+ connectWindow = null ;
61
+ } ) ;
62
+ }
63
+ windowsOpenCount ++ ;
64
+ _window . on ( 'closed' , function ( ) {
65
+ windowsOpenCount -- ;
66
+ if ( windowsOpenCount === 0 ) {
67
+ debug ( 'all windows closed. quitting.' ) ;
68
+ app . quit ( ) ;
69
+ }
70
+ } ) ;
49
71
return _window ;
50
72
} ;
51
73
52
- app . on ( 'ready' , function ( ) {
53
- // var height = DEFAULT_HEIGHT;
54
- var height = DEFAULT_HEIGHT_DIALOG ;
55
- if ( process . platform === 'win32' ) {
56
- height += 60 ;
57
- } else if ( process . platform === 'linux' ) {
58
- height += 30 ;
74
+ app . on ( 'show connect dialog' , function ( opts ) {
75
+ if ( connectWindow ) {
76
+ connectWindow . focus ( ) ;
77
+ return connectWindow ;
59
78
}
60
- debug ( 'loading main window' , DEFAULT_URL ) ;
61
79
62
- main = module . exports . main = module . exports . create ( {
63
- height : height ,
80
+ opts = opts || { } ;
81
+ opts = _ . extend ( opts || { } , {
82
+ height : DEFAULT_HEIGHT_DIALOG ,
64
83
width : DEFAULT_WIDTH_DIALOG ,
65
84
url : DEFAULT_URL
66
85
} ) ;
86
+ module . exports . create ( opts ) ;
87
+ } ) ;
67
88
68
- main . on ( 'closed' , function ( ) {
69
- debug ( 'main window closed. killing children.' ) ;
70
- main = null ;
71
- /*eslint no-unused-vars:0*/
72
- childWindows . map ( function ( _window ) {
73
- _window = null ;
74
- } ) ;
75
- } ) ;
89
+ app . on ( 'ready' , function ( ) {
90
+ app . emit ( 'show connect dialog' ) ;
76
91
} ) ;
0 commit comments