Skip to content

BrowserWindow.fromId causes the message sent by postmessage to be lost #176

Open
@zhu-xiaoming

Description

@zhu-xiaoming

When the BrowserWindow was created, the previously created BrowserWindow was reused using the formId, which generated a new EventEmitter, but the new EventEmitter did not call setDelegates, resulting in the postMessage of the webview was actually processed by the previously created EventEmitter and not sent to The new EventEmitter, which eventually caused the message to be lost.

function BrowserWindow(options) {
  options = options || {}

  var identifier = options.identifier || String(NSUUID.UUID().UUIDString())
  var threadDictionary = NSThread.mainThread().threadDictionary()

  var existingBrowserWindow = BrowserWindow.fromId(identifier)

  // if we already have a window opened, reuse it
  if (existingBrowserWindow) {
    return existingBrowserWindow
  }

  //...

  buildBrowserAPI(browserWindow, panel, webView)
  buildWebAPI(browserWindow, panel, webView)
  // setDelegates is called here
  setDelegates(browserWindow, panel, webView, options)
}

BrowserWindow.fromId = function (identifier) {
  var threadDictionary = NSThread.mainThread().threadDictionary()
  if (threadDictionary[identifier]) {
    return BrowserWindow.fromPanel(threadDictionary[identifier], identifier)
  }
  return undefined
}

BrowserWindow.fromPanel = function (panel, identifier) {
  // A new EventEmitter is created her
  var browserWindow = new EventEmitter()
  browserWindow.id = identifier

  if (!panel || !panel.contentView) {
    throw new Error('needs to pass an NSPanel')
  }

  // ...

  // But setDelegates is not called here
  buildBrowserAPI(browserWindow, panel, webView)
  buildWebAPI(browserWindow, panel, webView)

  return browserWindow
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions