electron-protocols
Manage file protocols in Electron
Install
npm install --save electron-protocols
Run the example:
npm start example
Usage
First register your protocol in main process before app.on('ready')
:
main process
const protocols = ;protocols;
Then you can use protocols.path
to map your protocol to a file path:
renderer/main process
const protocols = ; // return the module in ${app.getAppPath()}/my/module.jsconst myModule = ;
Also, you are free to use protocol in html in renderer process:
FAQ
What is the benefit to register again in renderer process?
It will speed up the search of protocols.path
by skip calling the remote (ipc-sync) functions.
API
Methods
protocols.register(protocol, fn)
protocol
stringfn
function
Register a protocol so that {@link Editor.url} can use it to convert an url to the filesystem path.
The fn
accept an url Object via url.parse
Example:
const app = ;const protocols = ;const path = ; protocols;
protocols.path(url)
url
string
Convert a url by its protocol to a filesystem path. This function is useful when you try to get
some internal file. You can use protocols.register
to register and map your filesystem path to url.
Example:
// it will return "{your-app-path}/foobar/foobar.js"protocols;
protocols.basepath(base)
base
string
A function help you register protocol by base
path you provide.
Example:
protocols;
License
MIT © 2017 Johnny Wu