ModelJobs not working when focus is out [message #1850021] |
Fri, 11 February 2022 04:08  |
Eclipse User |
|
|
|
Hi,
I have created ModelJob to run some job (fetch location using requestGeolocation() method) in Desktop.java in execInit method. (Also tried in execOpened and execGuiAttached).
This is working ok, if application is active and focused. But job stops working when:
1. We open another tab in browser
2. When we minimize browser
3. When we open another browser with another page
Is it possible to always run job to requestGeolocation even if application is out of focus.
This is code for ModelJob:
ModelJobs.schedule(() -> {
findLocationForTeam();
}, ModelJobs.newInput(ClientRunContexts.copyCurrent())
.withExecutionTrigger(Jobs.newExecutionTrigger().
withStartIn(5,TimeUnit.SECONDS)
.withSchedule(FixedDelayScheduleBuilder.repeatForever(10, TimeUnit.SECONDS)))
.withExceptionHandling(new ExceptionHandler() {
@Override
public void handle(Throwable t) {
System.err.println("Error with JOB: " + t);
}
}, true));
I also tried to set property isTrackFocus on Desktop.java to false, but have same problem.
Thank you!
|
|
|
|
|
Re: ModelJobs not working when focus is out [message #1850033 is a reply to message #1850025] |
Fri, 11 February 2022 10:41  |
Eclipse User |
|
|
|
Hi Luka
The whole geolocation magic happens in the JS part of the application. The Java part in Desktop.java only sends an event to the browser, which results in a call to the "navigator.geolocation" API and returns the results in a JSON response. You should see that request/reponse when you open the network panel (F12) an look at the JSON requests.
I did not test it but I can imagine, that the browser does not respond to calls to the geolocation API when the browser tab/window is not active - it would make sense, because you don't want a malicious website to access your location in the background. You might need to debug into DesktopAdapter.js#_onRequestGeolocation to see what happens in your case.
I'd recommend to check first if the geolocation API responds to calls when the browser is in the background, in a plain HTML/JavaScript environment for instance with https://jsfiddle.net/.
Cheers
André
|
|
|
Powered by
FUDForum. Page generated in 0.11920 seconds