Preheat the oven to 375°F (190°C).
Season the chicken breasts with salt and pepper on both sides.
In a large oven-safe skillet or pan, heat 1 tablespoon of olive oil over medium-high heat. Add the chicken breasts and cook until they are browned on both sides, about 3-4 minutes per side. Remove the chicken from the pan and set aside.
In the same pan, melt the butter and olive oil over medium heat. Add the thinly sliced onions and sugar (if using). Cook the onions, stirring occasionally, until they become soft and caramelized, about 20-25 minutes.
Add the minced garlic, thyme leaves, salt, and pepper to the caramelized onions. Cook for an additional 2 minutes until the garlic is fragrant. Remove from heat.
Spread the caramelized onion mixture evenly in the pan. Place the cooked chicken breasts on top of the onions.
In a saucepan, heat the heavy cream over medium heat until it's warm but not boiling. Gradually add the shredded Gruyere cheese and Parmesan cheese, stirring constantly until the cheeses are melted and the sauce is smooth. Season with salt and pepper to taste.
Pour the cheese sauce over the chicken and onions in the pan.
Transfer the skillet or pan to the preheated oven and bake for about 20-25 minutes, or until the chicken is cooked through and the cheese sauce is bubbly and golden brown on top.
Remove from the oven and let it rest for a few minutes before serving.
Garnish with fresh thyme leaves, if desired.