2016-05-08 11:14:14 +00:00
const app = require ( 'electron' ) . app
const { createProtocolObject , registerStandardSchemes } = process . atomBinding ( 'protocol' )
let protocol = null
2016-01-12 02:40:23 +00:00
2016-01-14 18:35:29 +00:00
// Warn about removed APIs.
2016-03-24 20:15:04 +00:00
var logAndThrow = function ( callback , message ) {
console . error ( message )
2016-01-12 02:40:23 +00:00
if ( callback ) {
2016-03-24 20:15:04 +00:00
return callback ( new Error ( message ) )
2016-01-12 02:40:23 +00:00
} else {
2016-03-24 20:15:04 +00:00
throw new Error ( message )
2016-01-12 02:40:23 +00:00
}
2016-03-24 20:15:04 +00:00
}
2016-01-12 02:40:23 +00:00
2016-05-08 11:14:14 +00:00
exports . registerStandardSchemes = function ( schemes ) {
if ( app . isReady ( ) ) {
throw new Error ( 'protocol.registerStandardSchemes should be called before app is ready' )
}
registerStandardSchemes ( schemes )
2016-03-24 20:15:04 +00:00
}
2016-01-12 02:40:23 +00:00
2016-05-08 11:14:14 +00:00
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-12 02:40:23 +00:00
2016-05-08 11:14:14 +00:00
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-12 02:40:23 +00:00
2016-05-08 11:14:14 +00:00
for ( let method in protocol ) {
exports [ method ] = protocol [ method ] . bind ( protocol )
}
} )