28 lines
764 B
JavaScript
28 lines
764 B
JavaScript
const {EventEmitter} = require('events')
|
|
const {app} = require('electron')
|
|
const {fromPartition, _setWrapSession} = process.atomBinding('session')
|
|
|
|
// Public API.
|
|
Object.defineProperties(exports, {
|
|
defaultSession: {
|
|
enumerable: true,
|
|
get () { return fromPartition('') }
|
|
},
|
|
fromPartition: {
|
|
enumerable: true,
|
|
value: fromPartition
|
|
}
|
|
})
|
|
|
|
const sessions = []
|
|
|
|
// Wraps native Session class.
|
|
_setWrapSession(function (session) {
|
|
// Session is an EventEmitter.
|
|
Object.setPrototypeOf(session, EventEmitter.prototype)
|
|
app.emit('session-created', session)
|
|
|
|
// The Sessions should never be garbage collected, since the common pattern is
|
|
// to use partition strings, instead of using the Session object directly.
|
|
sessions.push(session)
|
|
})
|