mirror of
https://github.com/electron/electron.git
synced 2026-01-09 15:38:08 -05:00
docs: improve registerFileProtocol example (#35580)
* improve registerFileProtocol example * link ProtocolResponse * kick lint
This commit is contained in:
@@ -10,11 +10,12 @@ An example of implementing a protocol that has the same effect as the
|
|||||||
```javascript
|
```javascript
|
||||||
const { app, protocol } = require('electron')
|
const { app, protocol } = require('electron')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
const url = require('url')
|
||||||
|
|
||||||
app.whenReady().then(() => {
|
app.whenReady().then(() => {
|
||||||
protocol.registerFileProtocol('atom', (request, callback) => {
|
protocol.registerFileProtocol('atom', (request, callback) => {
|
||||||
const url = request.url.substr(7)
|
const filePath = url.fileURLToPath('file://' + request.url.slice('atom://'.length))
|
||||||
callback({ path: path.normalize(`${__dirname}/${url}`) })
|
callback(filePath)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
@@ -175,7 +176,7 @@ property.
|
|||||||
* `handler` Function
|
* `handler` Function
|
||||||
* `request` [ProtocolRequest](structures/protocol-request.md)
|
* `request` [ProtocolRequest](structures/protocol-request.md)
|
||||||
* `callback` Function
|
* `callback` Function
|
||||||
* `response` ProtocolResponse
|
* `response` [ProtocolResponse](structures/protocol-response.md)
|
||||||
|
|
||||||
Returns `boolean` - Whether the protocol was successfully registered
|
Returns `boolean` - Whether the protocol was successfully registered
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user