2016-07-12 10:39:06 +00:00
|
|
|
const {app, session} = require('electron')
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-07-12 10:27:15 +00:00
|
|
|
// Global protocol APIs.
|
|
|
|
module.exports = process.atomBinding('protocol')
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-07-12 10:27:15 +00:00
|
|
|
// Fallback protocol APIs of default session.
|
|
|
|
Object.setPrototypeOf(module.exports, new Proxy({}, {
|
|
|
|
get (target, property) {
|
2016-07-12 10:39:06 +00:00
|
|
|
if (!app.isReady()) return
|
|
|
|
|
|
|
|
const protocol = session.defaultSession.protocol
|
|
|
|
if (!protocol.hasOwnProperty(property)) return
|
|
|
|
|
|
|
|
// Returning a native function directly would throw error.
|
|
|
|
return (...args) => protocol[property](...args)
|
2016-07-12 10:27:15 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
ownKeys () {
|
2016-07-12 10:39:06 +00:00
|
|
|
if (!app.isReady()) return []
|
|
|
|
|
2016-07-12 10:27:15 +00:00
|
|
|
return Object.getOwnPropertyNames(session.defaultSession.protocol)
|
|
|
|
},
|
2016-06-16 23:23:08 +00:00
|
|
|
|
2016-07-12 10:27:15 +00:00
|
|
|
getOwnPropertyDescriptor (target) {
|
|
|
|
return { configurable: true, enumerable: true }
|
|
|
|
}
|
|
|
|
}))
|