From e5aad3b9d79c0383b4af15c128fd8d0b62ae7898 Mon Sep 17 00:00:00 2001 From: Lucas Hrabovsky Date: Tue, 24 Jan 2017 13:00:44 -0500 Subject: [PATCH 1/2] COMPASS-586: Improve Linux appearance (logo in popups/about box, ...) --- src/app/connect/index.js | 2 ++ src/icon.js | 19 +++++++++++++++++++ .../schema/lib/store/index.js | 3 +++ src/main/window-manager.js | 17 +++++++++++++---- test/unit/icon.test.js | 8 ++++++++ 5 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 src/icon.js create mode 100644 test/unit/icon.test.js diff --git a/src/app/connect/index.js b/src/app/connect/index.js index 3a78f9dff8f..d7b45f1cf45 100644 --- a/src/app/connect/index.js +++ b/src/app/connect/index.js @@ -16,6 +16,7 @@ var dialog = remote.dialog; var Clipboard = remote.clipboard; var BrowserWindow = remote.BrowserWindow; var metrics = require('mongodb-js-metrics')(); +var COMPASS_ICON = require('../../icon'); var debug = require('debug')('mongodb-compass:connect:index'); @@ -331,6 +332,7 @@ var ConnectView = View.extend({ // ask user if Compass should use it to fill out form dialog.showMessageBox(BrowserWindow.getFocusedWindow(), { type: 'info', + icon: COMPASS_ICON, message: 'MongoDB connection string detected', detail: 'Compass detected a MongoDB connection string in your ' + 'clipboard. Do you want to use the connection string to ' diff --git a/src/icon.js b/src/icon.js new file mode 100644 index 00000000000..9f5325ad201 --- /dev/null +++ b/src/icon.js @@ -0,0 +1,19 @@ +var path = require('path'); +var COMPASS_ICON = path.join(__dirname, 'app', 'images', 'compass-dialog-icon.png'); +var nativeImage = require('electron').nativeImage; + +/** + * Convenience for getting the app icon to customize native UI components + * via electron. + * + * @example + * ```javascript + * var icon = require('./icon'); + * var dialog = require('electron').dialog; + * dialog.showMessageBox({icon: icon, message: 'I have a nice Compass icon.'}); + * ``` + * + * @see https://jira.mongodb.org/browse/COMPASS-586 + */ +module.exports = nativeImage.createFromPath(COMPASS_ICON); +module.exports.path = COMPASS_ICON; diff --git a/src/internal-packages/schema/lib/store/index.js b/src/internal-packages/schema/lib/store/index.js index bfb9bcd425d..4a450e5ec21 100644 --- a/src/internal-packages/schema/lib/store/index.js +++ b/src/internal-packages/schema/lib/store/index.js @@ -7,6 +7,8 @@ const schemaStream = require('mongodb-schema').stream; const toNS = require('mongodb-ns'); const ReadPreference = require('mongodb').ReadPreference; +const COMPASS_ICON = require('../../../../icon'); + /** * The default read preference. */ @@ -72,6 +74,7 @@ const SchemaStore = Reflux.createStore({ dialog.showMessageBox(BrowserWindow.getFocusedWindow(), { type: 'info', + icon: COMPASS_ICON, message: 'Share Schema', detail: detail, buttons: ['OK'] diff --git a/src/main/window-manager.js b/src/main/window-manager.js index 07feff748e6..420cef0f2a1 100644 --- a/src/main/window-manager.js +++ b/src/main/window-manager.js @@ -14,6 +14,7 @@ var debug = require('debug')('mongodb-compass:electron:window-manager'); var dialog = electron.dialog; var path = require('path'); var ipc = require('hadron-ipc'); +var COMPASS_ICON = require('../icon'); /** * When running in electron, we're in `/src/main`. @@ -118,13 +119,21 @@ var createWindow = module.exports.create = function(opts) { width: DEFAULT_WIDTH, height: DEFAULT_HEIGHT, minwidth: MIN_WIDTH, - url: DEFAULT_URL + url: DEFAULT_URL, + /** + * On Windows and macOS, this will be set automatically to the optimal + * app icon. Only on Linux do we need to set this explictly. + * + * @see https://jira.mongodb.org/browse/COMPASS-586 + */ + icon: process.platform === 'linux' ? COMPASS_ICON : undefined }); debug('creating new window: ' + opts.url); var _window = new BrowserWindow({ width: opts.width, height: opts.height, + icon: opts.icon, 'min-width': opts.minwidth, 'web-preferences': { 'subpixel-font-scaling': true, @@ -164,9 +173,9 @@ function showConnectWindow() { function showAboutDialog() { dialog.showMessageBox({ type: 'info', - title: 'About MongoDB Compass', - icon: path.join(RESOURCES, 'images', 'compass-dialog-icon.png'), - message: 'MongoDB Compass', + title: 'About ' + app.getName(), + icon: COMPASS_ICON, + message: app.getName(), detail: 'Version ' + app.getVersion(), buttons: ['OK'] }); diff --git a/test/unit/icon.test.js b/test/unit/icon.test.js new file mode 100644 index 00000000000..2744a722010 --- /dev/null +++ b/test/unit/icon.test.js @@ -0,0 +1,8 @@ +var assert = require('assert'); +var icon = require('../../src/icon'); + +describe('icon', function() { + it('should be a non-empty nativeImage', function() { + assert.equals(icon.isEmpty(), false); + }); +}); From 6dc621c285558b211ff9e59dd5cd458fcf47ac9a Mon Sep 17 00:00:00 2001 From: Peter Schmidt Date: Wed, 25 Jan 2017 17:57:24 +1100 Subject: [PATCH 2/2] assert.equals => assert.equal --- test/unit/icon.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/icon.test.js b/test/unit/icon.test.js index 2744a722010..5c278b40f23 100644 --- a/test/unit/icon.test.js +++ b/test/unit/icon.test.js @@ -3,6 +3,6 @@ var icon = require('../../src/icon'); describe('icon', function() { it('should be a non-empty nativeImage', function() { - assert.equals(icon.isEmpty(), false); + assert.equal(icon.isEmpty(), false); }); });