8396a2d504
* feat: promisify the Cookie API * chore: update specs to test promisified cookies * chore: add deprecate wrapper for cookie callback API * docs: update docs to cookie promise changes * chore: remove redundant namespace use * docs: improve cookie example * docs: restore docs for cookie callback API * chore: restore cookie callback tests * fix: syntax of cookie promise return types
40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
'use strict'
|
|
|
|
const { EventEmitter } = require('events')
|
|
const { app, deprecate } = require('electron')
|
|
const { Session, Cookies } = process.atomBinding('session')
|
|
const realFromPartition = process.atomBinding('session').fromPartition
|
|
|
|
const wrappedSymbol = Symbol('wrapped-deprecate')
|
|
const fromPartition = (partition) => {
|
|
const session = realFromPartition(partition)
|
|
if (!session[wrappedSymbol]) {
|
|
session[wrappedSymbol] = true
|
|
const { cookies } = session
|
|
cookies.flushStore = deprecate.promisify(cookies.flushStore, 0)
|
|
cookies.get = deprecate.promisify(cookies.get, 1)
|
|
cookies.remove = deprecate.promisify(cookies.remove, 2)
|
|
cookies.set = deprecate.promisify(cookies.set, 1)
|
|
}
|
|
return session
|
|
}
|
|
|
|
// Public API.
|
|
Object.defineProperties(exports, {
|
|
defaultSession: {
|
|
enumerable: true,
|
|
get () { return fromPartition('') }
|
|
},
|
|
fromPartition: {
|
|
enumerable: true,
|
|
value: fromPartition
|
|
}
|
|
})
|
|
|
|
Object.setPrototypeOf(Session.prototype, EventEmitter.prototype)
|
|
Object.setPrototypeOf(Cookies.prototype, EventEmitter.prototype)
|
|
|
|
Session.prototype._init = function () {
|
|
this.protocol.isProtocolHandled = deprecate.promisify(this.protocol.isProtocolHandled, 2)
|
|
app.emit('session-created', this)
|
|
}
|