cljfx

https://github.com/cljfx/cljfx
2020-10-31T13:02:03.129700Z

what is the correct way of exiting the application when the user closes the main window? Where should I call shutdown-agents of Platform/exit ?

Remy 2020-11-02T14:33:34.131900Z

have you tried running that last one inside a fx/on-fx-thread ?https://github.com/cljfx/cljfx/blob/master/src/cljfx/platform.clj#L24

vlaaad 2020-11-02T14:37:03.132200Z

run-later and on-fx-thread are pretty similar 🙂

1
Remy 2020-11-02T14:49:54.132500Z

Just to give a bit more detail. When calling :on-close-request (fn [& _] (fx/on-fx-thread (javafx.application.Platform/exit))) and setting up (javafx.application.Platform/setImplicitExit true) inside my -main

Exception in thread "JavaFX Application Thread" java.lang.IllegalStateException: Not on FX application thread; currentThread = JavaFX Application Thread
	at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:291)
	at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:446)
	at javafx.stage.Window.setShowing(Window.java:1173)
	at javafx.stage.Window.hide(Window.java:1199)
	at com.sun.javafx.stage.WindowCloseRequestHandler.dispatchBubblingEvent(WindowCloseRequestHandler.java:45)
	at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
	at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
	at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
	at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
	at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
	at javafx.event.Event.fireEvent(Event.java:198)
	at com.sun.javafx.stage.WindowPeerListener.closing(WindowPeerListener.java:93)
	at com.sun.javafx.tk.quantum.GlassWindowEventHandler.run(GlassWindowEventHandler.java:147)
	at com.sun.javafx.tk.quantum.GlassWindowEventHandler.run(GlassWindowEventHandler.java:40)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
	at com.sun.javafx.tk.quantum.GlassWindowEventHandler.lambda$handleWindowEvent$4(GlassWindowEventHandler.java:176)
	at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:412)
	at com.sun.javafx.tk.quantum.GlassWindowEventHandler.handleWindowEvent(GlassWindowEventHandler.java:174)
	at com.sun.glass.ui.Window.handleWindowEvent(Window.java:1351)
	at com.sun.glass.ui.Window.notifyClose(Window.java:1251)
	at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
	at com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
	at java.base/java.lang.Thread.run(Thread.java:832)

vlaaad 2020-11-02T14:51:53.132700Z

> java.lang.IllegalStateException: Not on FX application thread; currentThread = JavaFX Application Thread

vlaaad 2020-11-02T14:51:58.132900Z

wat

Remy 2020-11-02T14:52:09.133100Z

my thoughts exactly 😄

vlaaad 2020-11-02T14:52:16.133300Z

😂

Remy 2020-11-02T14:52:50.133500Z

I started seeing this kind of thread related issues when switching to fx/create-app

Remy 2020-11-02T14:54:47.133700Z

What I mean is I was forced to use on-fx-thread for (.showDialog (DirectryChooser.) window)

vlaaad 2020-11-02T14:59:07.133900Z

argh, create-app...

vlaaad 2020-11-02T14:59:23.134100Z

I made a mistake introducing fx/wrap-async

vlaaad 2020-11-02T14:59:35.134300Z

it only creates problems

vlaaad 2020-11-02T14:59:54.134500Z

it's deprecated now, but it's in create-app too...

1
vlaaad 2020-10-31T13:17:33.129800Z

You can set implicit exit to true to exit the platform on last window close, see https://github.com/cljfx/hn/blob/master/src/hn/core.clj#L49

vlaaad 2020-10-31T13:18:00.130100Z

I think it makes sense to call it in -main so it's not called during development

vlaaad 2020-10-31T13:18:37.130300Z

Do you use agents for cljfx's wrap async only?

vlaaad 2020-10-31T13:19:11.130500Z

If yes, I would suggest removing wrap-async, it creates more problems than solves

2020-10-31T14:59:25.130700Z

I already added (Platform/setImplicitExit true) but the app is still not exiting after I closed the main window, maybe because some threads still running

2020-10-31T14:59:49.130900Z

I'm not using wrap-async

2020-10-31T15:10:18.131100Z

what I'm doing now as a workaround is setting stage with :on-close-request (fn [& _] (System/exit 0))

vlaaad 2020-10-31T15:47:07.131300Z

Looks fine, though I would expect calling platform/exit and shutdown-agents there to let jvm quit

2020-10-31T16:54:08.131500Z

tried that, but platform/exit doesn't work, it complains about not being called in the correct thread, tried with run-later but didn't work either