electron/lib/browser/api/protocol.ts

30 lines
840 B
TypeScript
Raw Normal View History

import { app, session } from 'electron'
2016-01-12 02:40:23 +00:00
// Global protocol APIs.
const protocol = process.electronBinding('protocol')
2016-01-12 02:40:23 +00:00
// Fallback protocol APIs of default session.
Object.setPrototypeOf(protocol, new Proxy({}, {
get (_target, property) {
if (!app.isReady()) return
const protocol = session.defaultSession!.protocol
2016-08-02 12:02:28 +00:00
if (!Object.getPrototypeOf(protocol).hasOwnProperty(property)) return
// Returning a native function directly would throw error.
return (...args: any[]) => (protocol[property as keyof Electron.Protocol] as Function)(...args)
},
ownKeys () {
if (!app.isReady()) return []
return Object.getOwnPropertyNames(Object.getPrototypeOf(session.defaultSession!.protocol))
},
getOwnPropertyDescriptor () {
return { configurable: true, enumerable: true }
}
}))
export default protocol