delay protocol object creation

This commit is contained in:
deepak1556 2016-05-08 16:44:14 +05:30
parent 9c71c9fa6a
commit 70dac71639
4 changed files with 52 additions and 85 deletions

View file

@ -1,4 +1,6 @@
const protocol = process.atomBinding('protocol').protocol
const app = require('electron').app
const {createProtocolObject, registerStandardSchemes} = process.atomBinding('protocol')
let protocol = null
// Warn about removed APIs.
var logAndThrow = function (callback, message) {
@ -10,16 +12,29 @@ var logAndThrow = function (callback, message) {
}
}
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.')
exports.registerStandardSchemes = function (schemes) {
if (app.isReady()) {
throw new Error('protocol.registerStandardSchemes should be called before app is ready')
}
registerStandardSchemes(schemes)
}
protocol.isHandledProtocol = function (scheme, callback) {
return logAndThrow(callback, 'isHandledProtocol API has been replaced by isProtocolHandled.')
}
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.')
}
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.')
}
protocol.isHandledProtocol = function (scheme, callback) {
return logAndThrow(callback, 'isHandledProtocol API has been replaced by isProtocolHandled.')
}
module.exports = protocol
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.')
}
for (let method in protocol) {
exports[method] = protocol[method].bind(protocol)
}
})