Many of us are training our bodies to prefer the quick fix of chemicals that come from clicking our way to enjoyment, and this can carry over into even our most cherished endeavors.
No one will be able to prescribe a single solution for listlessness because it is a symptom of many smaller problems, and it may be some time before you find the right combination of changes that effect a total positive outcome. That said, I'll try to make some suggestions.
Never underestimate the importance of physical health. Our cognitive ability is tied very closely to our breathing and heart rate variability, and our moods are swayed more by diet than we'd like to believe. I've found a combination of ketogenic diet and weight training to work well, but your own mileage may vary.
Consider setting clear boundaries in your day for work and leisure. It becomes easy to confuse these things when we dedicate so much time to code, but requiring a clear delineation of yourself will help you separate your unconscious response, which is a start.
Distance yourself from the keyboard, screens of all kinds, and especially notifications. When was the last time you sat quietly by yourself with only your thoughts to keep you company? How long did you do so? If not long, try it for a couple hours and see how you fare. This can be a nice stand-in for meditation (unless you like the idea of practicing zazen; it isn't for everyone).
Over time, with practice, I've come to enjoy sitting in the open air with just a pen and a notebook, and it helps me to clear my head, organize my thoughts, and return to the keyboard more eager than before.
Failing that, I break my current task into smaller and smaller steps until I can finish the first little step. Then I try to finish the second little step, and the third. Eventually, the restless I feel is supplanted by a desire to organize these small tasks I've made into more efficient task bundles, and I soon go on to make real progress. When my success subsides, I force myself to scrutinize the current obstacle awhile before taking a break and starting all over again.
I hope you find a set of tactics that work well for you. Good luck!