I saw a related article here that has an interesting idea:
While these relatively straightforward strategies can be applied now, the researchers note that there may eventually be targeted attention-training exercises or interventions that people can employ to help them stay engaged. These are referred to as “closed-loop interventions” and are an active area of research.
As an example, Wagner and Madore envision wearable eye sensors that detect lapses in attention in real-time based on pupil size. If the individual wearer can then be cued to reorient their attention to the task at hand, the sensors may assist learning or information recall.