protocol.js 791 B

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