Florian
Florian

Reputation: 120

Server Push problem, when PWA in background

I have a Vaadin 24 application using PWA and PUSH. I have a dashboard with a background thread based on the tutorial which checks from time to time if a core task has finished and than a button state in the application is changed. The problem I face is, that if I put the PWA application in the background (not closing) and than putting it again in the front I need to refresh the application page to see the button changes. However the background thread still works if i look in the logs. If I add a refresh button which class the same method as the thread, the UI changes are applied.

Server push and PWA is something new for me, hopelfully someone can help me.

This is the code of the thread:

    private static Log log = LogFactory.getLog(DashboardThreadForHomeView.class);
    private final UI ui;
    private final HomeView view;

    public DashboardThreadForHomeView(UI ui, HomeView view) {
        this.ui = ui;
        this.view = view;
    }

    @Override
    public void run() {
        try {
            // Update the data for a while
            while (true) {
                for(DashboardComponent component : view.getTaskButtonHasMap()) {
                    ui.access(() -> component.update());
                }

                // Sleep
                Thread.sleep(3000);
            }
        } catch (InterruptedException e) {
            log.debug("Thread interrupted", e);
        }
    }
}

This is the method which is called by the thread:

public void update() {
        this.task = TaskUtil.getTask(task);
        if(task.getCurrentTaskExecution() != null) {
            // Toogle settings
            //execute.setValue(true);
            runStopButton.setText("Stop");
        } else {
            // Toggle settings
            //execute.setValue(false);
            runStopButton.setText("Start");
            // Endtime
            this.statusText.setText("");
        }
    }

Thanks, Florian

Upvotes: 0

Views: 89

Answers (0)

Related Questions