1
+ /**
2
+ * A high-level wrapper around electron's builtin
3
+ * [BrowserWindow](https://github.com/atom/electron/blob/master/docs/api/browser-window.md)
4
+ * class
5
+ */
6
+ var path = require ( 'path' ) ;
1
7
var _ = require ( 'lodash' ) ;
2
-
3
- var BrowserWindow = require ( 'browser-window' ) ;
4
8
var app = require ( 'app' ) ;
5
- var debug = require ( 'debug' ) ( 'scout-electron:window-manager' ) ;
6
9
var attachMenu = require ( './menu' ) ;
7
- var path = require ( 'path' ) ;
10
+ var BrowserWindow = require ( 'browser-window' ) ;
11
+ var debug = require ( 'debug' ) ( 'scout-electron:window-manager' ) ;
8
12
13
+ /**
14
+ * When running in electron, we're in `RESOURCES/src/electron`.
15
+ */
9
16
var RESOURCES = path . resolve ( __dirname , '../../' ) ;
17
+
18
+ /**
19
+ * The app's HTML shell which is the output of `./src/index.jade`
20
+ * created by the `build:pages` gulp task.
21
+ */
10
22
var DEFAULT_URL = 'file://' + path . join ( RESOURCES , 'index.html#connect' ) ;
11
23
24
+ /**
25
+ * The outer dimensions to use for new windows.
26
+ */
12
27
var DEFAULT_WIDTH = 1024 ;
13
28
var DEFAULT_HEIGHT = 700 ;
14
29
15
- var DEFAULT_HEIGHT_DIALOG ;
16
-
17
- if ( process . platform === 'win32' ) {
18
- DEFAULT_HEIGHT_DIALOG = 500 ;
19
- } else if ( process . platform === 'linux' ) {
20
- DEFAULT_HEIGHT_DIALOG = 470 ;
21
- } else {
22
- DEFAULT_HEIGHT_DIALOG = 440 ;
23
- }
30
+ /**
31
+ * The outer window dimensions to use for new dialog
32
+ * windows like the connection and setup dialogs.
33
+ */
24
34
var DEFAULT_WIDTH_DIALOG = 640 ;
35
+ var DEFAULT_HEIGHT_DIALOG = 600 ;
36
+ /**
37
+ * Adjust the heights to account for platforms
38
+ * that use a single menu bar at the top of the screen.
39
+ */
40
+ if ( process . platform === 'linux' ) {
41
+ DEFAULT_HEIGHT_DIALOG -= 30 ;
42
+ DEFAULT_HEIGHT -= 30 ;
43
+ } else if ( process . platform === 'darwin' ) {
44
+ DEFAULT_HEIGHT_DIALOG -= 60 ;
45
+ DEFAULT_HEIGHT -= 60 ;
46
+ }
25
47
48
+ /**
49
+ * We want want the Connect dialog window to be special
50
+ * and for there to ever only be one instance of it
51
+ * so we'll use scope to essentially make it a Singleton.
52
+ */
26
53
var connectWindow ;
54
+
55
+ // @todo (imlucas): Removed in setup branch as we dont need to do this anymore
56
+ // as a `all-windows-closed` event has been added to the `app` event api
57
+ // since this code was laid down.
27
58
var windowsOpenCount = 0 ;
28
59
60
+ /**
61
+ * Call me instead of using `new BrowserWindow()` directly because i'll:
62
+ *
63
+ * 1. Make sure the window is the right size
64
+ * 2. Doesn't load a blank screen
65
+ * 3. Overrides `window.open` so we have control over message passing via URL's
66
+
67
+ *
68
+ * @param {Object } opts - Smaller subset of [`BrowserWindow#options`][0].
69
+ * @return {BrowserWindow }
70
+ * [0]: http://git.io/vnwTY
71
+ */
29
72
module . exports . create = function ( opts ) {
30
73
opts = _ . defaults ( opts || { } , {
31
74
width : DEFAULT_WIDTH ,
@@ -49,6 +92,7 @@ module.exports.create = function(opts) {
49
92
debug ( 'intercepting new-window (disregard the "error" message '
50
93
+ 'preventDefault is about to cause)' ) ;
51
94
event . preventDefault ( ) ;
95
+
52
96
module . exports . create ( {
53
97
url : 'file://' + RESOURCES + '/index.html' + decodeURIComponent ( url . replace ( 'file://' , '' ) )
54
98
} ) ;
@@ -61,6 +105,8 @@ module.exports.create = function(opts) {
61
105
connectWindow = null ;
62
106
} ) ;
63
107
}
108
+
109
+ // @see `all-windows-closed` above
64
110
windowsOpenCount ++ ;
65
111
_window . on ( 'closed' , function ( ) {
66
112
windowsOpenCount -- ;
@@ -87,6 +133,12 @@ app.on('show connect dialog', function(opts) {
87
133
module . exports . create ( opts ) ;
88
134
} ) ;
89
135
136
+ /**
137
+ * When electron's main renderer has completed setup,
138
+ * we'll always show the [connect][./src/connect] dialog
139
+ * on start which is responsible for retaining it's own
140
+ * state between application launches.
141
+ */
90
142
app . on ( 'ready' , function ( ) {
91
143
app . emit ( 'show connect dialog' ) ;
92
144
} ) ;
0 commit comments