-
Type: New Feature
-
Resolution: Won't Do
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Connectivity, UI / UX
-
5
This would allow us to add a seamless "Open in Compass" button from the Atlas Connect dialog. Aggregation of my notes for protocol handlers for "mongodb://" and "compass://".
—
Introduction
Protocol handlers are also sometimes referred to as custom URL schemes. For an excellent overview, please read this excellent blog post: How To Create Your Own URL Scheme.
Spotify spotify://, iTunes itmms:// and Intercom intercom:// are just a few examples of protocol handlers in action you may have encountered in the past. If you've ever seen the "External Protocol Request" dialog in Chrome, you've used protocol handlers:
User experience
Atlas short-term
Allows for clicking on mongodb://localhost:27017 -> open compass with connect form pre-filled.
Atlas and docs long-term
See elastic' view in console on all code blocks: https://www.elastic.co/guide/en/elasticsearch/reference/5.0/modules-scripting-painless.html
Use compass://<route> like Atom does for internal app routing instead of location hashes directly.
Implementation
There is a bit of a confusing division when it comes to protocol handlers in electron.
Three parts: OS registration, Electron registration, and protocol request handling
1. OS Registration
Differs by platform. Tells the OS clicks on mongodb:// in Chrome should be routed to Compass.
macOS
Specified at build time and registration is part of the OS's installation process. We already specify for this in Compass master:
{ "protocols": [ {"name": "MongoDB Protocol", "schemes": ["mongodb"]}, {"name": "MongoDB Compass Protocol", "schemes": ["compass"]} ] }
Windows
Unlike macOS, registration is not part of OS installation process. The application is responsible for protocol registration on first-run and on Windows that is done by updating the Windows Registry). For more details, see how webtorrent desktop does windows.
Linux
Like Windows, the application takes responsibility . On Linux, this is done by creating/updating the user's .desktop file. For more details, see how webtorrent desktop does linux
2. Electron registration
The protocol module in electron tells Electron that requests to the mongodb:// protocol in Compass should be routed to Compass.
3. Protocol request handling
app.on('open-file', <callback>) and app.on('open-url', <callback>)
See the Compass mongodb-protocol-handler branch.
var electron = require('electron'); var app = electron.app; var program = require('commander'); var debug = require('nslog'); var open = { urls: [], files: [] }; app.on('will-finish-launching', function() { app.on('open-file', function(event, file) { event.preventDefault(); open.files.push(file); }); app.on('open-url', function(event, url) { event.preventDefault(); open.urls.push(url); }); }); program .version(app.getVersion()) .option('--dev', 'run in development mode'); program .command('[files...]') .action(function(files, opts) { debug('cli', {files: files, opts: opts}); }); function parseCommandLine(argv) { return program.parse(argv); } var shouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory) { return parseCommandLine(commandLine); }) if (shouldQuit) { app.quit(); } app.on('ready', function() { app.setAsDefaultProtocolClient('mongodb'); app.setAsDefaultProtocolClient('compass'); parseCommandLine(process.argv); });
Making it all work as a single user flow
- Code to check if compass installed: See https://github.com/ismailhabib/custom-protocol-detection
- open.spotify.com
- Move Compass tour to .com
- when compass installed open browser to Compass tour like vscode (can also exchange analytics tokens)
- when not installed
- embed an open after install in URL to download which is saved via cookies
- Welcome page on .com can then check this cookie and show "still want to open mongodb://...?"
Further Reading
Web-based Protocol Handlers
- is duplicated by
-
COMPASS-6085 Register Compass as a protocol handler for mongodb://
- Closed
- related to
-
COMPASS-4579 Register Compass as default handler for mongodb:// URLs
- Closed