feat: add app.getApplicationNameForProtocol API (#20399)

* Add GetApplicationNameForProtocol.

* Fix Windows implementation.

* Fix up test.

* Add documentation.

* Implement for real on Linux using xdg-mime.

Also ensure we allow blocking calls here to avoid errant DCHECKing.

* Improve docs for Linux.

* Clean up tests.

* Add a note about not relying on the precise format.

* Update docs/api/app.md

Co-Authored-By: Shelley Vohr <codebytere@github.com>

* Remove needless `done()`s from tests.

* Use vector list initialization.

* Add a simple test for isDefaultProtocolClient.

* Remove unneeded include and skip a test on Linux CI.

* We no longer differentiate between CI and non-CI test runs.
This commit is contained in:
Andrew MacDonald 2019-11-06 17:50:33 -08:00 committed by Shelley Vohr
parent 24939e8fa4
commit 9b01bb00d2
7 changed files with 183 additions and 20 deletions

View file

@ -846,6 +846,40 @@ describe('app module', () => {
})
})
})
it('sets the default client such that getApplicationNameForProtocol returns Electron', () => {
app.setAsDefaultProtocolClient(protocol)
expect(app.getApplicationNameForProtocol(`${protocol}://`)).to.equal('Electron')
})
})
describe('getApplicationNameForProtocol()', () => {
it('returns application names for common protocols', function () {
// We can't expect particular app names here, but these protocols should
// at least have _something_ registered. Except on our Linux CI
// environment apparently.
if (process.platform === 'linux') {
this.skip()
}
const protocols = [
'http://',
'https://'
]
protocols.forEach((protocol) => {
expect(app.getApplicationNameForProtocol(protocol)).to.not.equal('')
})
})
it('returns an empty string for a bogus protocol', () => {
expect(app.getApplicationNameForProtocol('bogus-protocol://')).to.equal('')
})
})
describe('isDefaultProtocolClient()', () => {
it('returns false for a bogus protocol', () => {
expect(app.isDefaultProtocolClient('bogus-protocol://')).to.equal(false)
})
})
describe('app launch through uri', () => {