Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zhu-xiaoming opened this issue Jun 21, 2021 · 0 comments
Open

Comments

@zhu-xiaoming
Copy link

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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant