In a large pot, melt butter and olive oil over medium heat.
Add sliced onions, sugar, and salt. Cook for 30-35 minutes, stirring occasionally, until deeply golden and caramelized.
Sprinkle flour over onions and stir for 1 minute.
Pour in wine (if using) and scrape the browned bits. Add broth and thyme.
Simmer uncovered for 20 minutes. Season with black pepper.
While soup simmers, toast baguette slices until crisp.
Preheat the broiler. Ladle soup into oven-safe bowls.
Top each with a toasted baguette slice and a generous amount of Gruyère.
Broil for 2-3 minutes until cheese is bubbly and golden.
Garnish with parsley (optional) and serve hot.