hxelectron icon indicating copy to clipboard operation
hxelectron copied to clipboard

Uncaught TypeError: Cannot read property 'TouchBarButton' of undefined

Open peteshand opened this issue 6 years ago • 8 comments

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?

peteshand avatar Oct 09 '19 02:10 peteshand

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]

tong avatar Oct 09 '19 09:10 tong

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?

peteshand avatar Oct 09 '19 09:10 peteshand

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 ?

tong avatar Oct 09 '19 10:10 tong

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?

peteshand avatar Oct 10 '19 00:10 peteshand

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?

peteshand avatar Oct 10 '19 12:10 peteshand

It should work with haxe -dce full since not referenced anymore. Still a bug!

tong avatar Oct 10 '19 22:10 tong

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

peteshand avatar Oct 10 '19 23:10 peteshand

This seems to be resolved with electron v7.* but currently i am unable to update cause of another issue (#46).

tong avatar Nov 26 '19 10:11 tong