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