зеркало из https://github.com/electron/electron.git
Move session-created event to app
This follows the convention of other *-created events.
This commit is contained in:
Родитель
45500701f1
Коммит
d739d8772c
|
@ -1,13 +1,12 @@
|
|||
const {EventEmitter} = require('events')
|
||||
const electron = require('electron')
|
||||
const {app} = require('electron')
|
||||
const bindings = process.atomBinding('session')
|
||||
|
||||
const PERSIST_PREFIX = 'persist:'
|
||||
const Session = new EventEmitter()
|
||||
|
||||
// Wrapper of binding.fromPartition that checks for ready event.
|
||||
const fromPartition = function (partition, persist) {
|
||||
if (!electron.app.isReady()) {
|
||||
if (!app.isReady()) {
|
||||
throw new Error('session module can only be used when app is ready')
|
||||
}
|
||||
|
||||
|
@ -15,7 +14,7 @@ const fromPartition = function (partition, persist) {
|
|||
}
|
||||
|
||||
// Returns the Session from |partition| string.
|
||||
Session.fromPartition = function (partition = '') {
|
||||
exports.fromPartition = function (partition = '') {
|
||||
if (partition === '') return exports.defaultSession
|
||||
|
||||
if (partition.startsWith(PERSIST_PREFIX)) {
|
||||
|
@ -26,7 +25,7 @@ Session.fromPartition = function (partition = '') {
|
|||
}
|
||||
|
||||
// Returns the default session.
|
||||
Object.defineProperty(Session, 'defaultSession', {
|
||||
Object.defineProperty(exports, 'defaultSession', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return fromPartition('', false)
|
||||
|
@ -36,9 +35,7 @@ Object.defineProperty(Session, 'defaultSession', {
|
|||
const wrapSession = function (session) {
|
||||
// Session is an EventEmitter.
|
||||
Object.setPrototypeOf(session, EventEmitter.prototype)
|
||||
Session.emit('session-created', session)
|
||||
app.emit('session-created', session)
|
||||
}
|
||||
|
||||
bindings._setWrapSession(wrapSession)
|
||||
|
||||
module.exports = Session
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const {app, ipcMain, session, webContents, BrowserWindow} = require('electron')
|
||||
const {app, ipcMain, webContents, BrowserWindow} = require('electron')
|
||||
const {getAllWebContents} = process.atomBinding('web_contents')
|
||||
const renderProcessPreferences = process.atomBinding('render_process_preferences').forAllWebContents()
|
||||
|
||||
|
@ -333,7 +333,7 @@ app.once('ready', function () {
|
|||
}
|
||||
})
|
||||
}
|
||||
session.on('session-created', function (ses) {
|
||||
app.on('session-created', function (ses) {
|
||||
ses.protocol.registerBufferProtocol('chrome-extension', chromeExtensionHandler, function (error) {
|
||||
if (error) {
|
||||
console.error(`Unable to register chrome-extension protocol: ${error}`)
|
||||
|
|
Загрузка…
Ссылка в новой задаче