kevgski
Thank you!
I set a sidebar with this discussion.
https://sketchplugins.com/d/2221-sidebar-error-in-sketch-v70/9
But the difference is views owned by the stack view is not NSButton,is webview create by sketch-module-web-view
import Browser from 'sketch-module-web-view'
const stackView = NSStackView.alloc().init()
stackView.setSpacing(0)
stackView.setFlipped(true)
stackView.setOrientation(1)
stackView.setFrame(NSMakeRect(0, 0, SIDEBAR_WIDTH, 0))
const browserWindow = new Browser(options)
const webview = browserWindow.getNativeWebViewHandle()
stackView.addView_inGravity(webview, 1)
const controller = NSViewController.alloc().init()
controller.setView(stackView)
const splitViewItem = NSSplitViewItem.splitViewItemWithViewController(controller)
document.splitViewController().insertSplitViewItem_atIndex(splitViewItem, 2)
The problem is sidebar can't respond to the first click when the Sketch application non-active.
My solution is add windowDidBecomeKey delegate in current document.
const delegateClass = new MochaJSDelegate({
'windowDidBecomeKey:': function (notification) {
const object = notification.object()
const className = object?.className()
const event = object?.currentEvent()
if (className == 'MSDocumentWindow' && event?.type() === NSEventTypeLeftMouseDown) {
const webview = browserWindow.getNativeWebViewHandle()
const sketchAppFrame = NSApplication.sharedApplication().mainWindow()?.frame()
const screenPoint = NSEvent.mouseLocation()
const screenFrame = NSScreen.mainScreen().frame()
const screenHeight = NSHeight(screenFrame)
const screenOriginY = screenFrame.origin.y
const point = webview.convertPoint_fromView(screenPoint, null)
point.x = point.x - ((sketchAppFrame?.origin?.x) ?? 0)
point.y = point.y + ((sketchAppFrame?.origin?.y) ?? 0)
webContents.executeJavaScript(`
const el = document.elementFromPoint(point.x}, point.y)
...
el.click()
...
`)
}
}
})
But here is a new problem. When I got the y-axis coordinate transformed by the webview.convertPoint_fromView(screenPoint, null), there is always a superfluous height of the toolbar. So I’d like to remove the height of the toolbar.
I reckon I did not set the correct constraints.