electron/lib/browser/api/protocol.ts
Felix Rieseberg 5581990d78 build: Update TypeScript, use @typescript-eslint (#17251)
* build: Update TypeScript to v3.3

* build: Update TypeScript, use @typescript-eslint
2019-03-07 12:56:02 -08:00

29 lines
836 B
TypeScript

import { app, session } from 'electron'
// Global protocol APIs.
const protocol = process.atomBinding('protocol')
// Fallback protocol APIs of default session.
Object.setPrototypeOf(protocol, new Proxy({}, {
get (_target, property) {
if (!app.isReady()) return
const protocol = session.defaultSession!.protocol
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