Refactor the desktop environment detection to eliminate the copy&paste.