Do not access default session before app is ready
This commit is contained in:
parent
fcd3357fb8
commit
45500701f1
1 changed files with 10 additions and 2 deletions
|
@ -1,4 +1,4 @@
|
|||
const {session} = require('electron')
|
||||
const {app, session} = require('electron')
|
||||
|
||||
// Global protocol APIs.
|
||||
module.exports = process.atomBinding('protocol')
|
||||
|
@ -6,10 +6,18 @@ module.exports = process.atomBinding('protocol')
|
|||
// Fallback protocol APIs of default session.
|
||||
Object.setPrototypeOf(module.exports, new Proxy({}, {
|
||||
get (target, property) {
|
||||
return (...args) => session.defaultSession.protocol[property](...args)
|
||||
if (!app.isReady()) return
|
||||
|
||||
const protocol = session.defaultSession.protocol
|
||||
if (!protocol.hasOwnProperty(property)) return
|
||||
|
||||
// Returning a native function directly would throw error.
|
||||
return (...args) => protocol[property](...args)
|
||||
},
|
||||
|
||||
ownKeys () {
|
||||
if (!app.isReady()) return []
|
||||
|
||||
return Object.getOwnPropertyNames(session.defaultSession.protocol)
|
||||
},
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue