77var AppMenu = require ( './menu' ) ;
88var BrowserWindow = require ( 'browser-window' ) ;
99var Clipboard = require ( 'clipboard' ) ;
10- var Connection = require ( 'mongodb-connection-model' ) ;
1110var Notifier = require ( 'node-notifier' ) ;
11+ var Path = require ( 'path' ) ;
1212
1313var _ = require ( 'lodash' ) ;
1414var app = require ( 'app' ) ;
1515var config = require ( './config' ) ;
1616var debug = require ( 'debug' ) ( 'scout-electron:window-manager' ) ;
1717var dialog = require ( 'dialog' ) ;
18- var path = require ( 'path' ) ;
1918
2019/**
2120 * When running in electron, we're in `RESOURCES/src/electron`.
2221 */
23- var RESOURCES = path . resolve ( __dirname , '../../' ) ;
22+ var RESOURCES = Path . resolve ( __dirname , '../../' ) ;
2423var SCOUT_ICON_PATH = RESOURCES + '/images/scout.png' ;
2524
2625/**
2726 * The app's HTML shell which is the output of `./src/index.jade`
2827 * created by the `build:pages` gulp task.
2928 */
30- var DEFAULT_URL = 'file://' + path . join ( RESOURCES , 'index.html#connect' ) ;
29+ var DEFAULT_URL = 'file://' + Path . join ( RESOURCES , 'index.html#connect' ) ;
3130
3231/**
3332 * We want the Connect dialog window to be special
3433 * and for there to ever only be one instance of it
3534 * so we'll use scope to essentially make it a Singleton.
3635 */
3736var connectWindow ;
38- var curNotifierOnClickFn ;
39- var lastClipboardTxt ;
4037
4138// @todo (imlucas): Removed in setup branch as we dont need to do this anymore
4239// as a `all-windows-closed` event has been added to the `app` event api
4340// since this code was laid down.
4441var windowsOpenCount = 0 ;
4542
46- var autofillConnect = function ( ) {
47- debug ( 'autofillConnect()' ) ;
48- var connection = Connection . from ( Clipboard . readText ( ) ) . toJSON ( ) ;
49- connectWindow . webContents . send ( 'message' , 'update-connection' , connection ) ;
50- } ;
51-
5243function isConnectDialog ( url ) {
5344 return url === DEFAULT_URL ;
5445}
5546
56- function isMongoURI ( str ) {
57- return str . indexOf ( 'mongodb://' ) > - 1 ;
58- }
59-
6047// returns true if the application is a single instance application otherwise
6148// focus the second window (which we'll quit from) and return false
6249// see "app.makeSingleInstance" in https://github.com/atom/electron/blob/master/docs/api/app.md
@@ -137,22 +124,7 @@ module.exports.create = function(opts) {
137124 connectWindow = _window ;
138125 connectWindow . on ( 'focus' , function ( ) {
139126 debug ( 'connect window focused.' ) ;
140- var cbTxt = Clipboard . readText ( ) ;
141- if ( cbTxt === lastClipboardTxt ) {
142- return ;
143- }
144- lastClipboardTxt = cbTxt ;
145-
146- if ( isMongoURI ( cbTxt ) ) {
147- debug ( 'mongoURI detected.' ) ;
148- curNotifierOnClickFn = autofillConnect ;
149- Notifier . notify ( {
150- 'icon' : SCOUT_ICON_PATH ,
151- 'message' : 'Click this notification to autofill the connection fields from your clipboard.' ,
152- 'title' : 'Autofill Connection' ,
153- 'wait' : true
154- } ) ;
155- }
127+ connectWindow . webContents . send ( 'message' , 'connect-window-focused' ) ;
156128 } ) ;
157129 connectWindow . on ( 'closed' , function ( ) {
158130 debug ( 'connect window closed.' ) ;
@@ -196,6 +168,19 @@ app.on('show about dialog', function() {
196168 } ) ;
197169} ) ;
198170
171+ app . on ( 'show autofill connection notification' , function ( ) {
172+ Notifier . notify ( {
173+ 'icon' : SCOUT_ICON_PATH ,
174+ 'message' : 'Click this notification to autofill the connection fields from your clipboard.' ,
175+ 'title' : 'Autofill Connection' ,
176+ 'wait' : true
177+ } , function ( err , resp ) {
178+ if ( resp === 'Activate\n' ) {
179+ connectWindow . webContents . send ( 'message' , 'autofill-connection-from-clipboard' ) ;
180+ }
181+ } ) ;
182+ } ) ;
183+
199184app . on ( 'hide connect submenu' , function ( ) {
200185 AppMenu . hideConnect ( ) ;
201186} ) ;
@@ -218,12 +203,15 @@ app.on('show share submenu', function() {
218203
219204app . on ( 'show bugsnag OS notification' , function ( errorMsg ) {
220205 if ( _ . contains ( [ 'development' , 'testing' ] , process . env . NODE_ENV ) ) {
221- curNotifierOnClickFn = openDevTools ;
222206 Notifier . notify ( {
223207 'icon' : SCOUT_ICON_PATH ,
224208 'message' : errorMsg ,
225209 'title' : 'MongoDB Compass Exception' ,
226210 'wait' : true
211+ } , function ( err , resp ) {
212+ if ( resp === 'Activate\n' ) {
213+ openDevTools ( ) ;
214+ }
227215 } ) ;
228216 }
229217} ) ;
@@ -236,10 +224,6 @@ app.on('show bugsnag OS notification', function(errorMsg) {
236224 */
237225app . on ( 'ready' , function ( ) {
238226 app . emit ( 'show connect dialog' ) ;
239-
240- Notifier . on ( 'click' , function ( ) {
241- curNotifierOnClickFn ( ) ;
242- } ) ;
243227} ) ;
244228
245229var ipc = require ( 'ipc' ) ;
0 commit comments