Move check of isReady to native code
This commit is contained in:
parent
d739d8772c
commit
06a41cedab
2 changed files with 16 additions and 15 deletions
|
@ -1,18 +1,9 @@
|
|||
const {EventEmitter} = require('events')
|
||||
const {app} = require('electron')
|
||||
const bindings = process.atomBinding('session')
|
||||
const {fromPartition, _setWrapSession} = process.atomBinding('session')
|
||||
|
||||
const PERSIST_PREFIX = 'persist:'
|
||||
|
||||
// Wrapper of binding.fromPartition that checks for ready event.
|
||||
const fromPartition = function (partition, persist) {
|
||||
if (!app.isReady()) {
|
||||
throw new Error('session module can only be used when app is ready')
|
||||
}
|
||||
|
||||
return bindings.fromPartition(partition, persist)
|
||||
}
|
||||
|
||||
// Returns the Session from |partition| string.
|
||||
exports.fromPartition = function (partition = '') {
|
||||
if (partition === '') return exports.defaultSession
|
||||
|
@ -32,10 +23,9 @@ Object.defineProperty(exports, 'defaultSession', {
|
|||
}
|
||||
})
|
||||
|
||||
const wrapSession = function (session) {
|
||||
// Wraps native Session class.
|
||||
_setWrapSession(function (session) {
|
||||
// Session is an EventEmitter.
|
||||
Object.setPrototypeOf(session, EventEmitter.prototype)
|
||||
app.emit('session-created', session)
|
||||
}
|
||||
|
||||
bindings._setWrapSession(wrapSession)
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue