Skip to content

Commit b4bee23

Browse files
committed
use showMessageBox instead of notifier to ask user for feedback.
1 parent 7ad7924 commit b4bee23

File tree

3 files changed

+60
-36
lines changed

3 files changed

+60
-36
lines changed

src/connect/behavior.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var assert = require('assert');
33
var Connection = require('../models/connection');
44
var _ = require('lodash');
55

6-
// var debug = require('debug')('scout:connect:behavior');
6+
var debug = require('debug')('scout:connect:behavior');
77

88
module.exports = State.extend({
99
props: {
@@ -81,7 +81,7 @@ module.exports = State.extend({
8181
dispatch: function(action) {
8282
var newState = this.reduce(this.state, action);
8383
// if (newState !== this.state) {
84-
// debug('transition: (%s, %s) ==> %s', this.state, action, newState);
84+
debug('transition: (%s, %s) ==> %s', this.state, action, newState);
8585
// }
8686
this.state = newState;
8787
return this.state;

src/connect/index.js

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ var View = require('ampersand-view');
88

99
var _ = require('lodash');
1010
var app = require('ampersand-app');
11-
var debug = require('debug')('scout:connect:index');
1211
var format = require('util').format;
1312
var metrics = require('mongodb-js-metrics');
1413

1514
var remote = window.require('remote');
15+
var dialog = remote.require('dialog');
1616
var Clipboard = remote.require('clipboard');
17+
var BrowserWindow = remote.require('browser-window');
18+
19+
var debug = require('debug')('scout:connect:index');
1720

1821
/**
1922
* AuthenticationOptionCollection
@@ -66,6 +69,10 @@ var ConnectView = View.extend({
6669
previousSslMethod: {
6770
type: 'string',
6871
default: null
72+
},
73+
clipboardText: {
74+
type: 'string',
75+
default: ''
6976
}
7077
},
7178
derived: {
@@ -233,36 +240,53 @@ var ConnectView = View.extend({
233240
this.listenToAndRun(this, 'change:sslMethod',
234241
this.replaceSslMethodFields.bind(this));
235242

236-
this.listenTo(app, 'autofill-connection-from-clipboard',
237-
this.autofillFromClipboard.bind(this));
243+
// this.listenTo(app, 'autofill-connection-from-clipboard',
244+
// this.autofillFromClipboard.bind(this));
245+
238246
this.listenTo(app, 'connect-window-focused',
239-
this.checkIfCanAutofillFromClipboard.bind(this));
247+
this.onConnectWindowFocused.bind(this));
240248

241249
// always start in NEW_EMPTY state
242250
this.dispatch('new connection clicked');
243251
},
244252

253+
// === MongoDB URI clipboard Handling
254+
255+
/**
256+
* Called when the user clicked "YES" in the message dialog after
257+
* a MongoDB URI was detected.
258+
*/
245259
autofillFromClipboard: function() {
246-
var connectionFromCB = MongoDBConnection.from(this.lastClipboardTxt).toJSON();
247-
this.connection = new Connection();
248-
/* eslint guard-for-in: 0 */
249-
for (var attr in connectionFromCB) {
250-
this.connection[attr] = connectionFromCB[attr];
251-
}
252-
/* eslint guard-for-in: 1 */
260+
this.connection = MongoDBConnection.from(this.clipboardText);
253261
this.updateForm();
254262
},
255263

256-
checkIfCanAutofillFromClipboard: function() {
257-
var cbTxt = Clipboard.readText();
258-
if (cbTxt === this.lastClipboardTxt) {
264+
/**
265+
* Called when the Connect Window receives focus.
266+
*/
267+
onConnectWindowFocused: function() {
268+
var clipboardText = Clipboard.readText();
269+
if (clipboardText === this.clipboardText) {
270+
// we have seen this value already, don't ask user again
259271
return;
260272
}
261-
this.lastClipboardTxt = cbTxt;
262-
263-
if (MongoDBConnection.isURI(cbTxt)) {
264-
debug('mongoURI detected.');
265-
app.sendMessage('show autofill connection notification');
273+
this.clipboardText = clipboardText;
274+
275+
if (MongoDBConnection.isURI(clipboardText)) {
276+
debug('MongoDB URI detected.', clipboardText);
277+
// ask user if Compass should use it to fill out form
278+
dialog.showMessageBox(BrowserWindow.getFocusedWindow(), {
279+
type: 'info',
280+
message: 'MongoDB connection string detected',
281+
detail: 'Compass detected a MongoDB connection string in your '
282+
+ 'clipboard. Do you want to use the connection string to '
283+
+ 'fill out this form?',
284+
buttons: ['Yes', 'No']
285+
}, function(response) {
286+
if (response === 0) {
287+
this.autofillFromClipboard();
288+
}
289+
}.bind(this));
266290
}
267291
},
268292

src/electron/window-manager.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -167,21 +167,21 @@ app.on('show about dialog', function() {
167167
});
168168
});
169169

170-
app.on('show autofill connection notification', function() {
171-
Notifier.notify({
172-
'icon': SCOUT_ICON_PATH,
173-
'message': 'Click this notification to autofill the connection fields from your clipboard.',
174-
'title': 'Autofill Connection',
175-
'wait': true
176-
}, function(err, resp) {
177-
if (err) {
178-
debug(err);
179-
}
180-
if (resp === 'Activate\n') {
181-
connectWindow.webContents.send('message', 'autofill-connection-from-clipboard');
182-
}
183-
});
184-
});
170+
// app.on('show autofill connection notification', function() {
171+
// Notifier.notify({
172+
// 'icon': SCOUT_ICON_PATH,
173+
// 'message': 'Click this notification to autofill the connection fields from your clipboard.',
174+
// 'title': 'Autofill Connection',
175+
// 'wait': true
176+
// }, function(err, resp) {
177+
// if (err) {
178+
// debug(err);
179+
// }
180+
// if (resp === 'Activate\n') {
181+
// connectWindow.webContents.send('message', 'autofill-connection-from-clipboard');
182+
// }
183+
// });
184+
// });
185185

186186
app.on('hide connect submenu', function() {
187187
AppMenu.hideConnect();

0 commit comments

Comments
 (0)