Skip to content

Commit 523dd44

Browse files
authored
COMPASS-2168: License for Compass Community (#1266)
* COMPASS-2168: Show license on community first start * Use the first license release * Hide 2nd window on load
1 parent 30fa9ce commit 523dd44

File tree

5 files changed

+51
-11
lines changed

5 files changed

+51
-11
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"node_modules/@mongodb-js/compass-connect",
6363
"node_modules/@mongodb-js/compass-crud",
6464
"node_modules/@mongodb-js/compass-deployment-awareness",
65+
"node_modules/@mongodb-js/compass-license",
6566
"node_modules/@mongodb-js/compass-query-history",
6667
"node_modules/@mongodb-js/compass-security",
6768
"node_modules/@mongodb-js/compass-status"
@@ -145,6 +146,7 @@
145146
"@mongodb-js/compass-crud": "^0.7.1",
146147
"@mongodb-js/compass-deployment-awareness": "^5.0.0",
147148
"@mongodb-js/compass-document-validation": "^5.0.0",
149+
"@mongodb-js/compass-license": "^0.0.1",
148150
"@mongodb-js/compass-query-history": "^2.0.1",
149151
"@mongodb-js/compass-security": "^0.0.2",
150152
"@mongodb-js/compass-serverstats": "^10.0.0",

src/app/index.js

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ require('./setup-hadron-caches');
2020
/**
2121
* The main entrypoint for the application!
2222
*/
23+
const pkg = require('../../package.json');
24+
const COMMUNITY = 'mongodb-compass-community';
25+
const DISTRIBUTION = pkg.config.hadron.distributions[process.env.HADRON_DISTRIBUTION];
26+
2327
var electron = require('electron');
2428
var APP_VERSION = electron.remote.app.getVersion();
2529

@@ -84,6 +88,7 @@ var Application = View.extend({
8488
' <div data-hook="tour-container"></div>',
8589
' <div data-hook="optin-container"></div>',
8690
' <div data-hook="security"></div>',
91+
' <div data-hook="license"></div>',
8792
'</div>'
8893
].join('\n');
8994
},
@@ -210,10 +215,34 @@ var Application = View.extend({
210215
});
211216
this.autoUpdate.render();
212217

213-
if (app.preferences.showFeatureTour) {
214-
this.showTour(false);
218+
const handleTour = () => {
219+
if (app.preferences.showFeatureTour) {
220+
this.showTour(false);
221+
} else {
222+
this.tourClosed();
223+
}
224+
};
225+
226+
/**
227+
* If we're in Compass community and the license has not been agreed, we need
228+
* to show it first and force the user to agree or disagree.
229+
*/
230+
if (DISTRIBUTION.name === COMMUNITY && !app.preferences.agreedToLicense) {
231+
const licenseComponent = app.appRegistry.getRole('Application.License')[0].component;
232+
const licenseStore = app.appRegistry.getStore('License.Store');
233+
const licenseActions = app.appRegistry.getAction('License.Actions');
234+
235+
ReactDOM.render(React.createElement(licenseComponent), this.queryByHook('license'));
236+
237+
licenseStore.listen((state) => {
238+
if (state.isAgreed) {
239+
handleTour();
240+
}
241+
});
242+
243+
licenseActions.show();
215244
} else {
216-
this.tourClosed();
245+
handleTour();
217246
}
218247

219248
if (process.env.NODE_ENV !== 'production') {

src/app/models/preferences.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ const preferencesProps = {
5555
required: true,
5656
default: ''
5757
},
58+
/**
59+
* Whether the user agreed to community license terms.
60+
* @type {Boolean}
61+
*/
62+
agreedToLicense: {
63+
type: 'boolean',
64+
required: true,
65+
default: false
66+
},
5867

5968
/**
6069
* Feature Flags

src/main/application.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ Application.prototype.setupLifecycleListeners = function() {
9393
debug('All windows closed. Quitting app.');
9494
app.quit();
9595
});
96+
97+
ipc.respondTo({
98+
'license:disagree': function() {
99+
debug('Did not agree to license, quitting app.');
100+
app.quit();
101+
}
102+
});
96103
};
97104

98105
Application.prototype.setupApplicationMenu = function() {
@@ -130,13 +137,6 @@ Application.prototype.setupUserDirectory = function() {
130137
}
131138
};
132139

133-
Application.prototype.setupLifecycleListeners = function() {
134-
app.on('window-all-closed', function() {
135-
debug('All windows closed. Quitting app.');
136-
app.quit();
137-
});
138-
};
139-
140140
Application._instance = null;
141141

142142
Application.main = function() {

src/setup-hadron-distribution.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const pkg = require('../package.json');
22

33
/**
44
* @note: HADRON_DISTRIBUTION is set via command line args in dev, for example:
5-
* npm start compass-enterprise
5+
* npm start compass-community
66
*/
77
if (!process.env.HADRON_DISTRIBUTION) {
88
process.env.HADRON_DISTRIBUTION = pkg.distribution || pkg.config.hadron.distributions.default;

0 commit comments

Comments
 (0)