From 3a6d6ff0083408588af10a8931f881d7ee134622 Mon Sep 17 00:00:00 2001 From: Kishan Bagaria Date: Thu, 8 Sep 2022 00:15:09 +0530 Subject: [PATCH] docs: improve registerFileProtocol example (#35580) * improve registerFileProtocol example * link ProtocolResponse * kick lint --- docs/api/protocol.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/api/protocol.md b/docs/api/protocol.md index 7a2b33401619..8b0d2fbc8990 100644 --- a/docs/api/protocol.md +++ b/docs/api/protocol.md @@ -10,11 +10,12 @@ An example of implementing a protocol that has the same effect as the ```javascript const { app, protocol } = require('electron') const path = require('path') +const url = require('url') app.whenReady().then(() => { protocol.registerFileProtocol('atom', (request, callback) => { - const url = request.url.substr(7) - callback({ path: path.normalize(`${__dirname}/${url}`) }) + const filePath = url.fileURLToPath('file://' + request.url.slice('atom://'.length)) + callback(filePath) }) }) ``` @@ -175,7 +176,7 @@ property. * `handler` Function * `request` [ProtocolRequest](structures/protocol-request.md) * `callback` Function - * `response` ProtocolResponse + * `response` [ProtocolResponse](structures/protocol-response.md) Returns `boolean` - Whether the protocol was successfully registered