Slice the onions into ¼-inch thick slices.
Heat the butter and olive oil in a large Dutch oven or other heavy pot over medium heat.
Once the butter has melted, add the sliced onions to the pot. Cook, stirring every few minutes, until very soft, browned (but not burnt) and caramelized, 25-30 minutes. Near the end of the cook time you will have to stir the onions more often to keep them from burning.
Add the garlic and flour to the pot and cook, stirring, for 1 minute.
Pour in the white wine and cook for 1-2 minutes, stirring and scraping up any browned bits from the bottom of the pot.
Add the beef broth or stock, salt, pepper, thyme sprigs (or dried thyme) and bay leaves. Increase the heat and bring to a simmer, then reduce the heat to a low simmer.
Cook at a low simmer for 30 minutes, uncovered, stirring occasionally.
While the soup simmers, preheat the oven to 400° F. Place the baguette slices on a baking sheet. Toast the bread slices in the preheated oven for 5-6 minutes, until golden brown on the edges.
Taste soup and add additional salt and pepper if needed. Remove the thyme stems and bay leaves and discard.
Preheat oven broiler to 425° F.
Place 4 oven-safe soup serving bowls on top of a heavy rimmed baking sheet. Transfer the soup into the serving bowls. Place 2 toasted baguette slices on top of each bowl of soup, browned side down. Sprinkle the shredded Gruyere over the top of the bread slices. (If you do not have oven-safe bowls, you can instead flip the toasted baguette slices over on the baking sheet, sprinkle the cheese on the bread, and broil for 2-4 minutes until the cheese melts and lightly browns. Then serve toasted cheesy bread with the soup.)
Put the baking sheet with the soup bowls in the oven and broil for 2-4 minutes, until cheese melts and lightly browns. Watch it carefully so as not to burn the cheesy toasts. Serve immediately, garnished with additional fresh thyme if desired. Be careful as the soup bowls will be very hot after they have been in the oven.