protocol.ts 840 B

1234567891011121314151617181920212223242526272829
  1. import { app, session } from 'electron'
  2. // Global protocol APIs.
  3. const protocol = process.electronBinding('protocol')
  4. // Fallback protocol APIs of default session.
  5. Object.setPrototypeOf(protocol, 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: any[]) => (protocol[property as keyof Electron.Protocol] as Function)(...args)
  12. },
  13. ownKeys () {
  14. if (!app.isReady()) return []
  15. return Object.getOwnPropertyNames(Object.getPrototypeOf(session.defaultSession!.protocol))
  16. },
  17. getOwnPropertyDescriptor () {
  18. return { configurable: true, enumerable: true }
  19. }
  20. }))
  21. export default protocol