hxelectron
hxelectron copied to clipboard
Uncaught TypeError: Cannot read property 'TouchBarButton' of undefined
Hey there
after upgrading the latest version of hxelectron I'm getting the following error: Science.js:7539 Uncaught TypeError: Cannot read property 'TouchBarButton' of undefined
It seems to be a result of electron.main.TouchBar, in particular where jsRequire is being used with the second param being TouchBar.TouchBarButton eg:
@:jsRequire("electron", "TouchBar.TouchBarButton") extern class TouchBarButton {
and as seem once compiled to js
var electron_main_TouchBarButton = require("electron").TouchBar.TouchBarButton;
Deleting the TouchBar extern resolves the issue, but it would be good to have an official.. Any ideas on how to resolve?
Cannot reproduce with haxe 4-rc.5.
trace(electron.main.TouchBar);
src/Main.hx:30: [Function: TouchBar] {
TouchBarButton: [Function: TouchBarButton],
TouchBarColorPicker: [Function: TouchBarColorPicker],
TouchBarGroup: [Function: TouchBarGroup],
TouchBarLabel: [Function: TouchBarLabel],
TouchBarPopover: [Function: TouchBarPopover],
TouchBarSlider: [Function: TouchBarSlider],
TouchBarSpacer: [Function: TouchBarSpacer],
TouchBarSegmentedControl: [Function: TouchBarSegmentedControl],
TouchBarScrubber: [Function: TouchBarScrubber]
hmmm interesting, thanks for checking..
I'm also running: 4-rc.5 and macOS 10.14.6
I'm not sure what other variables might be at play. What version of node and electron runtime are you using?
linux x64 node v12.4.0 electron 6.0.12 haxe 4.0.0-rc.5+4a745347f
Are you sure using the touchbar api from electron's main process ?
Ok, I think I know the cause of the issue. in my render processes I'm getting the current browserWindow like this.
import electron.renderer.Remote;
import electron.main.BrowserWindow;
...
var window:BrowserWindow = Remote.getCurrentWindow();
// do stuff with window
...
The issue is that BrowserWindow now internally references TouchBar.
@:electron_platforms(["macOS", "Experimental"])
function setTouchBar(touchBar:electron.main.TouchBar):Void;
This use to be Dynamic
@:electron_platforms(["macOS", "Experimental"])
function setTouchBar(touchBar:Dynamic):Void;
I know BrowserWindow is in the 'main' package, but considering you can have access to it through Remote.getCurrentWindow(); it would be nice if referencing it didn't cause a runtime error right?
I've been looking at a work around today, however the only solution I've found is to revert to
@:electron_platforms(["macOS", "Experimental"])
function setTouchBar(touchBar:Dynamic):Void;
The main issue is that within the TouchBar extern there are sub extern classes that are initialized through TouchBar
@:jsRequire("electron", "TouchBar.TouchBarButton") extern class TouchBarButton
js output
var electron_main_TouchBarButton = require("electron").TouchBar.TouchBarButton;
So because require("electron").TouchBar is null, we get a null ref issue, effectively
var electron_main_TouchBarButton = null.TouchBarButton;
Any thoughts?
It should work with haxe -dce full since not referenced anymore.
Still a bug!
Oh yes.. that's a good point.. just tested haxe -dce full and it does resolve it. But yeah would be good if it could also work with other dce settings
This seems to be resolved with electron v7.* but currently i am unable to update cause of another issue (#46).