01 - Heat 2 tablespoons butter and 1 tablespoon olive oil in a large skillet over medium heat. Add sliced onions, salt, pepper, and sugar. Stir frequently and cook until the onions are deeply golden and caramelized, approximately 25 to 30 minutes. Incorporate thyme in the last 5 minutes if desired. Remove from heat and set aside.
02 - Arrange bread slices on a cutting board. Spread a thin layer of softened butter on one side of each slice.
03 - On the unbuttered side of two bread slices, evenly distribute half of the grated Gruyère cheese. Layer generously with caramelized onions, then sprinkle over the remaining Gruyère. Top with the remaining bread, buttered side facing out.
04 - Heat a large skillet or griddle over medium-low heat. Place assembled sandwiches in the pan. Cook for 3 to 4 minutes per side, pressing gently, until the bread is crisp and golden and the cheese has melted. Flip carefully as required.
05 - Transfer sandwiches to a cutting board, rest for 1 minute, then slice and serve hot.