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