From e8cd4bf43107ff8dd40c3fccef2c81772780a947 Mon Sep 17 00:00:00 2001 From: hansonw Date: Tue, 16 May 2017 11:37:53 -0700 Subject: [PATCH] Fix the atom:// URL handler for real (with tests this time) --- .../packages/package-with-url-main/index.js | 4 ++++ .../package-with-url-main/package.json | 5 +++++ spec/main-process/atom-application.test.js | 21 +++++++++++++++++++ src/main-process/atom-application.coffee | 2 +- 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/packages/package-with-url-main/index.js create mode 100644 spec/fixtures/packages/package-with-url-main/package.json diff --git a/spec/fixtures/packages/package-with-url-main/index.js b/spec/fixtures/packages/package-with-url-main/index.js new file mode 100644 index 000000000..857963dd0 --- /dev/null +++ b/spec/fixtures/packages/package-with-url-main/index.js @@ -0,0 +1,4 @@ +module.exports = function initialize() { + global.reachedUrlMain = true; + return Promise.resolve(); +}; diff --git a/spec/fixtures/packages/package-with-url-main/package.json b/spec/fixtures/packages/package-with-url-main/package.json new file mode 100644 index 000000000..c0e16a57f --- /dev/null +++ b/spec/fixtures/packages/package-with-url-main/package.json @@ -0,0 +1,5 @@ +{ + "name": "package-with-url-main", + "version": "1.0.0", + "urlMain": "./index.js" +} diff --git a/spec/main-process/atom-application.test.js b/spec/main-process/atom-application.test.js index 0ae2dc195..5929b6ac9 100644 --- a/spec/main-process/atom-application.test.js +++ b/spec/main-process/atom-application.test.js @@ -437,6 +437,27 @@ describe('AtomApplication', function () { assert.deepEqual(await getTreeViewRootDirectories(window2), [dirB]) }) }) + + describe('when opening atom:// URLs', function () { + it('loads the urlMain file in a new window', async function () { + const packagePath = path.join(__dirname, '..', 'fixtures', 'packages', 'package-with-url-main') + const packagesDirPath = path.join(process.env.ATOM_HOME, 'packages') + fs.mkdirSync(packagesDirPath) + fs.symlinkSync(packagePath, path.join(packagesDirPath, 'package-with-url-main'), 'junction') + + const atomApplication = buildAtomApplication() + const launchOptions = parseCommandLine([]) + launchOptions.urlsToOpen = ['atom://package-with-url-main/test'] + let windows = atomApplication.launch(launchOptions) + await windows[0].loadedPromise + + let reached = await evalInWebContents(windows[0].browserWindow.webContents, function (sendBackToMainProcess) { + sendBackToMainProcess(global.reachedUrlMain) + }) + assert.equal(reached, true); + windows[0].close(); + }) + }) }) describe('before quitting', function () { diff --git a/src/main-process/atom-application.coffee b/src/main-process/atom-application.coffee index b2bfa560b..b7b59b95c 100644 --- a/src/main-process/atom-application.coffee +++ b/src/main-process/atom-application.coffee @@ -644,7 +644,7 @@ class AtomApplication openUrl: ({urlToOpen, devMode, safeMode, env}) -> unless @packages? PackageManager = require '../package-manager' - @packages = new PackageManager() + @packages = new PackageManager({}) @packages.initialize configDirPath: process.env.ATOM_HOME devMode: devMode