I struggle with this. Daydreaming is my instant Dopamin release system, always available, especially when I have to deal with something boring.
But I'm getting better by improving work package size, removing barriers beforehand. That increases flow and flow is pleasant even while doing mundane tasks.