diff --git a/package.json b/package.json index 9909ca88792..b97ac79c53d 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": "^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", 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/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;