protocol.js 775 B

123456789101112131415161718192021222324252627
  1. const {app, session} = require('electron')
  2. // Global protocol APIs.
  3. module.exports = process.atomBinding('protocol')
  4. // Fallback protocol APIs of default session.
  5. Object.setPrototypeOf(module.exports, new Proxy({}, {
  6. get (target, property) {
  7. if (!app.isReady()) return
  8. const protocol = session.defaultSession.protocol
  9. if (!Object.getPrototypeOf(protocol).hasOwnProperty(property)) return
  10. // Returning a native function directly would throw error.
  11. return (...args) => protocol[property](...args)
  12. },
  13. ownKeys () {
  14. if (!app.isReady()) return []
  15. return Object.getOwnPropertyNames(Object.getPrototypeOf(session.defaultSession.protocol))
  16. },
  17. getOwnPropertyDescriptor (target) {
  18. return { configurable: true, enumerable: true }
  19. }
  20. }))