const electron = require('electron');
const app = electron.app;
const path = require('path');
app.on('ready', function() {
var protocol = electron.protocol;
protocol.registerFileProtocol('atom', function(request, callback) {
var url = request.url.substr(7);
callback({path: path.normalize(__dirname + '/' + url)});
}, function (error) {
if (error)
console.error('Failed to register protocol')
});
});
方法
protocol.registerStandardSchemes(schemes)
schemes
Array - 将一个自定义的方案注册为标准的方案.
protocol.registerServiceWorkerSchemes(schemes)
schemes
Array - 将一个自定义的方案注册为处理 service workers.
protocol.registerFileProtocol(scheme, handler[, completion])
scheme
Stringhandler
Functioncompletion
Function (可选)
request
Objecturl
Stringreferrer
Stringmethod
StringuploadData
Array (可选)
callback
Function
data
Objectbytes
Buffer - 被发送的内容.file
String - 上传的文件路径.
protocol.registerBufferProtocol(scheme, handler[, completion])
scheme
Stringhandler
Functioncompletion
Function (可选)
例子:
protocol.registerBufferProtocol('atom', function(request, callback) {
callback({mimeType: 'text/html', data: new Buffer('<h5>Response</h5>')});
}, function (error) {
if (error)
console.error('Failed to register protocol')
});
protocol.registerStringProtocol(scheme, handler[, completion])
scheme
Stringhandler
Functioncompletion
Function (可选)
protocol.registerHttpProtocol(scheme, handler[, completion])
scheme
Stringhandler
Functioncompletion
Function (可选)
请发表评论