From f3624dfe45ca83acb23db18ce205e03815e9123d Mon Sep 17 00:00:00 2001 From: Durran Jordan Date: Wed, 11 Oct 2017 09:39:58 -0400 Subject: [PATCH 1/3] COMPASS-2168: Show license on community first start --- package.json | 2 ++ src/app/index.js | 35 +++++++++++++++++++++++++++++--- src/app/models/preferences.js | 9 ++++++++ src/main/application.js | 14 ++++++------- src/main/window-manager.js | 2 +- src/setup-hadron-distribution.js | 2 +- 6 files changed, 52 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 9909ca88792..0a74afbf6bc 100644 --- a/package.json +++ b/package.json @@ -62,6 +62,7 @@ "node_modules/@mongodb-js/compass-connect", "node_modules/@mongodb-js/compass-crud", "node_modules/@mongodb-js/compass-deployment-awareness", + "node_modules/@mongodb-js/compass-license", "node_modules/@mongodb-js/compass-query-history", "node_modules/@mongodb-js/compass-security", "node_modules/@mongodb-js/compass-status" @@ -145,6 +146,7 @@ "@mongodb-js/compass-crud": "^0.7.1", "@mongodb-js/compass-deployment-awareness": "^5.0.0", "@mongodb-js/compass-document-validation": "^5.0.0", + "@mongodb-js/compass-license": "^1.0.0", "@mongodb-js/compass-query-history": "^2.0.1", "@mongodb-js/compass-security": "^0.0.2", "@mongodb-js/compass-serverstats": "^10.0.0", diff --git a/src/app/index.js b/src/app/index.js index 855784c3768..193aeda0a0f 100644 --- a/src/app/index.js +++ b/src/app/index.js @@ -20,6 +20,10 @@ require('./setup-hadron-caches'); /** * The main entrypoint for the application! */ +const pkg = require('../../package.json'); +const COMMUNITY = 'mongodb-compass-community'; +const DISTRIBUTION = pkg.config.hadron.distributions[process.env.HADRON_DISTRIBUTION]; + var electron = require('electron'); var APP_VERSION = electron.remote.app.getVersion(); @@ -84,6 +88,7 @@ var Application = View.extend({ '
', '
', '
', + '
', '' ].join('\n'); }, @@ -210,10 +215,34 @@ var Application = View.extend({ }); this.autoUpdate.render(); - if (app.preferences.showFeatureTour) { - this.showTour(false); + const handleTour = () => { + if (app.preferences.showFeatureTour) { + this.showTour(false); + } else { + this.tourClosed(); + } + }; + + /** + * If we're in Compass community and the license has not been agreed, we need + * to show it first and force the user to agree or disagree. + */ + if (DISTRIBUTION.name === COMMUNITY && !app.preferences.agreedToLicense) { + const licenseComponent = app.appRegistry.getRole('Application.License')[0].component; + const licenseStore = app.appRegistry.getStore('License.Store'); + const licenseActions = app.appRegistry.getAction('License.Actions'); + + ReactDOM.render(React.createElement(licenseComponent), this.queryByHook('license')); + + licenseStore.listen((state) => { + if (state.isAgreed) { + handleTour(); + } + }); + + licenseActions.show(); } else { - this.tourClosed(); + handleTour(); } if (process.env.NODE_ENV !== 'production') { diff --git a/src/app/models/preferences.js b/src/app/models/preferences.js index 17f7b77bf8e..709d90fe673 100644 --- a/src/app/models/preferences.js +++ b/src/app/models/preferences.js @@ -55,6 +55,15 @@ const preferencesProps = { required: true, default: '' }, + /** + * Whether the user agreed to community license terms. + * @type {Boolean} + */ + agreedToLicense: { + type: 'boolean', + required: true, + default: false + }, /** * Feature Flags diff --git a/src/main/application.js b/src/main/application.js index f308b902ee0..619b84350a0 100644 --- a/src/main/application.js +++ b/src/main/application.js @@ -93,6 +93,13 @@ Application.prototype.setupLifecycleListeners = function() { debug('All windows closed. Quitting app.'); app.quit(); }); + + ipc.respondTo({ + 'license:disagree': function() { + debug('Did not agree to license, quitting app.'); + app.quit(); + } + }); }; Application.prototype.setupApplicationMenu = function() { @@ -130,13 +137,6 @@ Application.prototype.setupUserDirectory = function() { } }; -Application.prototype.setupLifecycleListeners = function() { - app.on('window-all-closed', function() { - debug('All windows closed. Quitting app.'); - app.quit(); - }); -}; - Application._instance = null; Application.main = function() { diff --git a/src/main/window-manager.js b/src/main/window-manager.js index 29f5aa05d06..68882dc08c7 100644 --- a/src/main/window-manager.js +++ b/src/main/window-manager.js @@ -116,7 +116,7 @@ var createWindow = module.exports.create = function(opts) { width: opts.width, height: opts.height, icon: opts.icon, - show: false, + show: true, devTools: process.env.NODE_ENV !== 'production', 'min-width': opts.minwidth, 'web-preferences': { diff --git a/src/setup-hadron-distribution.js b/src/setup-hadron-distribution.js index 5d42ea65a5e..46caa1e995f 100644 --- a/src/setup-hadron-distribution.js +++ b/src/setup-hadron-distribution.js @@ -2,7 +2,7 @@ const pkg = require('../package.json'); /** * @note: HADRON_DISTRIBUTION is set via command line args in dev, for example: - * npm start compass-enterprise + * npm start compass-community */ if (!process.env.HADRON_DISTRIBUTION) { process.env.HADRON_DISTRIBUTION = pkg.distribution || pkg.config.hadron.distributions.default; From 61b7fcb429c24221ab90b9ccc835fc0d61fdf0a4 Mon Sep 17 00:00:00 2001 From: Durran Jordan Date: Wed, 11 Oct 2017 10:24:44 -0400 Subject: [PATCH 2/3] Use the first license release --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0a74afbf6bc..b97ac79c53d 100644 --- a/package.json +++ b/package.json @@ -146,7 +146,7 @@ "@mongodb-js/compass-crud": "^0.7.1", "@mongodb-js/compass-deployment-awareness": "^5.0.0", "@mongodb-js/compass-document-validation": "^5.0.0", - "@mongodb-js/compass-license": "^1.0.0", + "@mongodb-js/compass-license": "^0.0.1", "@mongodb-js/compass-query-history": "^2.0.1", "@mongodb-js/compass-security": "^0.0.2", "@mongodb-js/compass-serverstats": "^10.0.0", From 40752fb71b0397fe56dd388974bb885dc16f2e58 Mon Sep 17 00:00:00 2001 From: Durran Jordan Date: Wed, 11 Oct 2017 10:28:02 -0400 Subject: [PATCH 3/3] Hide 2nd window on load --- src/main/window-manager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/window-manager.js b/src/main/window-manager.js index 68882dc08c7..29f5aa05d06 100644 --- a/src/main/window-manager.js +++ b/src/main/window-manager.js @@ -116,7 +116,7 @@ var createWindow = module.exports.create = function(opts) { width: opts.width, height: opts.height, icon: opts.icon, - show: true, + show: false, devTools: process.env.NODE_ENV !== 'production', 'min-width': opts.minwidth, 'web-preferences': {