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

Uncaught TypeError: Cannot read property 'TouchBarButton' of undefined #45

Open
peteshand opened this issue Oct 9, 2019 · 8 comments
Open
Labels

Comments

@peteshand
Copy link

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?

@tong
Copy link
Owner

tong commented Oct 9, 2019

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]

@peteshand
Copy link
Author

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?

@tong
Copy link
Owner

tong commented Oct 9, 2019

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 ?

@peteshand
Copy link
Author

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
Copy link
Author

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?

@tong
Copy link
Owner

tong commented Oct 10, 2019

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

@tong tong added the bug label Oct 10, 2019
@peteshand
Copy link
Author

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

@tong
Copy link
Owner

tong commented Nov 26, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants