From c61b27ba5cbcfe3b6069642612f329d3c044ae87 Mon Sep 17 00:00:00 2001 From: BoykoAlex Date: Mon, 12 Mar 2018 20:53:38 -0400 Subject: [PATCH 1/2] Support `atom` protocol links when links are handled --- spec/window-event-handler-spec.js | 21 +++++++++++++++++++-- src/window-event-handler.js | 8 ++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/spec/window-event-handler-spec.js b/spec/window-event-handler-spec.js index 2891aa2db..b5000388c 100644 --- a/spec/window-event-handler-spec.js +++ b/spec/window-event-handler-spec.js @@ -61,7 +61,7 @@ describe('WindowEventHandler', () => { }) ) - describe('when a link is clicked', () => + describe('when a link is clicked', () => { it('opens the http/https links in an external application', () => { const {shell} = require('electron') spyOn(shell, 'openExternal') @@ -93,7 +93,24 @@ describe('WindowEventHandler', () => { windowEventHandler.handleLinkClick(fakeEvent) expect(shell.openExternal).not.toHaveBeenCalled() }) - ) + + it('opens the "atom://" links with URL handler', () => { + const uriHandler = windowEventHandler.atomEnvironment.uriHandlerRegistry + expect(uriHandler).toBeDefined() + spyOn(uriHandler, 'handleURI') + + const link = document.createElement('a') + const linkChild = document.createElement('span') + link.appendChild(linkChild) + link.href = 'atom://github.com' + jasmine.attachToDOM(link) + const fakeEvent = {target: linkChild, currentTarget: link, preventDefault: () => {}} + + windowEventHandler.handleLinkClick(fakeEvent) + expect(uriHandler.handleURI).toHaveBeenCalled() + expect(uriHandler.handleURI.argsForCall[0][0]).toBe('atom://github.com') + }) + }) describe('when a form is submitted', () => it("prevents the default so that the window's URL isn't changed", () => { diff --git a/src/window-event-handler.js b/src/window-event-handler.js index da735294e..abb01a9ea 100644 --- a/src/window-event-handler.js +++ b/src/window-event-handler.js @@ -242,8 +242,12 @@ class WindowEventHandler { handleLinkClick (event) { event.preventDefault() const uri = event.currentTarget && event.currentTarget.getAttribute('href') - if (uri && (uri[0] !== '#') && /^https?:\/\//.test(uri)) { - this.applicationDelegate.openExternal(uri) + if (uri && uri[0] !== '#') { + if (/^https?:\/\//.test(uri)) { + this.applicationDelegate.openExternal(uri) + } else if (uri.startsWith('atom://')) { + this.atomEnvironment.uriHandlerRegistry.handleURI(uri); + } } } From 62d9d02f979dcc6dd5725c93edda0b40504fd657 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Thu, 26 Apr 2018 10:28:14 -0400 Subject: [PATCH 2/2] Fix linter error --- src/window-event-handler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/window-event-handler.js b/src/window-event-handler.js index abb01a9ea..6d927e76e 100644 --- a/src/window-event-handler.js +++ b/src/window-event-handler.js @@ -246,7 +246,7 @@ class WindowEventHandler { if (/^https?:\/\//.test(uri)) { this.applicationDelegate.openExternal(uri) } else if (uri.startsWith('atom://')) { - this.atomEnvironment.uriHandlerRegistry.handleURI(uri); + this.atomEnvironment.uriHandlerRegistry.handleURI(uri) } } }