Skip to content

Commit c7ee031

Browse files
pzrqimlucas
authored andcommitted
COMPASS-803: Backport COMPASS-586 COMPASS-788 icon changes (#792)
* COMPASS-586: Improve Linux appearance (logo in popups/about box, ...) (#762) * COMPASS-586: Improve Linux appearance (logo in popups/about box, ...) * assert.equals => assert.equal * [Selectively cherry-picked from COMPASS 701 Charts] * Extract PackageManager setup into its own file So I can possibly reuse it in tests where I’d like to test our listenToExternalStore wiring. * Expand the --renderer test so it can handle integration tests Tried several times to get this into the --unit tests, but our internal-packages tend to depend on “window” and “document” so that is not possible. Both those are genuinely available in the renderer process so it’s definitely a better home for these tests for now. We can decide later when we have more if they can or should be decoupled further. * COMPASS-788: mongodb:// in clipboard message has regressed on macOS / Red Hat (#787) * Fix white screen and icon on macOS If you have a string prefixed with `mongodb://`, e.g. every Atlas URL, present in your clipboard. * Fix icon on Share Schema as JSON message box Tested on a Red Hat VirtualBox VM, as per: https://github.com/10gen/compass-internal-docs/pull/4 * Add regression test for the share-schema-as-json feature Not unit testing the Ampersand View clipboard version as I have no idea how to do so. * Update hadron-app => ampersand-app As we don’t expect to back port b4a5a26 * Add ‘undefined’ to share-schema-as-json test Not sure why this is ‘undefined’ on this branch but not master, but there’s a lot of hadron-app and other changes floating around so it probably doesn’t matter.
1 parent c155232 commit c7ee031

File tree

10 files changed

+118
-9
lines changed

10 files changed

+118
-9
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@
200200
"mongodb-runner": "^3.4.0",
201201
"react-addons-test-utils": "^15.2.1",
202202
"sinon": "^1.17.6",
203+
"sinon-chai": "^2.8.0",
203204
"spectron": "^3.2.6",
204205
"xvfb-maybe": "^0.1.3"
205206
},

src/app/connect/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var dialog = remote.dialog;
1616
var Clipboard = remote.clipboard;
1717
var BrowserWindow = remote.BrowserWindow;
1818
var metrics = require('mongodb-js-metrics')();
19+
var COMPASS_ICON_PATH = require('../../icon').path;
1920

2021
var debug = require('debug')('mongodb-compass:connect:index');
2122

@@ -331,6 +332,7 @@ var ConnectView = View.extend({
331332
// ask user if Compass should use it to fill out form
332333
dialog.showMessageBox(BrowserWindow.getFocusedWindow(), {
333334
type: 'info',
335+
icon: COMPASS_ICON_PATH,
334336
message: 'MongoDB connection string detected',
335337
detail: 'Compass detected a MongoDB connection string in your '
336338
+ 'clipboard. Do you want to use the connection string to '

src/app/index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ var ModuleCache = require('hadron-module-cache');
2121
ModuleCache.register(resourcePath);
2222
ModuleCache.add(resourcePath);
2323

24-
var AppRegistry = require('hadron-app-registry');
25-
var PackageManager = require('hadron-package-manager').PackageManager;
2624

2725
var pkg = require('../../package.json');
2826
var CompileCache = require('hadron-compile-cache');
@@ -94,9 +92,7 @@ new StyleManager(
9492
// order to ensure that the compile cache has already been loaded and
9593
// hooked into require.extensions. Otherwise, packages will not have
9694
// use of the compile cache.
97-
app.appRegistry = new AppRegistry();
98-
app.packageManager = new PackageManager(path.join(__dirname, '..', 'internal-packages'));
99-
app.packageManager.activate();
95+
require('./setup-package-manager');
10096

10197
function getConnection(model, done) {
10298
function _fetch(fn) {

src/app/setup-package-manager.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const app = require('ampersand-app');
2+
const path = require('path');
3+
const AppRegistry = require('hadron-app-registry');
4+
const { PackageManager } = require('hadron-package-manager');
5+
6+
app.appRegistry = new AppRegistry();
7+
app.packageManager = new PackageManager(path.join(__dirname, '..', 'internal-packages'));
8+
app.packageManager.activate();

src/icon.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var path = require('path');
2+
var COMPASS_ICON = path.join(__dirname, 'app', 'images', 'compass-dialog-icon.png');
3+
var nativeImage = require('electron').nativeImage;
4+
5+
/**
6+
* Convenience for getting the app icon to customize native UI components
7+
* via electron.
8+
*
9+
* @example
10+
* ```javascript
11+
* var icon = require('./icon');
12+
* var dialog = require('electron').dialog;
13+
* dialog.showMessageBox({icon: icon, message: 'I have a nice Compass icon.'});
14+
* ```
15+
*
16+
* @see https://jira.mongodb.org/browse/COMPASS-586
17+
*/
18+
module.exports = nativeImage.createFromPath(COMPASS_ICON);
19+
module.exports.path = COMPASS_ICON;

src/internal-packages/schema/lib/store/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const schemaStream = require('mongodb-schema').stream;
77
const toNS = require('mongodb-ns');
88
const ReadPreference = require('mongodb').ReadPreference;
99

10+
const COMPASS_ICON_PATH = require('../../../../icon').path;
11+
1012
/**
1113
* The default read preference.
1214
*/
@@ -72,6 +74,7 @@ const SchemaStore = Reflux.createStore({
7274

7375
dialog.showMessageBox(BrowserWindow.getFocusedWindow(), {
7476
type: 'info',
77+
icon: COMPASS_ICON_PATH,
7578
message: 'Share Schema',
7679
detail: detail,
7780
buttons: ['OK']

src/main/window-manager.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var debug = require('debug')('mongodb-compass:electron:window-manager');
1414
var dialog = electron.dialog;
1515
var path = require('path');
1616
var ipc = require('hadron-ipc');
17+
var COMPASS_ICON = require('../icon');
1718

1819
/**
1920
* When running in electron, we're in `/src/main`.
@@ -118,13 +119,21 @@ var createWindow = module.exports.create = function(opts) {
118119
width: DEFAULT_WIDTH,
119120
height: DEFAULT_HEIGHT,
120121
minwidth: MIN_WIDTH,
121-
url: DEFAULT_URL
122+
url: DEFAULT_URL,
123+
/**
124+
* On Windows and macOS, this will be set automatically to the optimal
125+
* app icon. Only on Linux do we need to set this explictly.
126+
*
127+
* @see https://jira.mongodb.org/browse/COMPASS-586
128+
*/
129+
icon: process.platform === 'linux' ? COMPASS_ICON : undefined
122130
});
123131

124132
debug('creating new window: ' + opts.url);
125133
var _window = new BrowserWindow({
126134
width: opts.width,
127135
height: opts.height,
136+
icon: opts.icon,
128137
'min-width': opts.minwidth,
129138
'web-preferences': {
130139
'subpixel-font-scaling': true,
@@ -164,9 +173,9 @@ function showConnectWindow() {
164173
function showAboutDialog() {
165174
dialog.showMessageBox({
166175
type: 'info',
167-
title: 'About MongoDB Compass',
168-
icon: path.join(RESOURCES, 'images', 'compass-dialog-icon.png'),
169-
message: 'MongoDB Compass',
176+
title: 'About ' + app.getName(),
177+
icon: COMPASS_ICON,
178+
message: app.getName(),
170179
detail: 'Version ' + app.getVersion(),
171180
buttons: ['OK']
172181
});

test/renderer/_setup.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
require('babel-register')();
2+
3+
require('../../src/app/reflux-listen-to-external-store');
4+
5+
// Would be nice not to need this jQuery being present
6+
window.jQuery = require('jquery');
7+
8+
// Require our internal-packages so we can integration-test things fast,
9+
// i.e. without requiring a full functional test
10+
require('../../src/app/setup-package-manager');
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/* eslint no-unused-expressions: 0 */
2+
const app = require('ampersand-app');
3+
const sinon = require('sinon');
4+
const { remote } = require('electron');
5+
const chai = require('chai');
6+
const sinonChai = require('sinon-chai');
7+
const expect = chai.expect;
8+
const COMPASS_ICON_PATH = require('../../src/icon').path;
9+
10+
// For `expect(mySpy).to.have.been.calledWith("foo");` syntax
11+
chai.use(sinonChai);
12+
13+
describe('SchemaStore', function() {
14+
let writeText;
15+
let showMessageBox;
16+
17+
beforeEach(function() {
18+
this.SchemaStore = app.appRegistry.getStore('Schema.Store');
19+
this.clipboardSpy = sinon.spy();
20+
this.messageBoxSpy = sinon.spy();
21+
writeText = remote.clipboard.writeText;
22+
showMessageBox = remote.dialog.showMessageBox;
23+
remote.clipboard.writeText = this.clipboardSpy;
24+
remote.dialog.showMessageBox = this.messageBoxSpy;
25+
});
26+
27+
afterEach(function() {
28+
remote.clipboard.writeText = writeText;
29+
remote.dialog.showMessageBox = showMessageBox;
30+
});
31+
32+
context('shares a "null" schema as JSON', function() {
33+
beforeEach(function() {
34+
// Note that normally this menu option is only exposed after the user has
35+
// connected to an instance, navigated to a collection and sampled schema
36+
this.SchemaStore.handleSchemaShare();
37+
});
38+
it('copies to the clipboard', function() {
39+
expect(this.clipboardSpy).to.have.been.calledWith('null');
40+
});
41+
it('displays an informative message box', function() {
42+
expect(this.messageBoxSpy).to.have.been.calledWith(null, {
43+
buttons: ['OK'],
44+
detail: 'The schema definition of ' +
45+
'undefined' +
46+
' has been copied to your clipboard in JSON format.',
47+
icon: COMPASS_ICON_PATH,
48+
message: 'Share Schema',
49+
type: 'info'
50+
});
51+
});
52+
});
53+
});

test/unit/icon.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var assert = require('assert');
2+
var icon = require('../../src/icon');
3+
4+
describe('icon', function() {
5+
it('should be a non-empty nativeImage', function() {
6+
assert.equal(icon.isEmpty(), false);
7+
});
8+
});

0 commit comments

Comments
 (0)