fix docs and spec
This commit is contained in:
parent
0f2ae385ed
commit
9c71c9fa6a
3 changed files with 15 additions and 7 deletions
|
@ -52,7 +52,7 @@ void Protocol::RegisterStandardSchemes(
|
||||||
if (Browser::Get()->is_ready()) {
|
if (Browser::Get()->is_ready()) {
|
||||||
isolate()->ThrowException(v8::Exception::Error(mate::StringToV8(
|
isolate()->ThrowException(v8::Exception::Error(mate::StringToV8(
|
||||||
isolate(),
|
isolate(),
|
||||||
"\"protocol.registerStandardSchemes\" should be called before"
|
"protocol.registerStandardSchemes should be called before"
|
||||||
"app is ready")));
|
"app is ready")));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,11 +7,10 @@ An example of implementing a protocol that has the same effect as the
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const electron = require('electron');
|
const electron = require('electron');
|
||||||
const { app } = electron;
|
const { app, protocol } = electron;
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
app.on('ready', function() {
|
app.on('ready', function() {
|
||||||
const { protocol } = electron;
|
|
||||||
protocol.registerFileProtocol('atom', function(request, callback) {
|
protocol.registerFileProtocol('atom', function(request, callback) {
|
||||||
const url = request.url.substr(7);
|
const url = request.url.substr(7);
|
||||||
callback({path: path.normalize(__dirname + '/' + url)});
|
callback({path: path.normalize(__dirname + '/' + url)});
|
||||||
|
@ -21,9 +20,8 @@ app.on('ready', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
**Note:** All methods unless specified can only be used after the `ready`
|
||||||
**Note:** This module can only be used after the `ready` event in the `app`
|
event in the `app` module is emitted.
|
||||||
module is emitted.
|
|
||||||
|
|
||||||
## Methods
|
## Methods
|
||||||
|
|
||||||
|
@ -35,7 +33,11 @@ The `protocol` module has the following methods:
|
||||||
|
|
||||||
A standard `scheme` adheres to what RFC 3986 calls
|
A standard `scheme` adheres to what RFC 3986 calls
|
||||||
[generic URI syntax](https://tools.ietf.org/html/rfc3986#section-3). This
|
[generic URI syntax](https://tools.ietf.org/html/rfc3986#section-3). This
|
||||||
includes `file:` and `filesystem:`.
|
includes `file:`, `filesystem:`, `http` etc. Registering a scheme as standard, will
|
||||||
|
allow relative and absolute resources to be resolved correctly when served.
|
||||||
|
|
||||||
|
**Note:** This method can only be used before the `ready` event in the
|
||||||
|
`app` module is emitted.
|
||||||
|
|
||||||
### `protocol.registerServiceWorkerSchemes(schemes)`
|
### `protocol.registerServiceWorkerSchemes(schemes)`
|
||||||
|
|
||||||
|
|
|
@ -841,6 +841,12 @@ describe('protocol module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('throws when called after ready event', function () {
|
||||||
|
assert.throws(function () {
|
||||||
|
protocol.registerStandardSchemes(['some-scheme'])
|
||||||
|
}, 'protocol.registerStandardSchemes should be called before app is ready')
|
||||||
|
})
|
||||||
|
|
||||||
it('resolves relative resources', function (done) {
|
it('resolves relative resources', function (done) {
|
||||||
var handler = function (request, callback) {
|
var handler = function (request, callback) {
|
||||||
if (request.url === imageURL) {
|
if (request.url === imageURL) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue