electron/lib/browser/api/protocol.js

41 lines
1.4 KiB
JavaScript
Raw Normal View History

2016-05-08 16:44:14 +05:30
const app = require('electron').app
const {createProtocolObject, registerStandardSchemes} = process.atomBinding('protocol')
let protocol = null
2016-01-11 18:40:23 -08:00
2016-01-14 10:35:29 -08:00
// Warn about removed APIs.
var logAndThrow = function (callback, message) {
console.error(message)
2016-01-11 18:40:23 -08:00
if (callback) {
return callback(new Error(message))
2016-01-11 18:40:23 -08:00
} else {
throw new Error(message)
2016-01-11 18:40:23 -08:00
}
}
2016-01-11 18:40:23 -08:00
2016-05-08 16:44:14 +05:30
exports.registerStandardSchemes = function (schemes) {
if (app.isReady()) {
throw new Error('protocol.registerStandardSchemes should be called before app is ready')
}
registerStandardSchemes(schemes)
}
2016-01-11 18:40:23 -08:00
2016-05-08 16:44:14 +05:30
app.once('ready', function () {
protocol = createProtocolObject()
// Be compatible with old APIs.
protocol.registerProtocol = function (scheme, handler, callback) {
return logAndThrow(callback, 'registerProtocol API has been replaced by the register[File/Http/Buffer/String]Protocol API family, please switch to the new APIs.')
}
2016-01-11 18:40:23 -08:00
2016-05-08 16:44:14 +05:30
protocol.isHandledProtocol = function (scheme, callback) {
return logAndThrow(callback, 'isHandledProtocol API has been replaced by isProtocolHandled.')
}
protocol.interceptProtocol = function (scheme, handler, callback) {
return logAndThrow(callback, 'interceptProtocol API has been replaced by the intercept[File/Http/Buffer/String]Protocol API family, please switch to the new APIs.')
}
2016-01-11 18:40:23 -08:00
2016-05-08 16:44:14 +05:30
for (let method in protocol) {
exports[method] = protocol[method].bind(protocol)
}
})